Skip to content

Commit

Permalink
Merge pull request #173 from CSCfi/CSCFC4EMSCR-457v2
Browse files Browse the repository at this point in the history
disable edit mode after publihing crosswalk and remove unused code
  • Loading branch information
konolak authored May 22, 2024
2 parents 18b56c5 + 7f61d8d commit a3771b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function SchemaAndCrosswalkActionMenu({
const { t } = useTranslation('common');
const dispatch = useStoreDispatch();
const [isEditModeActive, setIsEditModeActive] = useState(false);
const [patchCrosswalk] = usePatchCrosswalkMutation();
const [patchCrosswalk, crosswalkPatchResponse] = usePatchCrosswalkMutation();
const [patchSchema] = usePatchSchemaMutation();
const [deleteSchema] = useDeleteSchemaMutation();
const [deleteCrosswalk] = useDeleteCrosswalkMutation();
Expand All @@ -56,6 +56,18 @@ export default function SchemaAndCrosswalkActionMenu({
const [isDeleteConfirmModalOpen, setDeleteConfirmModalOpen] = useState(false);
const [isRemoveConfirmModalOpen, setRemoveConfirmModalOpen] = useState(false);
const [isRevisionModalOpen, setRevisionModalOpen] = useState(false);
const [isCrosswalkPublished, setCrosswalkPublished] =
React.useState<boolean>(false);

if (!isCrosswalkPublished && crosswalkPatchResponse.isSuccess) {
if (
crosswalkPatchResponse?.originalArgs?.payload?.state === State.Published
) {
buttonCallbackFunction('disableEdit');
setIsEditModeActive(false);
setCrosswalkPublished(true);
}
}

const performModalAction = (action: string) => {
setPublishConfirmModalOpen(false);
Expand Down Expand Up @@ -174,7 +186,6 @@ export default function SchemaAndCrosswalkActionMenu({
}
};


useEffect(() => {
setIsEditModeActive(isMappingsEditModeActive);
}, [isMappingsEditModeActive]);
Expand All @@ -183,8 +194,6 @@ export default function SchemaAndCrosswalkActionMenu({
dispatch(clearNotification());
}, [dispatch]);



return (
<>
<ActionMenu buttonText={t('action.actions')}>
Expand Down
48 changes: 3 additions & 45 deletions mscr-ui/src/modules/crosswalk-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ export default function CrosswalkEditor({

const [crosswalkPublished, setCrosswalkPublished] =
React.useState<boolean>(true);
const [publishNotificationVisible, setPublishNotificationVisible] =
React.useState<boolean>(false);
const [saveNotificationVisible, setSaveNotificationVisible] =
React.useState<boolean>(false);
const [lastPatchCrosswalkId, setLastPatchCrosswalkId] =
React.useState<string>('');
const [lastPutMappingPid, setLastPutMappingPid] = React.useState<string>('');
Expand All @@ -126,7 +122,6 @@ export default function CrosswalkEditor({
React.useState<string>('');
const [showAttributeNames, setShowAttributeNames] = React.useState(true);

const [patchCrosswalk, crosswalkPatchResponse] = usePatchCrosswalkMutation();
const [putMapping, putMappingResponse] = usePutMappingMutation();
const [deleteMapping, deleteMappingResponse] = useDeleteMappingMutation();
const [patchMapping, patchMappingResponse] = usePatchMappingMutation();
Expand Down Expand Up @@ -172,28 +167,6 @@ export default function CrosswalkEditor({
</TreeItem>
);

if (crosswalkPatchResponse.isSuccess) {
if (
!crosswalkPublished &&
crosswalkPatchResponse?.originalArgs?.payload?.state === 'PUBLISHED'
) {
setCrosswalkPublished(true);
setPublishNotificationVisible(true);
setEditModeActive(false);
setLastPatchCrosswalkId(crosswalkPatchResponse.requestId);
refetchCrosswalkData();
setSelectedTab(0);
} else if (
!saveNotificationVisible &&
lastPatchCrosswalkId !== crosswalkPatchResponse.requestId
) {
// Operation is regular patch without publishing (save)
setLastPatchCrosswalkId(crosswalkPatchResponse.requestId);
refetchCrosswalkData();
setSaveNotificationVisible(true);
}
}

useEffect(() => {
// Reset initial state when tab changed.
if (selectedTab === 1) {
Expand Down Expand Up @@ -449,6 +422,9 @@ export default function CrosswalkEditor({
};

const performCallbackFromActionMenu = (action: any) => {
if (action === 'disableEdit') {
setEditModeActive(false);
}
if (action === 'edit') {
if (isEditModeActive) {
dispatch(setNotification('FINISH_EDITING_MAPPINGS'));
Expand Down Expand Up @@ -586,24 +562,6 @@ export default function CrosswalkEditor({
<CustomTabPanel value={selectedTab} index={2}>
</CustomTabPanel>*/}
<div className="row d-flex h-0">
{crosswalkPublished && publishNotificationVisible && (
<Notification
closeText="Close"
headingText="Crosswalk published successfully"
smallScreen
onCloseButtonClick={() =>
setPublishNotificationVisible(false)
}
></Notification>
)}
{saveNotificationVisible && (
<Notification
closeText="Close"
headingText="Crosswalk saved successfully"
smallScreen
onCloseButtonClick={() => setSaveNotificationVisible(false)}
></Notification>
)}
<div className={selectedTab === 1 ? 'col-10' : 'd-none'}></div>
<div
className={
Expand Down

0 comments on commit a3771b6

Please sign in to comment.