Skip to content

Commit

Permalink
update: Add toggle expand all button to table component
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGT96 committed Sep 4, 2023
1 parent b273156 commit d4901f3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 39 deletions.
13 changes: 13 additions & 0 deletions src/components/accessories/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IProps> = ({
rowData,
Expand Down Expand Up @@ -64,6 +66,7 @@ const Table: FunctionComponent<IProps> = ({
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);
};
Expand Down Expand Up @@ -224,9 +227,18 @@ const Table: FunctionComponent<IProps> = ({
setOpenCancelConfirmation(false);
};

const handleExpand = () => {
setExpanded(!expanded);
};

return (
<>
<TableContainer component={Paper}>
<div className="header">
<Button type="button" onClick={handleExpand}>
{t("common.toggle_expand_all")}
</Button>
</div>
<MaterialComponent className="table" aria-label="simple table">
<TableHead className="table_header">
<TableRow>
Expand Down Expand Up @@ -276,6 +288,7 @@ const Table: FunctionComponent<IProps> = ({
showEmptyCell={showEmptyCell}
renderCellDetails={renderItemDetails}
detailColSpan={detailColSpan}
expanded={expanded}
/>
))}
</TableBody>
Expand Down
20 changes: 7 additions & 13 deletions src/components/accessories/table/TableBodyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@ const TableBodyRow: FunctionComponent<IRowProps> = ({
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 (
<>
Expand All @@ -44,7 +34,11 @@ const TableBodyRow: FunctionComponent<IRowProps> = ({
size="small"
onClick={() => setOpen(!open)}
>
{open ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
{(expanded ? expanded : open) ? (
<KeyboardArrowUp />
) : (
<KeyboardArrowDown />
)}
</IconButton>
</TableCell>
) : (
Expand All @@ -68,7 +62,7 @@ const TableBodyRow: FunctionComponent<IRowProps> = ({
colSpan={detailColSpan ?? 6}
>
<Collapse
in={isPrintMode ? isPrintMode : open}
in={expanded ? expanded : open}
timeout="auto"
unmountOnExit
className="collapseWrapper"
Expand Down
31 changes: 20 additions & 11 deletions src/components/accessories/table/styles.scss
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
@import "../../../styles/variables";
@import "../../../../node_modules/susy/sass/susy";
.header {
display: flex;
justify-content: end;
}


.table{
.table_header{
th{
.table {
@media print {
height: auto !important;
}
.table_header {
th {
text-transform: capitalize;
font-weight: 600;
}
}
.table_body{
.table_body {
@media print {
height: auto !important;
}
tr {
td.MuiTableCell-root{
td.MuiTableCell-root {
padding: 5px;
}
}
.collapseWrapper{
.collapseWrapper {
background: lighten($c-grey-lighter, 22%);
padding: 5px 5px;
flex: 1;
ul{
ul {
column-count: 2;
margin: 14px;
padding: 15px 27px;
@include susy-media($smartphone){
@include susy-media($smartphone) {
column-count: 1;
}
li{
li {
list-style: none;
}
li + li {
Expand All @@ -35,4 +44,4 @@
}
}
}
}
}
1 change: 1 addition & 0 deletions src/components/accessories/table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IRowProps {
renderCellDetails?: <T>(row: T) => any;
coreRow?: any;
detailColSpan?: number;
expanded?: boolean;
}

export type TActions =
Expand Down
31 changes: 16 additions & 15 deletions src/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@
"thisyear": "This Year",
"lastyear": "Last Year"
},
"continue": "Continue ?"
"continue": "Continue ?",
"toggle_expand_all": "Toggle Expand All"
},
"permission": {
"denied": "Permission denied",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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" }
}
}
}

0 comments on commit d4901f3

Please sign in to comment.