-
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.
- Loading branch information
Piotr Rudnicki
committed
Dec 13, 2024
1 parent
5c6cbb9
commit 0778c73
Showing
4 changed files
with
69 additions
and
2 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
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
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"; | ||
|
||
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); | ||
console.log(activities); | ||
const to = all[i - 1]?.date; | ||
return { | ||
from: () => from, | ||
to: () => (to ? moment(to) : moment().add(1, "day").startOf("day")), | ||
name: i | ||
? t("calculateCounts.range.prevAction", "Previous {{activity}} #{{i}} {{date}}", { | ||
activity: current.type, | ||
i: all.length - i, | ||
date: from.format(DATE_FORMAT), | ||
}) | ||
: t("calculateCounts.range.lastDeploy", "Latest deploy"), | ||
}; | ||
}), | ||
) | ||
.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