diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 9ffee2f77..36605e1b7 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@instill-ai/toolkit", - "version": "0.110.0-rc.90", + "version": "0.110.0-rc.91", "description": "Instill AI's frontend toolkit", "repository": "https://github.com/instill-ai/design-system.git", "bugs": "https://github.com/instill-ai/design-system/issues", diff --git a/packages/toolkit/src/lib/dashboard/getModelTriggersSummary.ts b/packages/toolkit/src/lib/dashboard/getModelTriggersSummary.ts index 375c09edd..2b2a7db1e 100644 --- a/packages/toolkit/src/lib/dashboard/getModelTriggersSummary.ts +++ b/packages/toolkit/src/lib/dashboard/getModelTriggersSummary.ts @@ -1,47 +1,28 @@ -// import { -// ModelTriggersStatusSummary, -// ModelTriggerTableRecord, -// } from "instill-sdk"; +import { ModelTriggerCountRecord, ModelTriggersStatusSummary } from "instill-sdk"; -// import { calculatePercentageDelta } from "./calculatePercentageDelta"; +export function getModelTriggersSummary( + modelTriggerCounts: ModelTriggerCountRecord[] +): ModelTriggersStatusSummary { + const completedModel = modelTriggerCounts.find( + (r) => r.status === "STATUS_COMPLETED" + ); -// export function getModelTriggersSummary( -// models: ModelTriggerTableRecord[], -// modelsPrevious: ModelTriggerTableRecord[], -// ): ModelTriggersStatusSummary { -// let modelCompleteAmount = 0; -// let modelCompleteAmountPrevious = 0; -// let modelErroredAmount = 0; -// let modelErroredAmountPrevious = 0; + const erroredModel = modelTriggerCounts.find( + (r) => r.status === "STATUS_ERRORED" + ); -// models.forEach((model) => { -// modelCompleteAmount += Number(model.triggerCountCompleted); -// modelErroredAmount += Number(model.triggerCountErrored); -// }); - -// modelsPrevious.forEach((model) => { -// modelCompleteAmountPrevious += Number(model.triggerCountCompleted); -// modelErroredAmountPrevious += Number(model.triggerCountErrored); -// }); - -// return { -// completed: { -// statusType: "STATUS_COMPLETED", -// amount: modelCompleteAmount, -// type: "model", -// delta: calculatePercentageDelta( -// modelCompleteAmountPrevious, -// modelCompleteAmount, -// ), -// }, -// errored: { -// statusType: "STATUS_ERRORED", -// amount: modelErroredAmount, -// type: "model", -// delta: calculatePercentageDelta( -// modelErroredAmountPrevious, -// modelErroredAmount, -// ), -// }, -// }; -// } + return { + completed: { + statusType: "STATUS_COMPLETED" as const, + type: "model" as const, + amount: completedModel?.triggerCount || 0, + delta: 0 + }, + errored: { + statusType: "STATUS_ERRORED" as const, + type: "model" as const, + amount: erroredModel?.triggerCount || 0, + delta: 0 + } + }; +} \ No newline at end of file diff --git a/packages/toolkit/src/view/dashboard/activity/DashboardActivityPageMainView.tsx b/packages/toolkit/src/view/dashboard/activity/DashboardActivityPageMainView.tsx index e4d8f9584..f356ed03f 100755 --- a/packages/toolkit/src/view/dashboard/activity/DashboardActivityPageMainView.tsx +++ b/packages/toolkit/src/view/dashboard/activity/DashboardActivityPageMainView.tsx @@ -12,7 +12,7 @@ import { SelectOption } from "@instill-ai/design-system"; import { DashboardAvailableTimeframe, - // getModelTriggersSummary, + getModelTriggersSummary, getPipelineTriggersSummary, getPreviousTimeframe, getTimeInRFC3339Format, @@ -155,10 +155,10 @@ export const DashboardActivityPageMainView = () => { if ( triggeredPipelines.isError || pipelinesChart.isError || - previousTriggeredPipelines.isError - // triggeredModels.isError || - // modelsChart.isError || - // previousTriggeredModels.isError + previousTriggeredPipelines.isError || + triggeredModels.isError || + modelsChart.isError || + previousTriggeredModels.isError ) { router.push("/404"); } @@ -167,9 +167,9 @@ export const DashboardActivityPageMainView = () => { triggeredPipelines.isError, pipelinesChart.isError, previousTriggeredPipelines.isError, - // triggeredModels.isError, - // modelsChart.isError, - // previousTriggeredModels.isError, + triggeredModels.isError, + modelsChart.isError, + previousTriggeredModels.isError, ]); const pipelinesChartList = React.useMemo(() => { @@ -227,32 +227,12 @@ export const DashboardActivityPageMainView = () => { return null; } - const completedModel = modelsChart.data.modelTriggerCounts.find( - (r) => r.status === "STATUS_COMPLETED" - ); - - const erroredModel = modelsChart.data.modelTriggerCounts.find( - (r) => r.status === "STATUS_ERRORED" - ); - - return { - completed: { - statusType: "STATUS_COMPLETED" as const, - type: "model" as const, - amount: completedModel?.triggerCount || 0, - delta: 0 - }, - errored: { - statusType: "STATUS_ERRORED" as const, - type: "model" as const, - amount: erroredModel?.triggerCount || 0, - delta: 0 - } - }; + return getModelTriggersSummary(modelsChart.data.modelTriggerCounts); }, [ previousTriggeredModels.isSuccess, modelsChart.isSuccess, - modelsChart.data?.modelTriggerCounts + modelsChart.data?.modelTriggerCounts, + selectedTimeOption // Add this to ensure refetch on date change ]); return (