From d4901f37b7a27e3512b9886133503c98b3a28c17 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Mon, 4 Sep 2023 08:48:14 +0100 Subject: [PATCH] update: Add toggle expand all button to table component --- src/components/accessories/table/Table.tsx | 13 ++++++++ .../accessories/table/TableBodyRow.tsx | 20 +++++------- src/components/accessories/table/styles.scss | 31 ++++++++++++------- src/components/accessories/table/types.ts | 1 + src/resources/i18n/en.json | 31 ++++++++++--------- 5 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/components/accessories/table/Table.tsx b/src/components/accessories/table/Table.tsx index a2dacb3c9..d58d8cce1 100644 --- a/src/components/accessories/table/Table.tsx +++ b/src/components/accessories/table/Table.tsx @@ -32,6 +32,8 @@ import { import ConfirmationDialog from "../confirmationDialog/ConfirmationDialog"; import { useTranslation } from "react-i18next"; import warningIcon from "../../../assets/warning-icon.png"; +import SmallButton from "../smallButton/SmallButton"; +import Button from "../button/Button"; const Table: FunctionComponent = ({ rowData, @@ -64,6 +66,7 @@ const Table: FunctionComponent = ({ const [openDeleteConfirmation, setOpenDeleteConfirmation] = useState(false); const [openCancelConfirmation, setOpenCancelConfirmation] = useState(false); const [currentRow, setCurrentRow] = useState({} as any); + const [expanded, setExpanded] = useState(false); const handleChangePage = (event: unknown, newPage: number) => { setPage(newPage); }; @@ -224,9 +227,18 @@ const Table: FunctionComponent = ({ setOpenCancelConfirmation(false); }; + const handleExpand = () => { + setExpanded(!expanded); + }; + return ( <> +
+ +
@@ -276,6 +288,7 @@ const Table: FunctionComponent = ({ showEmptyCell={showEmptyCell} renderCellDetails={renderItemDetails} detailColSpan={detailColSpan} + expanded={expanded} /> ))} diff --git a/src/components/accessories/table/TableBodyRow.tsx b/src/components/accessories/table/TableBodyRow.tsx index 39a2913f7..86eb4f978 100644 --- a/src/components/accessories/table/TableBodyRow.tsx +++ b/src/components/accessories/table/TableBodyRow.tsx @@ -20,19 +20,9 @@ const TableBodyRow: FunctionComponent = ({ renderCellDetails, coreRow, detailColSpan, + expanded, }) => { const [open, setOpen] = React.useState(false); - const isPrintMode = useMediaQuery("print"); - useHotkeys("ctrl+space", async (event, handler) => { - event.preventDefault(); - setOpen((previousState) => !previousState); - }); - - useEffect(() => { - if (!isPrintMode) { - setOpen(false); - } - }, [isPrintMode]); return ( <> @@ -44,7 +34,11 @@ const TableBodyRow: FunctionComponent = ({ size="small" onClick={() => setOpen(!open)} > - {open ? : } + {(expanded ? expanded : open) ? ( + + ) : ( + + )} ) : ( @@ -68,7 +62,7 @@ const TableBodyRow: FunctionComponent = ({ colSpan={detailColSpan ?? 6} > (row: T) => any; coreRow?: any; detailColSpan?: number; + expanded?: boolean; } export type TActions = diff --git a/src/resources/i18n/en.json b/src/resources/i18n/en.json index d093039a0..ad2c0e9c1 100644 --- a/src/resources/i18n/en.json +++ b/src/resources/i18n/en.json @@ -444,7 +444,8 @@ "thisyear": "This Year", "lastyear": "Last Year" }, - "continue": "Continue ?" + "continue": "Continue ?", + "toggle_expand_all": "Toggle Expand All" }, "permission": { "denied": "Permission denied", @@ -546,11 +547,11 @@ "statusmustbedone": "Exam status must be 'DONE' if results are provided", "changestatus": "Change Exam Status", "changelabstatusto": "The status of the exam {{code}} will be changed to {{status}}", - "statuses" : { - "DRAFT" : "DRAFT", - "ALL" : "ALL", - "OPEN" : "OPEN", - "DONE" : "DONE" + "statuses": { + "DRAFT": "DRAFT", + "ALL": "ALL", + "OPEN": "OPEN", + "DONE": "DONE" } }, "admission": { @@ -725,15 +726,15 @@ "elderly": "Elderly" }, "lab": { - "undefined" : {"txt": "Undefined"}, - "blood": {"txt": "Blood"}, - "cfs": {"txt": "CFS"}, - "film": {"txt": "FILM"}, - "sputum":{"txt": "Sputum"}, - "stool":{"txt": "Stool"}, - "swabs":{"txt": "Swabs"}, - "tissues":{"txt": "Tissues"}, - "urine":{"txt": "Urine"} + "undefined": { "txt": "Undefined" }, + "blood": { "txt": "Blood" }, + "cfs": { "txt": "CFS" }, + "film": { "txt": "FILM" }, + "sputum": { "txt": "Sputum" }, + "stool": { "txt": "Stool" }, + "swabs": { "txt": "Swabs" }, + "tissues": { "txt": "Tissues" }, + "urine": { "txt": "Urine" } } } }