Skip to content

Commit

Permalink
insights->filtering (#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-aot authored May 16, 2024
1 parent 6998a91 commit 07b66e6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ const WorkList = () => {
showNotification("Error fetching works", { type: "error" });
}
}, [error]);

const federalInvolvements = useMemo(() => {
return Array.from(new Set(works.map((w) => w?.federal_involvement?.name)));
return Array.from(
new Set(
[...works]
.sort(
(a, b) =>
Number(a?.federal_involvement?.sort_order) -
Number(b?.federal_involvement?.sort_order)
)
.filter((p) => p.federal_involvement)
.map((w) => w?.federal_involvement?.name)
)
);
}, [works]);

const ministries = useMemo(() => {
Expand Down
5 changes: 5 additions & 0 deletions epictrack-web/src/models/federalInvolvement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ListType } from "./code";

export type FederalInvolvement = {
sort_order?: number;
} & ListType;
3 changes: 2 additions & 1 deletion epictrack-web/src/models/work.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ListType } from "./code";
import { FederalInvolvement } from "./federalInvolvement";
import { Ministry } from "./ministry";
import { Staff } from "./staff";
import { MasterBase } from "./type";
Expand Down Expand Up @@ -50,7 +51,7 @@ export interface Work extends MasterBase {
ministry: Ministry;
ea_act: ListType;
eao_team: ListType;
federal_involvement: ListType;
federal_involvement: FederalInvolvement;
responsible_epd: Staff;
work_lead: Staff;
work_type: ListType;
Expand Down
6 changes: 3 additions & 3 deletions epictrack-web/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const sort = (collection: any[], sortField: string) => {
sensitivity: "base",
});
const keys = sortField.split(".");
if (keys && keys.length === 0) {
if (keys.length > 1) {
return collection.sort(function (a, b) {
return collator.compare(a[sortField], b[sortField]);
return collator.compare(a[keys[0]][keys[1]], b[keys[0]][keys[1]]);
});
} else {
return collection.sort(function (a, b) {
return collator.compare(a[keys[0]][keys[1]], b[keys[0]][keys[1]]);
return collator.compare(a[sortField], b[sortField]);
});
}
};
Expand Down

0 comments on commit 07b66e6

Please sign in to comment.