Skip to content
Open
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
90 changes: 45 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,64 +1,40 @@
import React, { useState, useCallback } from 'react';
import React from 'react';
import { Button, Tooltip } from '@mui/material';
import CreateCollectionDialog from './CreateCollectionDialog';
import { Link } from 'react-router';
import AddIcon from '@mui/icons-material/Add';
import { useClient } from '../../../context/client-context';
import PropTypes from 'prop-types';

const BUTTON_LABEL = 'Create Collection';

const CreateCollectionButton = ({ onComplete }) => {
const [open, setOpen] = useState(false);
const CreateCollectionButton = () => {
const { isRestricted } = useClient();

const handleClose = useCallback(() => {
setOpen(false);
onComplete();
}, [onComplete]);

const handleOpen = useCallback(() => {
if (!isRestricted) {
setOpen(true);
}
}, [isRestricted]);
if (isRestricted) {
return (
<Tooltip
title="Access Denied: You do not have permission to create collections. Please contact your administrator."
placement="bottom"
>
<span>
<Button variant="contained" startIcon={<AddIcon fontSize="small" />} disabled aria-label={BUTTON_LABEL}>
{BUTTON_LABEL}
</Button>
</span>
</Tooltip>
);
}

return (
<>
{isRestricted ? (
<Tooltip
title="Access Denied: You do not have permission to create collections. Please contact your administrator."
placement="bottom"
>
{/* span is needed to allow tooltip on disabled button */}
<span>
<Button
variant="contained"
startIcon={<AddIcon fontSize="small" />}
onClick={handleOpen}
disabled
aria-label={BUTTON_LABEL}
>
{BUTTON_LABEL}
</Button>
</span>
</Tooltip>
) : (
<Button
variant="contained"
startIcon={<AddIcon fontSize="small" />}
onClick={handleOpen}
aria-label={BUTTON_LABEL}
>
{BUTTON_LABEL}
</Button>
)}
<CreateCollectionDialog open={open} handleClose={handleClose} />
</>
<Button
variant="contained"
startIcon={<AddIcon fontSize="small" />}
component={Link}
to="/collection/create"
aria-label={BUTTON_LABEL}
>
{BUTTON_LABEL}
</Button>
);
};

CreateCollectionButton.propTypes = {
onComplete: PropTypes.func.isRequired,
};

export default CreateCollectionButton;
21 changes: 21 additions & 0 deletions src/pages/CollectionCreation.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { useCallback } from 'react';
import { Navigate, useNavigate } from 'react-router';
import CreateCollectionDialog from '../components/Collections/CreateCollection/CreateCollectionDialog';
import { useClient } from '../context/client-context';

function CollectionCreation() {
const navigate = useNavigate();
const { isRestricted } = useClient();

const handleClose = useCallback(() => {
navigate('/collections');
}, [navigate]);

if (isRestricted) {
return <Navigate to="/collections" replace />;
}

return <CreateCollectionDialog open={true} handleClose={handleClose} />;
}

export default CollectionCreation;
2 changes: 1 addition & 1 deletion src/pages/Collections.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function Collections() {
Delete ({selectedCollections.size})
</Button>
)}
<CreateCollectionButton onComplete={() => getCollectionsCall(currentPage)} />
<CreateCollectionButton />
<SnapshotsUpload onComplete={() => getCollectionsCall(currentPage)} key={'snapshots'} />
</Grid>
<Grid size={12} mb={2}>
Expand Down
2 changes: 2 additions & 0 deletions src/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Home from './pages/Home';
import Console from './pages/Console';
import Collections from './pages/Collections';
import Collection from './pages/Collection';
import CollectionCreation from './pages/CollectionCreation';
import Visualize from './pages/Visualize';
import TutorialIndex from './pages/TutorialIndex';
import Tutorial from './pages/Tutorial';
Expand All @@ -22,6 +23,7 @@ const routes = () => [
{ path: '/welcome', element: <Welcome /> },
{ path: '/console', element: <Console /> },
{ path: '/datasets', element: <Datasets /> },
{ path: '/collection/create', element: <CollectionCreation /> },
{ path: '/collections', element: <Collections /> },
{ path: '/collections/:collectionName', element: <Collection /> },
{
Expand Down