Skip to content

Commit

Permalink
Add Not Applicable option for filters in workplan page (#1109)
Browse files Browse the repository at this point in the history
* Add Not Applicable option for filters

* Fix missing highlight on select

* Change highlight background color

* Change blank option label and sort
  • Loading branch information
jadmsaadaot authored Oct 27, 2023
1 parent 0e7acbd commit ec13dd5
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 28 deletions.
19 changes: 18 additions & 1 deletion epictrack-web/src/components/shared/MasterTrackTable/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const BLANK_OPTION = "(Blanks)";
export function getSelectFilterOptions<T>(
data: T[],
key: keyof T,
Expand All @@ -9,7 +10,10 @@ export function getSelectFilterOptions<T>(
// Step 2: Iterate through the data array to populate the Map
data.forEach((dataObject) => {
// Step 3: Skip undefined or null values
if (dataObject[key] === undefined || dataObject[key] === null) return;
if (dataObject[key] === undefined || dataObject[key] === null) {
optionsMap.set("", BLANK_OPTION);
return;
}

// Step 4: Populate the Map with unique values and their formatted labels
optionsMap.set(dataObject[key], formatLabel(dataObject[key]));
Expand All @@ -21,6 +25,19 @@ export function getSelectFilterOptions<T>(
value: key,
}));

// Step 6: Sort the array by 'value' property
optionsArray.sort((a, b) => {
if (a.value === "") {
return -1;
}

if (b.value === "") {
return 1;
}

return a.value < b.value ? -1 : 1;
});

return optionsArray;
}

Expand Down
121 changes: 94 additions & 27 deletions epictrack-web/src/components/workPlan/event/EventListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getTextFromDraftJsContentState } from "../../shared/richTextEditor/util
import TableFilter from "../../shared/filterSelect/TableFilter";
import { Switch, Case } from "react-if";
import {
BLANK_OPTION,
getSelectFilterOptions,
rowsPerPageOptions,
} from "../../shared/MasterTrackTable/utils";
Expand All @@ -38,6 +39,8 @@ const useStyle = makeStyles({
},
});

const highlightedRowBGColor = "rgb(249, 249, 251)";

