Skip to content

Commit

Permalink
OH2-281 | add filter functionality to table component (#582)
Browse files Browse the repository at this point in the history
* feature(OH2-276): Implement main menu + sidemenu navigation

* update: Update routes paths

* update: Apply requested/suggested changes

* update: Add hospital infos

* update: Update admin sidemenu responsiveness

* styles: Update admin sidebar styles

* styles: Update MenuItem styles

* feature: Add ward list

* styles: Update component styles

* feature: Add ward edit/new form

* feature: Implement  ward crud operations

* update: Update form field values formatting

* update: Add filter button component and update table component

* styles: Update admin content width and remove unused import

* update: Optimize import and sync permissionList fixtures

* update: Add filter functionality to table component

* fix: Fix number filter

* update: Update table filter and add props doc

* fix: Fix filter for select fields

* update: Update table header

* update: Prevent filter change dispatch when the filter is automatic

* update: Remove unused file and update filter props doc

* update: Update ward form cancel action

* update: Update filter menu

* fix(ADMIN): Fix admin side menu active section

---------

Co-authored-by: SteveGT96 <[email protected]>
  • Loading branch information
SteveGT96 and SteveGT96 authored May 21, 2024
1 parent e0a4890 commit 62829fc
Show file tree
Hide file tree
Showing 19 changed files with 537 additions and 229 deletions.
4 changes: 0 additions & 4 deletions src/components/accessories/admin/wards/Wards.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
display: flex;
flex-direction: column;
}
.actions {
display: flex;
justify-content: end;
}
29 changes: 16 additions & 13 deletions src/components/accessories/admin/wards/Wards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ export const Wards = () => {

return (
<div className={classes.wards}>
<div className={classes.actions}>
<Button
onClick={() => {
navigate("./new");
}}
type="button"
variant="contained"
color="primary"
>
{t("ward.addWard")}
</Button>
</div>
<WardTable onEdit={handleEdit} onDelete={handleDelete} />
<WardTable
onEdit={handleEdit}
onDelete={handleDelete}
headerActions={
<Button
onClick={() => {
navigate("./new");
}}
type="button"
variant="contained"
color="primary"
>
{t("ward.addWard")}
</Button>
}
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const EditWard = () => {
creationMode={false}
onSubmit={handleSubmit}
isLoading={!!update.isLoading}
resetButtonLabel={t("common.reset")}
resetButtonLabel={t("common.cancel")}
submitButtonLabel={t("ward.updateWard")}
fields={getInitialFields(state)}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/accessories/admin/wards/newWard/NewWard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const NewWard = () => {
creationMode
onSubmit={handleSubmit}
isLoading={!!create.isLoading}
resetButtonLabel={t("common.reset")}
resetButtonLabel={t("common.cancel")}
submitButtonLabel={t("ward.saveWard")}
fields={getInitialFields(undefined)}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/accessories/admin/wards/wardForm/WardForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const WardForm: FC<IWardProps> = ({

const handleResetConfirmation = () => {
setOpenResetConfirmation(false);
resetForm();
navigate(-1);
};

const handleCheckboxChange = useCallback(
Expand Down Expand Up @@ -299,7 +299,7 @@ const WardForm: FC<IWardProps> = ({
title={resetButtonLabel.toUpperCase()}
info={t("common.resetform")}
icon={warningIcon}
primaryButtonLabel={resetButtonLabel}
primaryButtonLabel={t("common.ok")}
secondaryButtonLabel={t("common.discard")}
handlePrimaryButtonClick={handleResetConfirmation}
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
Expand Down
27 changes: 16 additions & 11 deletions src/components/accessories/admin/wards/wardTable/WardTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent, useRef } from "react";
import React, { FunctionComponent, ReactNode, useRef } from "react";
import Table from "../../../table/Table";
import { useTranslation } from "react-i18next";
import InfoBox from "../../../infoBox/InfoBox";
Expand All @@ -12,15 +12,18 @@ import classes from "./WardTable.module.scss";
import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog";
import checkIcon from "../../../../../assets/check-icon.png";
import { deleteWardReset } from "../../../../../state/ward/actions";
import { TFilterField } from "../../../table/filter/types";

interface IOwnProps {
onEdit: (row: any) => void;
onDelete: (row: any) => void;
headerActions?: ReactNode;
}

export const WardTable: FunctionComponent<IOwnProps> = ({
onEdit,
onDelete,
headerActions,
}) => {
const dispatch = useDispatch();
const { t } = useTranslation();
Expand Down Expand Up @@ -53,16 +56,13 @@ export const WardTable: FunctionComponent<IOwnProps> = ({
fax: t("ward.fax"),
visitDuration: t("ward.visitDuration"),
};
const order = [
"code",
"description",
"beds",
"nurs",
"docs",
"opd",
"pharmacy",
"male",
"female",
const order = ["code", "description", "beds", "nurs", "docs"];

const filters: TFilterField[] = [
{ key: "pharmacy", label: t("ward.pharmacy"), type: "boolean" },
{ key: "male", label: t("ward.male"), type: "boolean" },
{ key: "female", label: t("ward.female"), type: "boolean" },
{ key: "opd", label: t("ward.opd"), type: "boolean" },
];

const { data, status, error } = useSelector<IState, IApiResponse<WardDTO[]>>(
Expand Down Expand Up @@ -127,6 +127,11 @@ export const WardTable: FunctionComponent<IOwnProps> = ({
onEdit={handleEdit}
onDelete={handleDelete}
showEmptyCell={false}
filterColumns={filters}
rawData={data}
manualFilter={false}
rowKey="code"
headerActions={headerActions}
/>
{deleteWard.status === "FAIL" && (
<div ref={infoBoxRef} className="info-box-container">
Expand Down
2 changes: 2 additions & 0 deletions src/components/accessories/checkboxField/CheckboxField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CheckboxField: FunctionComponent<IProps> = ({
disabled,
label,
onChange,
indeterminate,
}) => {
const [value, setValue] = useState<boolean>(false);

Expand All @@ -28,6 +29,7 @@ const CheckboxField: FunctionComponent<IProps> = ({
checked={value}
onChange={handleChange}
name={fieldName}
indeterminate={indeterminate}
/>
}
label={label}
Expand Down
1 change: 1 addition & 0 deletions src/components/accessories/checkboxField/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface IProps {
fieldName: string;
checked: boolean;
disabled?: boolean;
indeterminate?: boolean;
label: string;
onChange: (value: boolean) => void;
}
Loading

0 comments on commit 62829fc

Please sign in to comment.