Skip to content

Commit

Permalink
Merge branch 'develop' into MAT-7872/displayingNoResultsFoundInSavedD…
Browse files Browse the repository at this point in the history
…efinitionsAndParameters
  • Loading branch information
sb-prateekkeerthi committed Nov 15, 2024
2 parents b0cbb1a + 8604ac7 commit 0021b7c
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/AceEditor/madie-ace-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface EditorPropsType {
parameter: Parameter,
parameterToApply: Parameter
) => void;
handleParameterDelete?: (parameter: Parameter) => void;
handleApplyValueSet?: (vs: ValueSetForSearch) => void;
handleApplyDefinition?: (def: Definition) => void;
handleDefinitionEdit?: (lib: SelectedLibrary, def: Definition) => void;
Expand Down
3 changes: 3 additions & 0 deletions src/CqlBuilderPanel/CqlBuilderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function CqlBuilderPanel({
handleApplyCode,
handleApplyParameter,
handleParameterEdit,
handleParameterDelete,
handleApplyValueSet,
handleApplyDefinition,
handleDefinitionEdit,
Expand Down Expand Up @@ -217,6 +218,8 @@ export default function CqlBuilderPanel({
<Parameters
canEdit={canEdit}
handleApplyParameter={handleApplyParameter}
handleParameterEdit={handleParameterEdit}
handleParameterDelete={handleParameterDelete}
cqlBuilderLookupsTypes={cqlBuilderLookupsTypes}
isCQLUnchanged={isCQLUnchanged}
cql={measureStoreCql}
Expand Down
107 changes: 107 additions & 0 deletions src/CqlBuilderPanel/Parameters/SavedParameters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,111 @@ describe("SavedParameters Component tests", () => {
expect(screen.getByText("Test Period 6")).toBeInTheDocument();
});
});

it("test cancel delete parameter when CQL is unchanged", async () => {
render(
<SavedParameters
canEdit={true}
parameters={saveParameters}
isCQLUnchanged={true}
cql="test CQL"
setEditorValue={setEditorValue}
handleApplyParameter={handleApplyParameter}
handleParameterEdit={handleParameterEdit}
handleParameterDelete={handleParameterDelete}
resetCql={resetCql}
loading={false}
/>
);

const deleteBtn = screen.getByTestId("delete-button-0");
expect(deleteBtn).toBeInTheDocument();

userEvent.click(deleteBtn);
expect(screen.getByTestId("delete-dialog")).toBeInTheDocument();
expect(screen.getByText("Are you sure?")).toBeInTheDocument();

const cancelBtn = screen.getByTestId("delete-dialog-cancel-button");
const continueDeleteBtn = screen.getByTestId(
"delete-dialog-continue-button"
);
expect(cancelBtn).toBeInTheDocument();
expect(continueDeleteBtn).toBeInTheDocument();

userEvent.click(cancelBtn);

expect(screen.getByTestId("parameters-row-0")).toBeInTheDocument();
expect(handleParameterDelete).not.toBeCalled();
});

it("test continue delete parameter when CQL is unchanged", async () => {
render(
<SavedParameters
canEdit={true}
parameters={saveParameters}
isCQLUnchanged={true}
cql="test CQL"
setEditorValue={setEditorValue}
handleApplyParameter={handleApplyParameter}
handleParameterEdit={handleParameterEdit}
handleParameterDelete={handleParameterDelete}
resetCql={resetCql}
loading={false}
/>
);

const deleteBtn = screen.getByTestId("delete-button-0");
expect(deleteBtn).toBeInTheDocument();

userEvent.click(deleteBtn);
expect(screen.getByTestId("delete-dialog")).toBeInTheDocument();
expect(screen.getByText("Are you sure?")).toBeInTheDocument();

const cancelBtn = screen.getByTestId("delete-dialog-cancel-button");
const continueDeleteBtn = screen.getByTestId(
"delete-dialog-continue-button"
);
expect(cancelBtn).toBeInTheDocument();
expect(continueDeleteBtn).toBeInTheDocument();

userEvent.click(continueDeleteBtn);

expect(screen.getByTestId("parameters-row-0")).toBeInTheDocument();
expect(handleParameterDelete).toBeCalled();
});

it("test delete parameter discard changes when cql has changes", async () => {
render(
<SavedParameters
canEdit={true}
parameters={saveParameters}
isCQLUnchanged={false}
cql="test CQL"
setEditorValue={setEditorValue}
handleApplyParameter={handleApplyParameter}
handleParameterEdit={handleParameterEdit}
handleParameterDelete={handleParameterDelete}
resetCql={resetCql}
loading={false}
/>
);

const deleteBtn = screen.getByTestId("delete-button-0");
expect(deleteBtn).toBeInTheDocument();

userEvent.click(deleteBtn);
expect(screen.getByTestId("discard-dialog")).toBeInTheDocument();
expect(screen.getByText("Discard Changes?")).toBeInTheDocument();
expect(screen.getByText("You have unsaved changes.")).toBeInTheDocument();

const cancelBtn = screen.getByTestId("discard-dialog-cancel-button");
const discardBtn = screen.getByTestId("discard-dialog-continue-button");
expect(cancelBtn).toBeInTheDocument();
expect(discardBtn).toBeInTheDocument();

userEvent.click(discardBtn);

expect(screen.getByTestId("delete-dialog")).toBeInTheDocument();
expect(screen.getByText("Are you sure?")).toBeInTheDocument();
});
});
40 changes: 38 additions & 2 deletions src/CqlBuilderPanel/Parameters/SavedParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "styled-components/macro";
import {
Pagination,
MadieDiscardDialog,
MadieDeleteDialog,
} from "@madie/madie-design-system/dist/react";
import Skeleton from "@mui/material/Skeleton";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
Expand All @@ -20,6 +21,7 @@ import { Lookup } from "../../model/CqlBuilderLookup";
import { Stack } from "@mui/material";
import { ParametersProps } from "./Parameters";
import EditParameterDialog from "./EditParameterDialog";
import { Parameter } from "./ParameterBuilder";

const TH = tw.th`p-3 text-left text-sm font-bold capitalize`;
const TD = tw.td`p-3 text-left text-sm break-all`;
Expand All @@ -36,7 +38,7 @@ const SavedParameters = ({
loading,
}: ParametersProps) => {
const [selectedParameter, setSelectedParameter] = useState<Lookup>();

const [parameterToDelete, setParameterToDelete] = useState<Parameter>();
const [totalPages, setTotalPages] = useState<number>(0);
const [totalItems, setTotalItems] = useState<number>(0);
const [visibleItems, setVisibleItems] = useState<number>(0);
Expand All @@ -47,6 +49,7 @@ const SavedParameters = ({
});

const [openParameterDialog, setOpenParameterDialog] = useState<boolean>();
const [deleteDialogOpen, setDeleteDialogOpen] = useState<boolean>(false);

const [offset, setOffset] = useState<number>(0);
const [currentLimit, setCurrentLimit] = useState<number>(5);
Expand Down Expand Up @@ -97,7 +100,24 @@ const SavedParameters = ({
"aria-label": `delete-button-${row.cell.row.id}`,
size: "small",
onClick: (e) => {
setSelectedParameter(row.row.original.name);
const seletedParameter = table.getRow(
row.cell.row.id
).original;
const parameterToDelete = {
parameterName: seletedParameter.name,
expression:
seletedParameter.logic?.slice(0, 1).toUpperCase() +
seletedParameter.logic?.slice(
1,
seletedParameter.logic?.length
),
} as Parameter;
setParameterToDelete(parameterToDelete);
if (!isCQLUnchanged) {
setDiscardDialog({ open: true, operation: "delete" });
} else {
setDeleteDialogOpen(true);
}
},
}}
>
Expand Down Expand Up @@ -219,6 +239,16 @@ const SavedParameters = ({
))}
</tbody>
</table>
<MadieDeleteDialog
open={deleteDialogOpen}
onContinue={() => {
handleParameterDelete(parameterToDelete);
setDeleteDialogOpen(false);
}}
onClose={() => setDeleteDialogOpen(false)}
dialogTitle="Are you sure?"
name={"this Parameter"}
/>
<MadieDiscardDialog
open={discardDialog?.open}
onContinue={() => {
Expand All @@ -229,6 +259,12 @@ const SavedParameters = ({
operation: "edit",
});
setOpenParameterDialog(true);
} else if (discardDialog?.operation === "delete") {
setDiscardDialog({
open: false,
operation: "delete",
});
setDeleteDialogOpen(true);
}
}}
onClose={() => {
Expand Down
2 changes: 2 additions & 0 deletions src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const CqlEditorWithTerminology = ({
handleApplyCode,
handleApplyParameter,
handleParameterEdit,
handleParameterDelete,
handleApplyValueSet,
handleApplyDefinition,
handleApplyLibrary,
Expand Down Expand Up @@ -111,6 +112,7 @@ const CqlEditorWithTerminology = ({
handleApplyCode={handleApplyCode}
handleApplyParameter={handleApplyParameter}
handleParameterEdit={handleParameterEdit}
handleParameterDelete={handleParameterDelete}
handleApplyValueSet={handleApplyValueSet}
handleApplyDefinition={handleApplyDefinition}
handleDefinitionEdit={handleDefinitionEdit}
Expand Down

0 comments on commit 0021b7c

Please sign in to comment.