Skip to content

Commit

Permalink
- first implementation of #1354
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Mar 12, 2024
1 parent 4121519 commit a3dc819
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
22 changes: 22 additions & 0 deletions js/components/projects/legacySnapshotModal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { Fragment, useState } from 'react';
import { Modal } from '../../common';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';

export const LegacySnapshotModal = ({ open, project, snapshot }) => {
const [legacyLink, setLegacyLink] = useState('');

if (DJANGO_CONTEXT['legacy_url'] && DJANGO_CONTEXT['legacy_url'] !== '' && legacyLink === '') {
setLegacyLink(`${DJANGO_CONTEXT['legacy_url']}/viewer/react/projects/${project}/${snapshot}`);
}

return (
<Modal open={open}>
<h3>
Snapshot is not recognized. Maybe it is available in the legacy system. Please try link below. <br />
</h3>
<a href={legacyLink} target="_blank">
Legacy link
</a>
</Modal>
);
};
11 changes: 9 additions & 2 deletions js/components/projects/projectPreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { restoreCurrentActionsList } from '../../../reducers/tracking/dispatchAc
import { setIsSnapshotDirty } from '../../../reducers/tracking/actions';
import { setDownloadStructuresDialogOpen } from '../../snapshot/redux/actions';
import { ToastContext } from '../../toast';
import { LegacySnapshotModal } from '../legacySnapshotModal';

export const ProjectPreview = memo(({ }) => {
export const ProjectPreview = memo(({}) => {
const { toast } = useContext(ToastContext);
const [canShow, setCanShow] = useState(undefined);
const isSnapshotLoaded = useRef(undefined);
Expand All @@ -23,6 +24,8 @@ export const ProjectPreview = memo(({ }) => {
const isActionRestoring = useSelector(state => state.trackingReducers.isActionRestoring);
const isActionRestored = useSelector(state => state.trackingReducers.isActionRestored);

const [showLegacySnapshotModal, setShowLegacySnapshotModal] = useState(false);

useEffect(() => {
if (!snapshotId && currentSnapshotID === null) {
dispatch(loadSnapshotByProjectID(projectId))
Expand All @@ -49,6 +52,7 @@ export const ProjectPreview = memo(({ }) => {
setCanShow(true);
} else {
setCanShow(false);
setShowLegacySnapshotModal(true);
}
if (response.data) {
const dataObj = JSON.parse(response.data);
Expand All @@ -59,6 +63,7 @@ export const ProjectPreview = memo(({ }) => {
} else {
isSnapshotLoaded.current = response;
setCanShow(false);
setShowLegacySnapshotModal(true);
}
}
})
Expand Down Expand Up @@ -96,5 +101,7 @@ export const ProjectPreview = memo(({ }) => {
(currentSessionProject.projectID === null || currentSessionProject.authorID === null))
}
/>
) : null;
) : (
<LegacySnapshotModal open={showLegacySnapshotModal} project={projectId} snapshot={snapshotId} />
);
});

0 comments on commit a3dc819

Please sign in to comment.