Skip to content

Commit

Permalink
Sorted daily rounds by Measured At instead of Created at
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamprakash123 committed Nov 26, 2023
1 parent c37b554 commit c753f32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/CAREUI/misc/PaginatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function useContextualized<TItem>() {
interface Props<TItem> extends QueryOptions<PaginatedResponse<TItem>> {
route: QueryRoute<PaginatedResponse<TItem>>;
perPage?: number;
sortFunc?: (item1: any, item2: any) => number;
children: (
ctx: PaginatedListContext<TItem>,
query: ReturnType<typeof useQuery<PaginatedResponse<TItem>>>
Expand All @@ -42,6 +43,7 @@ interface Props<TItem> extends QueryOptions<PaginatedResponse<TItem>> {
export default function PaginatedList<TItem extends object>({
children,
route,
sortFunc,
perPage = DEFAULT_PER_PAGE_LIMIT,
...queryOptions
}: Props<TItem>) {
Expand All @@ -55,7 +57,11 @@ export default function PaginatedList<TItem extends object>({
},
});

const items = query.data?.results ?? [];
const items = query.data?.results
? sortFunc
? query.data?.results.sort(sortFunc)
: query.data?.results
: [];

return (
<context.Provider
Expand Down
6 changes: 6 additions & 0 deletions src/Components/Facility/Consultations/DailyRoundsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const DailyRoundsList = (props: any) => {
query={{
rounds_type: showAutomatedRounds ? "" : "NORMAL,VENTILATOR,ICU",
}}
sortFunc={(item1, item2) => {
const takenAt1 = item1.taken_at;
const takenAt2 = item2.taken_at;
return Number(new Date(takenAt2)) - Number(new Date(takenAt1));
}}
>
{(_) => (
<div className="-mt-2 flex w-full flex-col gap-4">
Expand All @@ -52,6 +57,7 @@ export const DailyRoundsList = (props: any) => {
/>
);
}
console.log(items);
return (
<DefaultLogUpdateCard
round={item}
Expand Down

0 comments on commit c753f32

Please sign in to comment.