Skip to content

Commit

Permalink
MAT-7185: remove redundant fetch call for draft and only send id and …
Browse files Browse the repository at this point in the history
…name
  • Loading branch information
chubert-sb committed Aug 4, 2024
1 parent 73def11 commit 9c7f0c0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 42 deletions.
9 changes: 6 additions & 3 deletions src/api/useCqlLibraryServiceApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ export class CqlLibraryServiceApi {
);
}

async createDraft(cqlLibrary: CqlLibrary): Promise<void> {
async createDraft(
cqlLibraryId: string,
cqlLibraryName: string
): Promise<void> {
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()}`,
Expand Down
22 changes: 5 additions & 17 deletions src/components/cqlLibraryList/CqlLibraryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
});
Expand Down
23 changes: 2 additions & 21 deletions src/components/createDraftDialog/CreateDraftDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<MadieDialog
form
Expand Down

0 comments on commit 9c7f0c0

Please sign in to comment.