-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Nu-7330] Use activities endpoint to compute ranges in counts window
- Loading branch information
Piotr Rudnicki
committed
Dec 17, 2024
1 parent
5069ac1
commit 47965a8
Showing
5 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
designer/client/src/components/modals/CalculateCounts/useActivityHistory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import HttpService from "../../../http/HttpService"; | ||
import { DATE_FORMAT } from "../../../config"; | ||
import { Range } from "./CountsRangesButtons"; | ||
import moment from "moment"; | ||
import { PredefinedActivityType } from "../../toolbars/activities/types"; | ||
|
||
function displayableNameOfPredefinedActivityType(predefinedActivityType: PredefinedActivityType) { | ||
switch (predefinedActivityType) { | ||
case PredefinedActivityType.ScenarioCanceled: | ||
return "Cancel"; | ||
case PredefinedActivityType.ScenarioDeployed: | ||
return "Deployment"; | ||
case PredefinedActivityType.PerformedScheduledExecution: | ||
return "Scheduled deployment"; | ||
case PredefinedActivityType.PerformedSingleExecution: | ||
return "Run now"; | ||
default: | ||
return "Unknown activity type"; | ||
} | ||
} | ||
|
||
export function useActivityHistory(processName: string): Range[] { | ||
const { t } = useTranslation(); | ||
const [activities, setActivities] = useState<Range[]>([]); | ||
|
||
useEffect(() => { | ||
HttpService.fetchProcessesActivities(processName) | ||
.then((activities) => | ||
activities.map((current, i, all) => { | ||
const from = moment(current.date); | ||
const to = all[i - 1]?.date; | ||
const isOmitted = current.type === PredefinedActivityType.ScenarioCanceled; | ||
return { | ||
from: () => from, | ||
to: () => (to ? moment(to) : moment().add(1, "day").startOf("day")), | ||
name: i | ||
? t("calculateCounts.range.prevAction", "Previous {{activity}} #{{i}} {{date}}", { | ||
activity: displayableNameOfPredefinedActivityType(current.type), | ||
i: all.length - i, | ||
date: from.format(DATE_FORMAT), | ||
}) | ||
: t("calculateCounts.range.lastDeploy", "Latest deploy"), | ||
isOmitted, | ||
}; | ||
}), | ||
) | ||
.then((res) => res.filter((activity) => !activity.isOmitted)) | ||
.then(setActivities); | ||
}, [t, processName]); | ||
|
||
return activities; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters