diff --git a/package.json b/package.json index 61c9378d..b2ba8842 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ }, "dependencies": { "@madie/cql-antlr-parser": "^1.0.8", - "@madie/madie-design-system": "^1.2.37", + "@madie/madie-design-system": "^1.2.39", "@material-ui/core": "^4.12.4", "@mui/icons-material": "^5.5.1", "@mui/lab": "^5.0.0-alpha.73", diff --git a/src/CqlBuilderPanel/CqlBuilderPanel.tsx b/src/CqlBuilderPanel/CqlBuilderPanel.tsx index 227dfca0..fda312e0 100644 --- a/src/CqlBuilderPanel/CqlBuilderPanel.tsx +++ b/src/CqlBuilderPanel/CqlBuilderPanel.tsx @@ -247,6 +247,7 @@ export default function CqlBuilderPanel({ loading={loading} cql={measureStoreCql} isCQLUnchanged={isCQLUnchanged} + resetCql={resetCql} /> )} diff --git a/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx b/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx index 995a428b..6aca4988 100644 --- a/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx +++ b/src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx @@ -18,6 +18,7 @@ export interface FunctionProps { cql: string; isCQLUnchanged: boolean; functions?: FunctionLookup[]; + resetCql: Function; } const getArgumentNames = (logic: string) => { const args = logic.substring(logic.indexOf("(") + 1, logic.indexOf(")")); @@ -31,6 +32,7 @@ export default function FunctionsSection({ cql, isCQLUnchanged, cqlBuilderLookupsTypes, + resetCql, }: FunctionProps) { const [activeTab, setActiveTab] = useState("function"); @@ -94,6 +96,7 @@ export default function FunctionsSection({ functions={functionLookups} isCQLUnchanged={isCQLUnchanged} cql={cql} + resetCql={resetCql} /> )} diff --git a/src/CqlBuilderPanel/functionsSection/functions/Functions.tsx b/src/CqlBuilderPanel/functionsSection/functions/Functions.tsx index fa1fc66f..02648097 100644 --- a/src/CqlBuilderPanel/functionsSection/functions/Functions.tsx +++ b/src/CqlBuilderPanel/functionsSection/functions/Functions.tsx @@ -15,7 +15,10 @@ import ToolTippedIcon from "../../../toolTippedIcon/ToolTippedIcon"; import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline"; import BorderColorOutlinedIcon from "@mui/icons-material/BorderColorOutlined"; import Skeleton from "@mui/material/Skeleton"; -import { Pagination } from "@madie/madie-design-system/dist/react"; +import { + Pagination, + MadieConfirmDialog, +} from "@madie/madie-design-system/dist/react"; import Tooltip from "@mui/material/Tooltip"; const TH = tw.th`p-3 text-left text-sm font-bold capitalize`; @@ -39,6 +42,7 @@ const Functions = ({ loading, functions, isCQLUnchanged, + resetCql, }: FunctionProps) => { const [totalPages, setTotalPages] = useState(0); const [totalItems, setTotalItems] = useState(0); @@ -46,6 +50,12 @@ const Functions = ({ const [visibleFunctions, setVisibleFunctions] = useState( [] ); + const [selectedFunction, setSelectedFunction] = useState(); + const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); + const [discardDialog, setDiscardDialog] = useState({ + open: false, + operation: null, + }); const [offset, setOffset] = useState(0); const [currentLimit, setCurrentLimit] = useState(5); @@ -134,7 +144,14 @@ const Functions = ({ "data-testid": `delete-button-${row.cell.row.id}`, "aria-label": `delete-button-${row.cell.row.id}`, size: "small", - onClick: (e) => {}, + onClick: (e) => { + setSelectedFunction(row.row.original.name); + if (!isCQLUnchanged) { + setDiscardDialog({ open: true, operation: "delete" }); + } else { + setDeleteDialogOpen(true); + } + }, }} > @@ -262,6 +279,44 @@ const Functions = ({ hidePrevButton={!canGoPrev} /> + { + resetCql(); + if (discardDialog?.operation === "delete") { + setDiscardDialog({ + open: false, + operation: "delete", + }); + setDeleteDialogOpen(true); + } + }} + onClose={() => { + setDiscardDialog({ + open: false, + operation: null, + }); + }} + /> + { + //handleDefinitionDelete(selectedDefinition); + setDeleteDialogOpen(false); + }} + onClose={() => setDeleteDialogOpen(false)} + action="delete" + dialogTitle="Are you sure?" + name={"delete this Function"} + warning={"This action cannot be undone!"} + continueText="Yes, Delete" + /> ); };