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

MAT-7185: refactor library drafting #153

Merged
merged 1 commit into from
Aug 9, 2024
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: 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
Loading