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

Cscfc4 emscr 591 remove file upload from add revision modal for mscr format #230

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
9 changes: 9 additions & 0 deletions mscr-ui/src/common/components/schema/schema.slice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export const schemaApi = createApi({
},
})
}),
// this should be the API for creating revisions of schemas in MSCR format
putMscrSchemaRevision: builder.mutation<Schema, { pid: string; data: Partial<Metadata> }>({
query: ({pid, data }) => ({
url: `/schema?action=revisionOf&target=${pid}`,
method: 'PUT',
data: data,
})
}),
putSchemaMscrCopy: builder.mutation<Schema, { pid: string; data: Partial<Metadata> }>({
query: ({pid, data }) => ({
url: `/schema?action=mscrCopyOf&target=${pid}`,
Expand Down Expand Up @@ -182,6 +190,7 @@ export const {
useGetSchemasQuery,
usePutSchemaFullMutation,
usePutSchemaRevisionMutation,
usePutMscrSchemaRevisionMutation,
usePutSchemaMscrCopyMutation,
usePatchSchemaMutation,
usePatchSchemaRootSelectionMutation,
Expand Down
2 changes: 1 addition & 1 deletion mscr-ui/src/modules/form/generate-payload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function generatePayload(
}
} else if (modalType == ModalType.RevisionMscr) {
if (contentType == Type.Schema) {
const { namespace, organizations, format, ...revisionPayload } =
const { organizations, ...revisionPayload } =
schemaPayload;
return revisionPayload;
} else if (contentType == Type.Crosswalk) {
Expand Down
66 changes: 45 additions & 21 deletions mscr-ui/src/modules/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useTranslation } from 'next-i18next';
import getApiError from '@app/common/utils/getApiErrors';
import { useRouter } from 'next/router';
import {
usePutMscrSchemaRevisionMutation,
usePutSchemaFullMutation,
usePutSchemaMscrCopyMutation,
usePutSchemaRevisionMutation,
Expand Down Expand Up @@ -100,6 +101,8 @@ export default function FormModal({
const [putCrosswalkFull, resultCrosswalkFull] = usePutCrosswalkFullMutation();
const [putSchemaRevision, resultSchemaRevision] =
usePutSchemaRevisionMutation();
const [putMscrSchemaRevision, resultMscrSchemaRevision] =
usePutMscrSchemaRevisionMutation();
const [putCrosswalkRevision, resultCrosswalkRevision] =
usePutCrosswalkRevisionMutation();
const [putCrosswalkFullRevision, resultCrosswalkFullRevision] =
Expand All @@ -108,10 +111,9 @@ export default function FormModal({
usePutSchemaMscrCopyMutation();
const [submitAnimationVisible, setSubmitAnimationVisible] =
useState<boolean>(false);

const formDataFromInitialData = useCallback(() => {
if (!initialData) return;
const existingData: FormType = {
const existingData: FormType = {
format:
modalType == ModalType.MscrCopy ? Format.Mscr : initialData.format,
languages: [
Expand Down Expand Up @@ -202,6 +204,12 @@ export default function FormModal({
resultCrosswalkRevision.data
) {
pid = resultCrosswalkRevision.data.pid;
} else if (
contentType == Type.Schema &&
resultMscrSchemaRevision.isSuccess &&
resultMscrSchemaRevision.data
) {
pid = resultMscrSchemaRevision.data.pid;
}
break;
case ModalType.RevisionFull:
Expand Down Expand Up @@ -247,6 +255,8 @@ export default function FormModal({
resultSchemaMscrCopy.isSuccess,
resultSchemaRevision.data,
resultSchemaRevision.isSuccess,
resultMscrSchemaRevision.data,
resultMscrSchemaRevision.isSuccess,
]
);

Expand Down Expand Up @@ -325,6 +335,7 @@ export default function FormModal({
fileData,
fileUri
);

setErrors(formErrors);

if (
Expand All @@ -343,6 +354,7 @@ export default function FormModal({
modalType,
organizationPid
);

const newFormData = new FormData();
newFormData.append('metadata', JSON.stringify(payload));
if (fileUri && fileUri.length > 0) {
Expand All @@ -352,7 +364,6 @@ export default function FormModal({
} else if (formData.format !== Format.Mscr) {
return;
}

// Choose the api call and parameters according to content type and modal type
let makeApiCall;
if (modalType == ModalType.RegisterNewFull) {
Expand All @@ -364,6 +375,7 @@ export default function FormModal({
}
);
} else if (modalType == ModalType.RegisterNewMscr) {
//what is register new MSCR?
Promise.all([spinnerDelay(), putCrosswalk(payload)]).then((_values) => {
setSubmitAnimationVisible(false);
});
Expand Down Expand Up @@ -400,8 +412,20 @@ export default function FormModal({
]).then((_values) => {
setSubmitAnimationVisible(false);
});
// Creating revision of MSCR format schemas
} else if (
initialData &&
modalType == ModalType.RevisionMscr &&
contentType == Type.Schema
) {
Promise.all([
spinnerDelay(),
putMscrSchemaRevision({ pid: initialData.pid, data: payload }),
]).then((_values) => {
setSubmitAnimationVisible(false);
});
}
// Missing scenarios: MSCR copy of a crosswalk, revision of an MSCR copy
// Missing scenarios: MSCR copy of a crosswalk
}
};

Expand Down Expand Up @@ -565,19 +589,19 @@ export default function FormModal({
? modalType == ModalType.RegisterNewFull
? t('content-form.title.schema-register')
: modalType == ModalType.MscrCopy
? t('content-form.title.schema-mscr-copy')
: t('content-form.title.schema-revision')
? t('content-form.title.schema-mscr-copy')
: t('content-form.title.schema-revision')
: modalType == ModalType.RegisterNewFull
? t('content-form.title.crosswalk-register')
: modalType == ModalType.RegisterNewMscr
? t('content-form.title.crosswalk-create')
: modalType == ModalType.MscrCopy
? t('content-form.title.crosswalk-mscr-copy')
: t('content-form.title.crosswalk-revision')}
? t('content-form.title.crosswalk-register')
: modalType == ModalType.RegisterNewMscr
? t('content-form.title.crosswalk-create')
: modalType == ModalType.MscrCopy
? t('content-form.title.crosswalk-mscr-copy')
: t('content-form.title.crosswalk-revision')}
</ModalTitle>

{(modalType == ModalType.RegisterNewFull ||
modalType == ModalType.RevisionFull) &&
modalType == ModalType.RevisionFull) &&
renderFileDropArea()}

{contentType == Type.Schema && (
Expand Down Expand Up @@ -628,15 +652,15 @@ export default function FormModal({
? modalType == ModalType.RegisterNewFull
? t('content-form.button.schema-register')
: modalType == ModalType.MscrCopy
? t('content-form.button.mscr-copy')
: t('content-form.button.schema-revision')
? t('content-form.button.mscr-copy')
: t('content-form.button.schema-revision')
: modalType == ModalType.RegisterNewFull
? t('content-form.button.crosswalk-register')
: modalType == ModalType.RegisterNewMscr
? t('content-form.button.crosswalk-create')
: modalType == ModalType.MscrCopy
? t('content-form.button.mscr-copy')
: t('content-form.button.crosswalk-revision')}
? t('content-form.button.crosswalk-register')
: modalType == ModalType.RegisterNewMscr
? t('content-form.button.crosswalk-create')
: modalType == ModalType.MscrCopy
? t('content-form.button.mscr-copy')
: t('content-form.button.crosswalk-revision')}
</Button>
<Button variant="secondary" onClick={() => handleClose()}>
{userPosted ? t('close') : t('cancel')}
Expand Down
32 changes: 22 additions & 10 deletions mscr-ui/src/modules/schema-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,28 @@ export default function SchemaView({ schemaId }: { schemaId: string }) {
text1={t('confirm-modal.unset-root-selection')}
/>
)}
{/*ToDo: When making a revision of an mscr copy is possible, take that into account here (Modaltype.RevisionMscr)*/}
<FormModal
modalType={ModalType.RevisionFull}
contentType={Type.Schema}
visible={formModalIsOpen.version}
setVisible={(value) =>
dispatch(setFormModalState({ key: 'version', value: value }))
}
initialData={schemaData}
/>
{schemaData.format == Format.Mscr ? (
<FormModal
modalType={ModalType.RevisionMscr}
contentType={Type.Schema}
visible={formModalIsOpen.version}
setVisible={(value) =>
dispatch(setFormModalState({ key: 'version', value: value }))
}
initialData={schemaData}
/>
) : (
<FormModal
modalType={ModalType.RevisionFull}
contentType={Type.Schema}
visible={formModalIsOpen.version}
setVisible={(value) =>
dispatch(setFormModalState({ key: 'version', value: value }))
}
initialData={schemaData}
/>
)}

<FormModal
modalType={ModalType.MscrCopy}
contentType={Type.Schema}
Expand Down
Loading