interface EventListTable {
onRowClick: (event: any, rowOriginal: any) => void;
events: EventsGridModel[];
Expand Down Expand Up @@ -88,24 +91,30 @@ const EventListTable = ({
const assigneeOptions = Array.from(
new Set(
events
.map((event) => event.assignees || [])
.map((event) => event.assignees || [""])
.flat()
.map(
(assignee) =>
`${assignee.assignee.first_name} ${assignee.assignee.last_name}`
.map((assignee) =>
assignee
? `${assignee.assignee.first_name} ${assignee.assignee.last_name}`
: BLANK_OPTION
)
)
);
const responsibilityFilterOptions = Array.from(
new Set(events.map((event) => event?.responsibility?.split(", ")).flat())
).filter((responsibility) => responsibility);
new Set(
events
.map((event) => event?.responsibility?.split(", "))
.flat()
.map((responsibility) => responsibility || BLANK_OPTION)
)
);

const statusFilterOptions = getSelectFilterOptions(
events,
"status",
(value) =>
statusOptions.find((statusOption) => statusOption.value == value)
?.label ?? ""
?.label ?? BLANK_OPTION
);

const columns = React.useMemo<MRT_ColumnDef<EventsGridModel>[]>(
Expand Down Expand Up @@ -145,7 +154,18 @@ const EventListTable = ({
/>
);
},
filterFn: "multiSelectFilter",
filterFn: (row, id, filterValue) => {
if (
!filterValue.length ||
filterValue.length > typeFilterOptions.length // select all is selected
) {
return true;
}

const value: string = row.getValue(id) || "";

return filterValue.includes(value);
},
filterSelectOptions: typeFilterOptions,
Cell: ({ cell, row }) => (
<ETParagraph bold={row.original.type === EVENT_TYPE.MILESTONE}>
Expand All @@ -168,7 +188,18 @@ const EventListTable = ({
/>
);
},
filterFn: "multiSelectFilter",
filterFn: (row, id, filterValue) => {
if (
!filterValue.length ||
filterValue.length > startDateFilterOptions.length // select all is selected
) {
return true;
}

const value: string = row.getValue(id) || "";

return filterValue.includes(value);
},
filterSelectOptions: startDateFilterOptions,
size: 140,
Cell: ({ cell, row }) => (
Expand Down Expand Up @@ -197,6 +228,18 @@ const EventListTable = ({
);
},
filterSelectOptions: endDateFilterOptions,
filterFn: (row, id, filterValue) => {
if (
!filterValue.length ||
filterValue.length > endDateFilterOptions.length // select all is selected
) {
return true;
}

const value: string = row.getValue(id) || "";

return filterValue.includes(value);
},
Cell: ({ cell, row }) => (
<ETParagraph
bold={row.original.type === EVENT_TYPE.MILESTONE}
Expand Down Expand Up @@ -224,7 +267,18 @@ const EventListTable = ({
/>
);
},
filterFn: "multiSelectFilter",
filterFn: (row, id, filterValue) => {
if (
!filterValue.length ||
filterValue.length > numberOfDaysFilterOptions.length // select all is selected
) {
return true;
}

const value: string = row.getValue(id) || "";

return filterValue.includes(value);
},
filterSelectOptions: numberOfDaysFilterOptions,
size: 100,
header: "Days",
Expand Down Expand Up @@ -255,13 +309,12 @@ const EventListTable = ({
filterFn: (row, id, filterValue) => {
if (
!filterValue.length ||
filterValue.length >= assigneeOptions.length
filterValue.length > assigneeOptions.length // select all is selected
) {
return true;
}

const renderedValue: string = row.renderValue(id);
if (!renderedValue) return false;
const renderedValue: string = row.renderValue(id) || BLANK_OPTION;
return filterValue.every((filterName: string) =>
renderedValue.includes(filterName)
);
Expand Down Expand Up @@ -299,13 +352,11 @@ const EventListTable = ({
filterFn: (row, id, filterValue) => {
if (
!filterValue.length ||
filterValue.length >= responsibilityFilterOptions.length
filterValue.length > responsibilityFilterOptions.length // select all is selected
) {
return true;
}
const value: string = row.getValue(id);

if (!value) return false;
const value: string = row.getValue(id) || BLANK_OPTION;

return filterValue.every((filterName: string) =>
value.includes(filterName)
Expand Down Expand Up @@ -349,7 +400,18 @@ const EventListTable = ({
/>
);
},
filterFn: "multiSelectFilter",
filterFn: (row, id, filterValue) => {
if (
!filterValue.length ||
filterValue.length > statusFilterOptions.length // select all is selected
) {
return true;
}

const value: string = row.getValue(id) || "";

return filterValue.includes(value);
},
filterSelectOptions: statusFilterOptions,
header: "Progress",
size: 150,
Expand Down Expand Up @@ -398,15 +460,20 @@ const EventListTable = ({
muiTablePaginationProps={{
rowsPerPageOptions: rowsPerPageOptions(events.length),
}}
muiTableBodyRowProps={({ row }) => ({
style: {
background:
row.original.type === highlightedRow?.type &&
row.original.id === highlightedRow?.id
? Palette.success.bg.light
: "inherit",
},
})}
muiTableBodyRowProps={({ row }) => {
if (
row.original.type === highlightedRow?.type &&
row.original.id === highlightedRow?.id
) {
return {
style: {
background: highlightedRowBGColor,
},
};
}

return {};
}}
state={{
isLoading: loading,
showGlobalFilter: true,
Expand Down

0 comments on commit ec13dd5

Please sign in to comment.