fix: address CodeRabbit review findings
- docker-table: inspect refetch result instead of .catch() (TQ v5 compat) - rssFeed: sort all entries by date before slicing to max posts - toValidDate: reject null/boolean inputs before Date construction - system-resources: reset chart history when integrationIds changes - settleIntegrationQueries: wrap fn in async boundary for safe allSettled
This commit is contained in:
5 files changed
+18
-14
No files matched your search
@@ -163,19 +163,19 @@ export function DockerTable({ initialData }: DockerTableProps) {
|
|||||||
});
|
});
|
||||||
const relativeTime = useTimeAgo(data?.timestamp ?? new Date());
|
const relativeTime = useTimeAgo(data?.timestamp ?? new Date());
|
||||||
const mutate = useCallback(() => {
|
const mutate = useCallback(() => {
|
||||||
void refetch()
|
void refetch().then((result) => {
|
||||||
.then(() => {
|
if (result.isError) {
|
||||||
showSuccessNotification({
|
|
||||||
title: tDocker("action.refresh.notification.success.title"),
|
|
||||||
message: tDocker("action.refresh.notification.success.message"),
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
title: tDocker("action.refresh.notification.error.title"),
|
title: tDocker("action.refresh.notification.error.title"),
|
||||||
message: tDocker("action.refresh.notification.error.message"),
|
message: tDocker("action.refresh.notification.error.message"),
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
showSuccessNotification({
|
||||||
|
title: tDocker("action.refresh.notification.success.title"),
|
||||||
|
message: tDocker("action.refresh.notification.success.message"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}, [refetch, tDocker]);
|
}, [refetch, tDocker]);
|
||||||
|
|
||||||
const containers = data?.containers ?? [];
|
const containers = data?.containers ?? [];
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ export const rssFeedRouter = createTRPCRouter({
|
|||||||
logger.warn("RSS feed fetch failed", { url: urls[index], error: result.reason });
|
logger.warn("RSS feed fetch failed", { url: urls[index], error: result.reason });
|
||||||
return [];
|
return [];
|
||||||
})
|
})
|
||||||
.slice(0, input.maximumAmountPosts)
|
|
||||||
.toSorted((entryA, entryB) => {
|
.toSorted((entryA, entryB) => {
|
||||||
return entryA.published && entryB.published
|
return entryA.published && entryB.published
|
||||||
? new Date(entryB.published).getTime() - new Date(entryA.published).getTime()
|
? new Date(entryB.published).getTime() - new Date(entryA.published).getTime()
|
||||||
: 0;
|
: 0;
|
||||||
});
|
})
|
||||||
|
.slice(0, input.maximumAmountPosts);
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export async function settleIntegrationQueries<TIntegration extends IntegrationL
|
|||||||
integrations: TIntegration[],
|
integrations: TIntegration[],
|
||||||
fn: (integration: TIntegration) => Promise<TResult>,
|
fn: (integration: TIntegration) => Promise<TResult>,
|
||||||
): Promise<TResult[]> {
|
): Promise<TResult[]> {
|
||||||
const settled = await Promise.allSettled(integrations.map(fn));
|
const settled = await Promise.allSettled(integrations.map(async (integration) => fn(integration)));
|
||||||
return settled.flatMap((result, index) => {
|
return settled.flatMap((result, index) => {
|
||||||
if (result.status === "fulfilled") return [result.value];
|
if (result.status === "fulfilled") return [result.value];
|
||||||
const integration = integrations[index];
|
const integration = integrations[index];
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export function formatDuration(milliseconds: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const toValidDate = (value: unknown): Date | null => {
|
export const toValidDate = (value: unknown): Date | null => {
|
||||||
|
if (value == null || typeof value === "boolean") return null;
|
||||||
const date = value instanceof Date ? value : new Date(value as string | number);
|
const date = value instanceof Date ? value : new Date(value as string | number);
|
||||||
return Number.isFinite(date.getTime()) ? date : null;
|
return Number.isFinite(date.getTime()) ? date : null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,13 +44,16 @@ export default function SystemResources({ integrationIds, options }: WidgetCompo
|
|||||||
>(() => (data[0] ? [toChartItem(data[0].healthInfo)] : []));
|
>(() => (data[0] ? [toChartItem(data[0].healthInfo)] : []));
|
||||||
|
|
||||||
const lastUpdatedAt = useRef(dataUpdatedAt);
|
const lastUpdatedAt = useRef(dataUpdatedAt);
|
||||||
|
const prevIntegrationIds = useRef(integrationIds);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (dataUpdatedAt === lastUpdatedAt.current) return;
|
if (dataUpdatedAt === lastUpdatedAt.current) return;
|
||||||
lastUpdatedAt.current = dataUpdatedAt;
|
lastUpdatedAt.current = dataUpdatedAt;
|
||||||
const firstItem = data[0];
|
const firstItem = data[0];
|
||||||
if (!firstItem) return;
|
if (!firstItem) return;
|
||||||
setItems((prev) => [...prev, toChartItem(firstItem.healthInfo)].slice(-MAX_QUEUE_SIZE));
|
const idsChanged = prevIntegrationIds.current !== integrationIds;
|
||||||
}, [dataUpdatedAt, data]);
|
prevIntegrationIds.current = integrationIds;
|
||||||
|
setItems((prev) => (idsChanged ? [toChartItem(firstItem.healthInfo)] : [...prev, toChartItem(firstItem.healthInfo)].slice(-MAX_QUEUE_SIZE)));
|
||||||
|
}, [dataUpdatedAt, data, integrationIds]);
|
||||||
|
|
||||||
const showNetwork =
|
const showNetwork =
|
||||||
items.length === 0 || (items.every((item) => item.network !== null) && options.visibleCharts.includes("network"));
|
items.length === 0 || (items.every((item) => item.network !== null) && options.visibleCharts.includes("network"));
|
||||||
|
|||||||
Reference in new issue
Block a user