Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Add singularity command switcher #442

Merged
merged 9 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading