diff --git a/src/api/useCqlLibraryServiceApi.tsx b/src/api/useCqlLibraryServiceApi.tsx index 7585c18..24ad830 100644 --- a/src/api/useCqlLibraryServiceApi.tsx +++ b/src/api/useCqlLibraryServiceApi.tsx @@ -80,10 +80,13 @@ export class CqlLibraryServiceApi { ); } - async createDraft(cqlLibrary: CqlLibrary): Promise { + async createDraft( + cqlLibraryId: string, + cqlLibraryName: string + ): Promise { return await axios.post( - `${this.baseUrl}/cql-libraries/draft/${cqlLibrary.id}`, - cqlLibrary, + `${this.baseUrl}/cql-libraries/draft/${cqlLibraryId}`, + { cqlLibraryName: cqlLibraryName }, { headers: { Authorization: `Bearer ${this.getAccessToken()}`, diff --git a/src/components/cqlLibraryList/CqlLibraryList.tsx b/src/components/cqlLibraryList/CqlLibraryList.tsx index 32b72bd..5d94638 100644 --- a/src/components/cqlLibraryList/CqlLibraryList.tsx +++ b/src/components/cqlLibraryList/CqlLibraryList.tsx @@ -110,7 +110,7 @@ export default function CqlLibraryList({ cqlLibraryList, onListUpdate }) { const createDraft = async (cqlLibrary: CqlLibrary) => { await cqlLibraryServiceApi - .createDraft(cqlLibrary) + .createDraft(cqlLibrary.id, cqlLibrary.cqlLibraryName) .then(async () => { handleDialogClose(); await onListUpdate(); @@ -215,22 +215,10 @@ export default function CqlLibraryList({ cqlLibraryList, onListUpdate }) { }; const onDraftClicked = (selectedCQLLibrary: CqlLibrary) => { - cqlLibraryServiceApi - .fetchCqlLibrary(selectedCQLLibrary.id) - .then((cqlLibrary) => { - setSelectedCqlLibrary(cqlLibrary); - setCreateDraftDialog({ - open: true, - cqlLibrary: cqlLibrary, - }); - }) - .catch(() => { - setSnackBar({ - message: "An error occurred while fetching the CQL Library!", - open: true, - severity: "error", - }); - }); + setCreateDraftDialog({ + open: true, + cqlLibrary: selectedCQLLibrary, + }); setOptionsOpen(false); setAnchorEl(null); }; diff --git a/src/components/createDraftDialog/CreateDraftDialog.test.tsx b/src/components/createDraftDialog/CreateDraftDialog.test.tsx index b84c99e..25e9aac 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.test.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.test.tsx @@ -205,7 +205,6 @@ describe("Create Draft Dialog component", () => { await waitFor(() => { expect(onSubmitFn).toHaveBeenCalledWith({ ...cqlLibrary, - cql: "library TestingLibraryName12 version '0.0.000'\nusing QICore version '4.1.1'\n", cqlLibraryName: "TestingLibraryName12", }); }); diff --git a/src/components/createDraftDialog/CreateDraftDialog.tsx b/src/components/createDraftDialog/CreateDraftDialog.tsx index 5b23e41..da96973 100644 --- a/src/components/createDraftDialog/CreateDraftDialog.tsx +++ b/src/components/createDraftDialog/CreateDraftDialog.tsx @@ -34,29 +34,10 @@ const CreatDraftDialog = ({ ), }), enableReinitialize: true, - onSubmit: async ({ cqlLibraryName }) => submitForm(cqlLibraryName), + onSubmit: async ({ cqlLibraryName }) => + onSubmit({ ...cqlLibrary, cqlLibraryName }), }); - const submitForm = async (cqlLibraryName: string) => { - const cqlContents = cqlLibrary?.cql?.split("\n"); - let cql = cqlLibrary?.cql; - const previousLibraryName = cqlLibrary?.cqlLibraryName; - // make sure cql is updated with new library name, if it is changed - if ( - previousLibraryName !== cqlLibraryName && - cql && - cqlContents[0].includes(cqlLibrary.cqlLibraryName) - ) { - cqlContents[0] = `library ${cqlLibraryName} version '${cqlLibrary.version}'`; - cql = cqlContents.join("\n"); - } - return onSubmit({ - ...cqlLibrary, - cqlLibraryName, - cql, - }); - }; - return (