Skip to content

Commit

Permalink
[ENH] Add singularity command switcher (#442)
Browse files Browse the repository at this point in the history
* [ENH] Add singularity command switcher

* Fix typo and ts error

* Add MUI theme to vite config

To make tests run locally with the custom theme
Not entirely sure still why

* Add component test for singularity switcher

* Apply suggestions from code review

Co-authored-by: Arman Jahanpour <[email protected]>

* Remove superfluous MUI from vite config

---------

Co-authored-by: Arman Jahanpour <[email protected]>
  • Loading branch information
surchs and rmanaem authored Jan 24, 2025
1 parent ffe0612 commit a089f06
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
15 changes: 15 additions & 0 deletions cypress/component/GetDataDialog.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,19 @@ describe('GetDataDialog', () => {
cy.get('[data-cy="get-data-dialog-close-button"]').click();
cy.get('@onCloseSpy').should('have.been.called');
});

it('Switches between docker and singularity commands', () => {
cy.mount(<GetDataDialog open={props.open} onClose={props.onClose} />);

cy.get('button').contains('docker').should('exist');
cy.get('button').contains('singularity').should('exist');

cy.get('code').should('contain', 'docker run');

cy.get('button').contains('singularity').click();
cy.get('code').should('contain', 'singularity run');

cy.get('button').contains('docker').click();
cy.get('code').should('contain', 'docker run');
});
});
25 changes: 23 additions & 2 deletions src/components/GetDataDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
DialogContent,
DialogContentText,
useMediaQuery,
ToggleButton,
ToggleButtonGroup,
} from '@mui/material';
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import { useTheme } from '@mui/material/styles';
Expand All @@ -17,14 +19,19 @@ import NBTheme from '../theme';
function GetDataDialog({ open, onClose }: { open: boolean; onClose: () => void }) {
const DOCKER_RUN_COMMAND =
'docker run -t -u $(id -u):$(id -g) -v $(pwd):/data neurobagel/dataget:latest /data/neurobagel-query-results.tsv /data/output';
const SINGULARITY_RUN_COMMAND =
'singularity run --bind $(pwd):/data docker://neurobagel/dataget:latest /data/neurobagel-query-results.tsv /data/output';
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));

const [commandType, setCommandType] = React.useState('docker');
const showRunCommand = commandType === 'docker' ? DOCKER_RUN_COMMAND : SINGULARITY_RUN_COMMAND;

const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
const [showPopover, setShowPopover] = useState(false);

const handleCopyClick = (event: React.MouseEvent<HTMLButtonElement>) => {
navigator.clipboard.writeText(DOCKER_RUN_COMMAND);
navigator.clipboard.writeText(showRunCommand);
setAnchorEl(event.currentTarget);
setShowPopover(true);

Expand All @@ -38,6 +45,10 @@ function GetDataDialog({ open, onClose }: { open: boolean; onClose: () => void }
setShowPopover(false);
};

const handleToggle = (_event: React.MouseEvent<HTMLElement>, newCommand: string) => {
setCommandType(newCommand);
};

return (
<Dialog fullScreen={fullScreen} open={open} onClose={onClose} data-cy="get-data-dialog">
<DialogContent>
Expand All @@ -57,9 +68,19 @@ function GetDataDialog({ open, onClose }: { open: boolean; onClose: () => void }
<li>Copy and run the command below</li>
</ol>
</DialogContentText>
<ToggleButtonGroup
color="primary"
value={commandType}
exclusive
onChange={handleToggle}
aria-label="Platform"
>
<ToggleButton value="docker">docker</ToggleButton>
<ToggleButton value="singularity">singularity</ToggleButton>
</ToggleButtonGroup>
<DialogContentText>
<div className="flex items-center rounded bg-gray-200 px-2 py-1 text-sm">
<code className="flex-grow text-black">{DOCKER_RUN_COMMAND}</code>
<code className="flex-grow text-black">{showRunCommand}</code>
<IconButton
color="primary"
onClick={handleCopyClick}
Expand Down
5 changes: 3 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export default defineConfig(({ mode }) => {
},
plugins: [react()],
envPrefix: 'NB_',
// Excluding the Auth0 library from the bundle to avoid issues with
// Cypress component tests. TODO: understand why this is necessary

optimizeDeps: {
// Excluding the Auth0 library from the bundle to avoid issues with
// Cypress component tests. TODO: understand why this is necessary
exclude: ['@auth0/auth0-react'],
},
};
Expand Down

0 comments on commit a089f06

Please sign in to comment.