diff --git a/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.test.tsx b/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.test.tsx index d595a63f..086e1433 100644 --- a/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.test.tsx +++ b/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.test.tsx @@ -141,12 +141,6 @@ describe("Saved Codes section component", () => { expect(getByTestId("saved-code-row-0")).toBeInTheDocument(); - await waitFor(() => { - const selectButton = getByTestId(`select-action-0_apply`); - expect(selectButton).toBeInTheDocument(); - userEvent.click(selectButton); - }); - const editButton = getByTestId(`edit-code-0`); expect(editButton).toBeInTheDocument(); @@ -184,11 +178,7 @@ describe("Saved Codes section component", () => { parsedCodesList={parsedCodesList} /> ); - await waitFor(() => { - const selectButton = getByTestId(`select-action-0_apply`); - expect(selectButton).toBeInTheDocument(); - userEvent.click(selectButton); - }); + await checkRows(2); const editButton = getByTestId(`edit-code-0`); userEvent.click(editButton); await waitFor(() => { @@ -225,12 +215,6 @@ describe("Saved Codes section component", () => { expect(getByTestId("saved-code-row-0")).toBeInTheDocument(); - await waitFor(() => { - const selectButton = getByTestId(`select-action-0_apply`); - expect(selectButton).toBeInTheDocument(); - userEvent.click(selectButton); - }); - const editButton = getByTestId(`edit-code-0`); expect(editButton).toBeInTheDocument(); @@ -267,12 +251,6 @@ describe("Saved Codes section component", () => { ); await checkRows(2); - await waitFor(() => { - const selectButton = getByTestId(`select-action-0_apply`); - expect(selectButton).toBeInTheDocument(); - userEvent.click(selectButton); - }); - const removeButton = getByTestId(`remove-code-0`); expect(removeButton).toBeInTheDocument(); @@ -301,12 +279,6 @@ describe("Saved Codes section component", () => { ); await checkRows(2); - await waitFor(() => { - const selectButton = getByTestId(`select-action-0_apply`); - expect(selectButton).toBeInTheDocument(); - userEvent.click(selectButton); - }); - const removeButton = getByTestId(`remove-code-0`); expect(removeButton).toBeInTheDocument(); @@ -341,12 +313,6 @@ describe("Saved Codes section component", () => { ); await checkRows(2); - await waitFor(() => { - const selectButton = getByTestId(`select-action-0_apply`); - expect(selectButton).toBeInTheDocument(); - userEvent.click(selectButton); - }); - const removeButton = getByTestId(`remove-code-0`); expect(removeButton).toBeInTheDocument(); diff --git a/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.tsx b/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.tsx index 2fa007f9..1d954530 100644 --- a/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.tsx +++ b/src/CqlBuilderPanel/codesSection/codesSubSection/savedCodesSubSection/SavedCodesSubSection.tsx @@ -22,6 +22,8 @@ import DoDisturbOutlinedIcon from "@mui/icons-material/DoDisturbOutlined"; import DoNotDisturbOnIcon from "@mui/icons-material/DoNotDisturbOn"; import CheckCircleIcon from "@mui/icons-material/CheckCircle"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; +import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline"; +import BorderColorOutlinedIcon from "@mui/icons-material/BorderColorOutlined"; import useTerminologyServiceApi, { Code, } from "../../../../api/useTerminologyServiceApi"; @@ -109,8 +111,7 @@ export default function SavedCodesSubSection({ setToastOpen(false); }; const [loading, setLoading] = useState(false); - const [optionsOpen, setOptionsOpen] = useState(false); - const [anchorEl, setAnchorEl] = useState(null); + const [selectedReferenceId, setSelectedReferenceId] = useState(null); const [selectedCodeDetails, setSelectedCodeDetails] = useState(null); @@ -146,9 +147,7 @@ export default function SavedCodesSubSection({ selectedId, event: React.MouseEvent ) => { - setOptionsOpen(true); setSelectedReferenceId(selectedId); - setAnchorEl(event.currentTarget); setSelectedCodeDetails(table.getRow(selectedId).original); }; @@ -220,20 +219,47 @@ export default function SavedCodesSubSection({ header: "", accessorKey: "apply", cell: (row: any) => ( -
+
{canEdit ? ( - + <> + { + setSelectedCodeDetails( + table.getRow(row.cell.row.id).original + ); + if (!isCQLUnchanged) { + setDiscardDialogOpen(true); + } else { + setDeleteDialogModalOpen(true); + } + }, + }} + > + + + { + const selectedCode = table.getRow( + row.cell.row.id + ).original; + setSelectedCodeDetails(selectedCode); + handleEditCode(selectedCode); + }, + }} + > + + + ) : ( "" )} @@ -302,24 +328,17 @@ export default function SavedCodesSubSection({ ); }; - const handleClose = () => { - setOptionsOpen(false); - setSelectedReferenceId(null); - setAnchorEl(null); - }; - const toggleEditCodeDialogState = () => { setOpenEditCodeDialog(!open); }; - const handleEditCode = () => { - setOptionsOpen(false); + const handleEditCode = (selectedCode) => { setOpenEditCodeDialog(true); const parsedCode = parsedCodesList.find( - (parsedCode) => parsedCode.code === selectedCodeDetails.name + (parsedCode) => parsedCode.code === selectedCode.name ); setSelectedCodeDetails({ - ...selectedCodeDetails, + ...selectedCode, suffix: parsedCode?.suffix, versionIncluded: parsedCode.versionIncluded, }); @@ -400,32 +419,6 @@ export default function SavedCodesSubSection({
)} - - { - setOptionsOpen(false); - if (!isCQLUnchanged) { - setDiscardDialogOpen(true); - } else { - setDeleteDialogModalOpen(true); - } - }, - dataTestId: `remove-code-${selectedReferenceId}`, - }} - otherSelectOptionProps={[ - { - label: "Edit", - toImplementFunction: () => handleEditCode(), - dataTestId: `edit-code-${selectedReferenceId}`, - }, - ]} - />