mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
CloudLogList: group by calendar days
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import _get from "lodash/get";
|
||||
import { differenceInCalendarDays } from "date-fns";
|
||||
|
||||
import { List, ListProps } from "@mui/material";
|
||||
import CloudLogSubheader from "./CloudLogSubheader";
|
||||
@@ -15,16 +16,43 @@ export default function CloudLogList({ items, ...props }: ICloudLogListProps) {
|
||||
const item = items[i];
|
||||
const prevItem = items[i - 1];
|
||||
|
||||
if (
|
||||
_get(item, "labels.execution_id") !==
|
||||
_get(prevItem, "labels.execution_id")
|
||||
) {
|
||||
renderedLogItems.push(
|
||||
<CloudLogSubheader key={_get(item, "labels.execution_id")}>
|
||||
Function <code>{_get(item, "resource.labels.function_name")}</code>{" "}
|
||||
execution <code>{_get(item, "labels.execution_id")}</code>
|
||||
</CloudLogSubheader>
|
||||
// Group by function execution ID if available
|
||||
if (item.labels.execution_id) {
|
||||
if (
|
||||
_get(item, "labels.execution_id") !==
|
||||
_get(prevItem, "labels.execution_id")
|
||||
) {
|
||||
renderedLogItems.push(
|
||||
<CloudLogSubheader key={_get(item, "labels.execution_id")}>
|
||||
Function{" "}
|
||||
<code>{_get(item, "resource.labels.function_name")}</code>{" "}
|
||||
execution <code>{_get(item, "labels.execution_id")}</code>
|
||||
</CloudLogSubheader>
|
||||
);
|
||||
}
|
||||
}
|
||||
// Otherwise, group by day
|
||||
else {
|
||||
const diff = differenceInCalendarDays(
|
||||
Date.now(),
|
||||
(_get(item, "timestamp.seconds") ?? 0) * 1000
|
||||
);
|
||||
const prevDiff = differenceInCalendarDays(
|
||||
Date.now(),
|
||||
(_get(prevItem, "timestamp.seconds") ?? 0) * 1000
|
||||
);
|
||||
|
||||
if (diff !== prevDiff) {
|
||||
renderedLogItems.push(
|
||||
<CloudLogSubheader key={`${diff} days ago`}>
|
||||
{diff === 0
|
||||
? "Today"
|
||||
: diff === 1
|
||||
? "Yesterday"
|
||||
: `${diff} days ago`}
|
||||
</CloudLogSubheader>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
renderedLogItems.push(
|
||||
|
||||
Reference in New Issue
Block a user