Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type NotificationSendHistory = {
duration_millis?: number | undefined;
created_at: string;
parent_id?: string;
group_id?: string;
};

export type NotificationSendHistoryApiResponse = NotificationSendHistory & {
Expand Down
31 changes: 26 additions & 5 deletions src/components/Notifications/NotificationSendHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,38 @@ export default function NotificationSendHistoryList({
const isOpen = searchParams.has("id");

const heirarchicalData = useMemo(() => {
const child = data.filter((row) => row.parent_id);
// The latest send history for each group
const groupLeader: Record<string, string> = {};
for (const row of data) {
if (row.group_id && !groupLeader[row.group_id]) {
groupLeader[row.group_id] = row.id;
}
}

// send histories in the same group should be grouped together
const histories = data.map((row) => {
if (row.parent_id || !row.group_id) {
return { ...row };
}

if (!groupLeader[row.group_id] || groupLeader[row.group_id] === row.id) {
return { ...row };
}

return {
...row,
parent_id: groupLeader[row.group_id]
};
});

return data
return histories
.filter((row) => !row.parent_id)
.map((row) => {
const children = child.filter((child) => child.parent_id === row.id);
const rowWithSubRows: NotificationSendHistoryWithSubRows = {
const children = histories.filter((c) => c.parent_id === row.id);
return {
...row,
subRows: children
};
return rowWithSubRows;
});
}, [data]);

Expand Down
Loading