Skip to content

Commit

Permalink
[Nu-7330] Initial refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Rudnicki committed Dec 13, 2024
1 parent 5c6cbb9 commit 0778c73
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CountsRangesButtons } from "./CountsRangesButtons";
import { useDeployHistory } from "./useDeployHistory";
import { predefinedRanges } from "./utils";
import { StyledRangesWrapper } from "./CountsStyled";
import { useActivityHistory } from "./useActivityHistory";

interface RangesProps {
label: string;
Expand All @@ -16,6 +17,7 @@ interface RangesProps {
export function CountsRanges({ label, onChange }: RangesProps): JSX.Element {
const { t } = useTranslation<string>();
const processName = useSelector(getProcessName);
const activities = useActivityHistory(processName);
const deploys = useDeployHistory(processName);
const dates = useMemo(() => predefinedRanges(t), [t]);

Expand All @@ -24,7 +26,7 @@ export function CountsRanges({ label, onChange }: RangesProps): JSX.Element {
<p>{label}</p>
<StyledRangesWrapper>
<CountsRangesButtons ranges={dates} onChange={onChange} />
<CountsRangesButtons ranges={deploys} onChange={onChange} limit={1}>
<CountsRangesButtons ranges={activities} onChange={onChange} limit={1}>
{t("calculateCounts.deployments", "Previous deployments...")}
</CountsRangesButtons>
</StyledRangesWrapper>
Expand Down
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;
}
7 changes: 7 additions & 0 deletions designer/client/src/components/toolbars/activities/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export type ActivityType =
| "AUTOMATIC_UPDATE"
| "CUSTOM_ACTION";

export enum PredefinedActivityType {
ScenarioDeployed = "SCENARIO_DEPLOYED",
ScenarioCanceled = "SCENARIO_CANCELED",
PerformedSingleExecution = "PERFORMED_SINGLE_EXECUTION",
PerformedScheduledExecution = "PERFORMED_SCHEDULED_EXECUTION",
}

export interface ActivityMetadata {
type: ActivityType;
displayableName: string;
Expand Down
24 changes: 23 additions & 1 deletion designer/client/src/http/HttpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import {
Scenario,
StatusDefinitionType,
} from "../components/Process/types";
import { ActivitiesResponse, ActivityMetadataResponse } from "../components/toolbars/activities/types";
import {
ActivitiesResponse,
ActivityMetadataResponse,
ActivityType,
PredefinedActivityType,
} from "../components/toolbars/activities/types";
import { ToolbarsConfig } from "../components/toolbarSettings/types";
import { EventTrackingSelectorType, EventTrackingType } from "../containers/event-tracking";
import { BackendNotification } from "../containers/Notifications";
Expand Down Expand Up @@ -321,6 +326,23 @@ class HttpService {
return promise;
}

fetchProcessesActivities(processName: string) {
return api
.get<{ activities: { date: string; type: ActivityType }[] }>(
`/processes/${encodeURIComponent(processName)}/activity/activities`,
)
.then((res) => {
return res.data.activities.filter(
({ date, type }) =>
type === PredefinedActivityType.ScenarioDeployed ||
type === PredefinedActivityType.ScenarioCanceled ||
type === PredefinedActivityType.PerformedSingleExecution ||
type === PredefinedActivityType.PerformedScheduledExecution,
);
})
.then((res) => res.reverse());
}

fetchProcessesDeployments(processName: string) {
return api
.get<
Expand Down

0 comments on commit 0778c73

Please sign in to comment.