Skip to content

Commit

Permalink
feat: use switch and enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong committed Nov 8, 2024
1 parent 122a507 commit 679e270
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/libs/Models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export enum AccessManagement {
OPEN = 'open',
CONTROLLED = 'controlled',
EXTERNAL = 'external'
}
45 changes: 23 additions & 22 deletions src/pages/DatasetStatistics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {find} from 'lodash/fp';
import {ReadMore} from '../components/ReadMore';
import {formatDate} from '../libs/utils';
import {Button} from '@mui/material';
import {AccessManagement} from '../libs/Models.ts';

const LINE = <div style={{borderTop: '1px solid #BABEC1', height: 0}}/>;

Expand Down Expand Up @@ -62,31 +63,31 @@ export default function DatasetStatistics(props) {
}
};

const accessButton = () => {
const accessInstructions = () => {
const accessManagement = extract('Access Management').toLowerCase();
if (accessManagement === 'controlled') {
return <Button variant='contained' onClick={applyForAccess} sx={{transform: 'scale(1.5)'}}>
Apply for Access
</Button>;
}
const locationUrl = extract('URL');
if (accessManagement === 'open') {
return <span>
This dataset is open access, does not require an access request
{locationUrl &&
<span>, and can be accessed directly through this <a href={locationUrl}>link</a>.</span>
}
</span>;
}
if (accessManagement === 'external') {
return <span>
switch (accessManagement) {
case AccessManagement.CONTROLLED:
return <Button variant='contained' onClick={applyForAccess} sx={{transform: 'scale(1.5)'}}>
Apply for Access
</Button>;
case AccessManagement.OPEN:
return <span>dataset is open access, does not require an access request
{locationUrl &&
<span>, and can be accessed directly through this <a href={locationUrl}>link</a>.</span>
}
</span>;
case AccessManagement.EXTERNAL:
return <span>
This dataset is externally managed. Requests cannot be made via DUOS
{locationUrl &&
<span>, but must be made directly through the <a href={locationUrl}>dataset&apos;s host repository</a>.</span>
}
</span>;
{locationUrl &&
<span>, but must be made directly through the <a
href={locationUrl}>dataset&apos;s host repository</a>.</span>
}
</span>;
default:
return <div/>;
}
return <div/>;
};

if (!isLoading) {
Expand All @@ -106,7 +107,7 @@ export default function DatasetStatistics(props) {
</div>
</div>
<div style={{paddingTop: '20px', paddingLeft: '30px'}}>
{accessButton()}
{accessInstructions()}
</div>
</div>
<div style={Styles.SUB_HEADER}>Dataset Information</div>
Expand Down

0 comments on commit 679e270

Please sign in to comment.