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 5 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
31 changes: 27 additions & 4 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,12 +111,12 @@ export default function FormModal({
usePutSchemaMscrCopyMutation();
const [submitAnimationVisible, setSubmitAnimationVisible] =
useState<boolean>(false);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra whitespace

const formDataFromInitialData = useCallback(() => {
if (!initialData) return;
const existingData: FormType = {
format:
modalType == ModalType.MscrCopy ? Format.Mscr : initialData.format,
modalType == ModalType.MscrCopy? Format.Mscr : initialData.format,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a space between the conditional operators and the operands, so restore space between 'ModalType.MscrCopy' and '?'

languages: [
{
labelText: t('language-english-with-suffix'),
Expand Down Expand Up @@ -202,6 +205,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 +256,8 @@ export default function FormModal({
resultSchemaMscrCopy.isSuccess,
resultSchemaRevision.data,
resultSchemaRevision.isSuccess,
resultMscrSchemaRevision.data,
resultMscrSchemaRevision.isSuccess
]
);

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

setErrors(formErrors);

if (
Expand Down Expand Up @@ -352,6 +364,7 @@ export default function FormModal({
} else if (formData.format !== Format.Mscr) {
return;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental?

Copy link
Member Author

@rquazi rquazi Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be its my problem to add always some extra new lines as things look congested in my eye :)


// Choose the api call and parameters according to content type and modal type
let makeApiCall;
Expand All @@ -363,7 +376,7 @@ export default function FormModal({
setSubmitAnimationVisible(false);
}
);
} else if (modalType == ModalType.RegisterNewMscr) {
} else if (modalType == ModalType.RegisterNewMscr) {//what is register new MSCR?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the definition of the ModalType:

export enum ModalType {
  RegisterNewFull = 'REGISTER_NEW_FULL',
  RegisterNewMscr = 'REGISTER_NEW_MSCR',
  RevisionFull = 'REVISION_FULL',
  RevisionMscr = 'REVISION_MSCR',
  MscrCopy = 'MSCR_COPY',
}

RegisterNewMscr is registering something in MSCR-format, where there's no file sent, as opposed to RegisterNewFull, where there should also be a file attached. In practice it always means creating (and registering) a new crosswalk, since that's always MSCR-format.

Copy link
Member Author

@rquazi rquazi Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :) I was wondering what this action :)

Promise.all([spinnerDelay(), putCrosswalk(payload)]).then((_values) => {
setSubmitAnimationVisible(false);
});
Expand Down Expand Up @@ -400,8 +413,18 @@ 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
1 change: 1 addition & 0 deletions mscr-ui/src/modules/form/validate-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
formatsAvailableForSchemaRegistration,
} from '@app/common/interfaces/format.interface';


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for adding extra empty lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, just accidental !!

export interface InputErrors {
languageAmount: boolean;
titleAmount: string[];
Expand Down
31 changes: 22 additions & 9 deletions mscr-ui/src/modules/schema-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,28 @@ export default function SchemaView({ schemaId }: { schemaId: string }) {
/>
)}
{/*ToDo: When making a revision of an mscr copy is possible, take that into account here (Modaltype.RevisionMscr)*/}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ToDo is completed with your changes! :)

<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