Skip to content

Commit

Permalink
feat(cavatica): SKFP-895 move cavatica widgets to ferlab-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
lflangis committed Jan 24, 2024
1 parent 99199c8 commit b02399b
Show file tree
Hide file tree
Showing 59 changed files with 952 additions and 2,222 deletions.
27 changes: 14 additions & 13 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@babel/core": "^7.16.0",
"@dnd-kit/core": "^4.0.3",
"@dnd-kit/sortable": "^5.1.0",
"@ferlab/ui": "^7.19.3",
"@ferlab/ui": "^7.20.2",
"@loadable/component": "^5.15.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
"@react-keycloak/core": "^3.2.0",
Expand Down
7 changes: 4 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Switch,
} from 'react-router-dom';
import Empty from '@ferlab/ui/core/components/Empty';
import { PASSPORT } from '@ferlab/ui/core/components/Widgets/Cavatica';
import MaintenancePage from '@ferlab/ui/core/pages/MaintenancePage';
import { setLocale } from '@ferlab/ui/core/utils/localeUtils';
import loadable from '@loadable/component';
Expand Down Expand Up @@ -39,9 +40,9 @@ import SideImageLayout from 'components/Layout/SideImage';
import GradientAccent from 'components/uiKit/GradientAccent';
import Spinner from 'components/uiKit/Spinner';
import NotificationContextHolder from 'components/utils/NotificationContextHolder';
import { initGa } from 'services/analytics';
import { useLang } from 'store/global';
import { DYNAMIC_ROUTES, STATIC_ROUTES } from 'utils/routes';
import { initGa } from 'services/analytics';

const loadableProps = { fallback: <Spinner size="large" /> };
const Dashboard = loadable(() => import('views/Dashboard'), loadableProps);
Expand Down Expand Up @@ -94,9 +95,9 @@ const App = () => {
render={() => <FenceRedirect fence={FENCE_NAMES.gen3} />}
/>
<Route
path={STATIC_ROUTES.CAVATICA_FENCE_REDIRECT}
path={STATIC_ROUTES.CAVATICA_PASSPORT_REDIRECT}
exact
render={() => <FenceRedirect fence={FENCE_NAMES.cavatica} />}
render={() => <FenceRedirect fence={PASSPORT.cavatica} />}
/>
<Route exact path={STATIC_ROUTES.LOGIN}>
<GradientAccent isFixed />
Expand Down
10 changes: 1 addition & 9 deletions src/common/fenceTypes.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
export enum FENCE_NAMES {
dcf = 'dcf',
gen3 = 'gen3',
cavatica = 'cavatica',
}

export const ALL_FENCE_NAMES = [FENCE_NAMES.gen3, FENCE_NAMES.dcf, FENCE_NAMES.cavatica];
export const ALL_FENCE_NAMES = [FENCE_NAMES.gen3, FENCE_NAMES.dcf];
export const ALL_STUDIES_FENCE_NAMES = [FENCE_NAMES.gen3, FENCE_NAMES.dcf];

export enum FENCE_CONNECTION_STATUSES {
connected = 'connected',
disconnected = 'disconnected',
unknown = 'unknown',
}

export type TFenceConnections = {
[FENCE_NAMES.dcf]?: TConnection;
[FENCE_NAMES.gen3]?: TConnection;
[FENCE_NAMES.cavatica]?: TConnection;
};

export type TProjects = { [index: string]: any };
Expand Down
200 changes: 125 additions & 75 deletions src/components/Cavatica/AnalyzeButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { useCallback, useEffect } from 'react';
import intl from 'react-intl-universal';
import { useDispatch } from 'react-redux';
import { CloudUploadOutlined } from '@ant-design/icons';
import CavaticaAnalyse from '@ferlab/ui/core/components/Widgets/Cavatica/CavaticaAnalyse';
import {
CAVATICA_ANALYSE_STATUS,
PASSPORT_AUTHENTIFICATION_STATUS,
} from '@ferlab/ui/core/components/Widgets/Cavatica/type';
import { BooleanOperators } from '@ferlab/ui/core/data/sqon/operators';
import { ISqonGroupFilter } from '@ferlab/ui/core/data/sqon/types';
import { Button, Modal } from 'antd';
import { CAVATICA_FILE_BATCH_SIZE } from 'views/Studies/utils/constant';
import { CAVATICA_FILE_BATCH_SIZE } from 'views/DataExploration/utils/constant';

import { FENCE_NAMES } from 'common/fenceTypes';
import AnalyzeModal from 'components/Cavatica/AnalyzeModal';
import CreateProjectModal from 'components/Cavatica/CreateProjectModal';
import { useFenceCavatica } from 'store/fenceCavatica';
import { fenceCavaticaActions } from 'store/fenceCavatica/slice';
import { beginAnalyse } from 'store/fenceCavatica/thunks';
import { connectToFence } from 'store/fenceConnection/thunks';
import { CavaticaApi } from 'services/api/cavatica';
import { ICavaticaCreateProjectBody } from 'services/api/cavatica/models';
import { fetchAllFencesAuthentificationStatus } from 'store/fences/thunks';
import { useCavaticaPassport } from 'store/passport';
import { passportActions } from 'store/passport/slice';
import {
beginCavaticaAnalyse,
connectCavaticaPassport,
createCavaticaProjet,
} from 'store/passport/thunks';

interface OwnProps {
fileIds: string[];
Expand All @@ -28,14 +34,13 @@ const CavaticaAnalyzeButton: React.FC<OwnProps> = ({
type = 'default',
disabled = false,
}) => {
const { isConnected, isInitializingAnalyse, beginAnalyseAfterConnection } = useFenceCavatica();

const dispatch = useDispatch();
const cavatica = useCavaticaPassport();

const onBeginAnalyse = useCallback(
() =>
dispatch(
beginAnalyse({
beginCavaticaAnalyse({
sqon: sqon || {
op: BooleanOperators.and,
content: [],
Expand All @@ -47,72 +52,117 @@ const CavaticaAnalyzeButton: React.FC<OwnProps> = ({
);

useEffect(() => {
if (isConnected && beginAnalyseAfterConnection) {
dispatch(fetchAllFencesAuthentificationStatus());
}, []);

// If the user is not connected to cavatica
useEffect(() => {
if (
cavatica.authentification.status === PASSPORT_AUTHENTIFICATION_STATUS.connected &&
cavatica.bulkImportData.status === CAVATICA_ANALYSE_STATUS.pending_analyse
) {
onBeginAnalyse();
}
}, [isConnected, beginAnalyseAfterConnection, onBeginAnalyse]);

const onCavaticaUploadLimitReached = () =>
Modal.error({
title: intl.get('screen.dataExploration.tabs.datafiles.cavatica.bulkImportLimit.title'),
content: intl.getHTML(
'screen.dataExploration.tabs.datafiles.cavatica.bulkImportLimit.description',
{
limit: CAVATICA_FILE_BATCH_SIZE,
},
),
okText: 'Ok',
cancelText: undefined,
});

const onCavaticaConnectionRequired = () =>
Modal.confirm({
type: 'warn',
title: intl.get('screen.dataExploration.tabs.datafiles.cavatica.authWarning.title'),
content: intl.get('screen.dataExploration.tabs.datafiles.cavatica.authWarning.description'),
okText: intl.get('screen.dataExploration.tabs.datafiles.cavatica.authWarning.connect'),
onOk: () => {
dispatch(fenceCavaticaActions.setBeginAnalyseConnectionFlag());
dispatch(connectToFence(FENCE_NAMES.cavatica));
},
});
}, [cavatica.authentification.status, cavatica.bulkImportData.status, onBeginAnalyse]);

return (
<>
<Button
type={type}
icon={<CloudUploadOutlined />}
loading={isInitializingAnalyse}
disabled={disabled}
onClick={() => {
if (isConnected) {
if (fileIds.length > CAVATICA_FILE_BATCH_SIZE) {
onCavaticaUploadLimitReached();
} else {
dispatch(
beginAnalyse({
sqon: sqon || {
op: BooleanOperators.and,
content: [],
},
fileIds: fileIds,
}),
);
}
} else {
onCavaticaConnectionRequired();
}
}}
>
{intl.get('screen.dataExploration.tabs.datafiles.cavatica.analyseInCavatica')}
</Button>
{isConnected && (
<>
<AnalyzeModal />
<CreateProjectModal />
</>
)}
</>
<CavaticaAnalyse
disabled={disabled}
type={type}
handleBeginAnalyse={onBeginAnalyse}
handleFilesAndFolders={CavaticaApi.listFilesAndFolders}
cavatica={cavatica}
setCavaticaBulkImportDataStatus={(status: CAVATICA_ANALYSE_STATUS) => {
dispatch(passportActions.setCavaticaBulkImportDataStatus(status));
}}
handleConnection={() => {
dispatch(connectCavaticaPassport());
}}
handleResetErrors={() => {
dispatch(passportActions.resetCavaticaBillingsGroupError());
dispatch(passportActions.resetCavaticaProjectsError());
dispatch(passportActions.setCavaticaBulkImportDataStatus(CAVATICA_ANALYSE_STATUS.unknow));
}}
handleCreateProject={(values: ICavaticaCreateProjectBody) => {
dispatch(
createCavaticaProjet({
body: values,
}),
);
}}
dictionary={{
analyseModal: {
copyFiles: intl.get(
'screen.dataExploration.tabs.datafiles.cavatica.analyseModal.copyFiles',
),
copyFilesTo: intl.get(
'screen.dataExploration.tabs.datafiles.cavatica.analyseModal.copyFilesTo',
),
createProjectToPushFileTo: intl.get(
'screen.dataExploration.tabs.datafiles.cavatica.analyseModal.createProjectToPushFileTo',
),
newProject: intl.get(
'screen.dataExploration.tabs.datafiles.cavatica.analyseModal.newProject',
),
title: intl.get('screen.dataExploration.tabs.datafiles.cavatica.analyseInCavatica'),
youAreAuthorizedToCopy: intl.get(
'screen.dataExploration.tabs.datafiles.cavatica.analyseModal.youAreAuthorizedToCopy',
),
files: intl.get('screen.dataExploration.tabs.datafiles.cavatica.analyseModal.files'),
ofFiles: intl.get('screen.dataExploration.tabs.datafiles.cavatica.analyseModal.ofFiles'),
},
billingGroupsErrorModal: {
description: intl.get('api.cavatica.error.projects.fetch'),
title: intl.get('api.cavatica.error.title'),
},
buttonText: intl.get('screen.dataExploration.tabs.datafiles.cavatica.analyseInCavatica'),
connectionRequiredModal: {
description: intl.get(
'screen.dataExploration.tabs.datafiles.cavatica.authWarning.description',
),
okText: intl.get('screen.dataExploration.tabs.datafiles.cavatica.authWarning.connect'),
title: intl.get('screen.dataExploration.tabs.datafiles.cavatica.authWarning.title'),
},
fetchErrorModal: {
description: intl.get('api.cavatica.error.bulk.fetchfiles'),
title: intl.get('api.cavatica.error.title'),
},
createProjectModal: {
title: intl.get('screen.dashboard.cards.cavatica.newProject'),
requiredField: intl.get('global.forms.errors.requiredField'),
projectName: {
label: 'Project name',
placeholder: 'e.g. KF-NBL Neuroblastoma Aligned Reads',
},
billingGroup: {
label: intl.get('screen.dashboard.cards.cavatica.billingGroups.label'),
empty: intl.get('screen.dashboard.cards.cavatica.billingGroups.empty'),
},
okText: intl.get('screen.dashboard.cards.cavatica.createProject'),
cancelText: intl.get('screen.dashboard.cards.cavatica.cancelText'),
},
projectCreateErrorModal: {
description: intl.get('api.cavatica.error.projects.fetch'),
title: intl.get('api.cavatica.error.title'),
},
projectFetchErrorModal: {
description: intl.get('api.cavatica.error.projects.fetch'),
title: intl.get('api.cavatica.error.title'),
},
unauthorizedModal: {
description: intl.get('api.cavatica.error.fileAuth.description'),
title: intl.get('api.cavatica.error.fileAuth.title'),
},
uploadLimitReachedModalError: {
description: intl.getHTML(
'screen.dataExploration.tabs.datafiles.cavatica.bulkImportLimit.description',
{ limit: CAVATICA_FILE_BATCH_SIZE },
),
okText: 'OK',
title: intl.get('screen.dataExploration.tabs.datafiles.cavatica.bulkImportLimit.title'),
},
}}
/>
);
};

Expand Down
Loading

0 comments on commit b02399b

Please sign in to comment.