Skip to content

Commit

Permalink
refactor again
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Rudnicki committed Dec 19, 2024
1 parent 2445a8d commit 94c0752
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Moment } from "moment";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
import { getProcessCategory, getProcessingType, getProcessName } from "../../../reducers/selectors/graph";
import { getProcessingType, getProcessName } from "../../../reducers/selectors/graph";
import { CountsRangesButtons } from "./CountsRangesButtons";
import { predefinedRanges } from "./utils";
import { StyledRangesWrapper } from "./CountsStyled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import HttpService from "../../../http/HttpService";
import { DATE_FORMAT } from "../../../config";
import { Range } from "./CountsRangesButtons";
import moment from "moment";
import { PredefinedActivityType } from "../../toolbars/activities/types";
import { ActivityTypesRelatedToExecutions } from "../../toolbars/activities/types";

function displayableNameOfPredefinedActivityType(predefinedActivityType: PredefinedActivityType) {
function displayableNameOfPredefinedActivityType(predefinedActivityType: ActivityTypesRelatedToExecutions) {
switch (predefinedActivityType) {
case PredefinedActivityType.ScenarioCanceled:
case ActivityTypesRelatedToExecutions.ScenarioCanceled:
return "Cancel";
case PredefinedActivityType.ScenarioDeployed:
case ActivityTypesRelatedToExecutions.ScenarioDeployed:
return "Deployment";
case PredefinedActivityType.PerformedScheduledExecution:
case ActivityTypesRelatedToExecutions.PerformedScheduledExecution:
return "Scheduled deployment";
case PredefinedActivityType.PerformedSingleExecution:
case ActivityTypesRelatedToExecutions.PerformedSingleExecution:
return "Run now";
default:
return "Unknown activity type";
Expand All @@ -26,17 +26,17 @@ export function useActivityHistory(processName: string, processingMode: string):
const [activities, setActivities] = useState<Range[]>([]);

useEffect(() => {
HttpService.fetchProcessesActivities(processName)
HttpService.fetchActivitiesRelatedToExecutions(processName)
.then((activities) =>
processingMode.includes("batch")
? activities.filter((activity) => activity.type !== PredefinedActivityType.ScenarioDeployed)
? activities.filter((activity) => activity.type !== ActivityTypesRelatedToExecutions.ScenarioDeployed)
: activities,
)
.then((activities) =>
activities.map((current, i, all) => {
const from = moment(current.date);
const to = all[i - 1]?.date;
const isOmitted = current.type === PredefinedActivityType.ScenarioCanceled;
const isOmitted = current.type === ActivityTypesRelatedToExecutions.ScenarioCanceled;
return {
from: () => from,
to: () => (to ? moment(to) : moment().add(1, "day").startOf("day")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ActivityType =
| "AUTOMATIC_UPDATE"
| "CUSTOM_ACTION";

export enum PredefinedActivityType {
export enum ActivityTypesRelatedToExecutions {
ScenarioDeployed = "SCENARIO_DEPLOYED",
ScenarioCanceled = "SCENARIO_CANCELED",
PerformedSingleExecution = "PERFORMED_SINGLE_EXECUTION",
Expand Down
14 changes: 5 additions & 9 deletions designer/client/src/http/HttpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
ActivitiesResponse,
ActivityMetadataResponse,
ActivityType,
PredefinedActivityType,
ActivityTypesRelatedToExecutions,
} from "../components/toolbars/activities/types";
import { ToolbarsConfig } from "../components/toolbarSettings/types";
import { EventTrackingSelectorType, EventTrackingType } from "../containers/event-tracking";
Expand Down Expand Up @@ -326,21 +326,17 @@ class HttpService {
return promise;
}

fetchProcessesActivities(processName: string) {
fetchActivitiesRelatedToExecutions(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,
return res.data.activities.filter(({ date, type }) =>
Object.values(ActivityTypesRelatedToExecutions).includes(type as ActivityTypesRelatedToExecutions),
);
})
.then((res) => res.reverse().map((item) => ({ ...item, type: item.type as PredefinedActivityType })));
.then((res) => res.reverse().map((item) => ({ ...item, type: item.type as ActivityTypesRelatedToExecutions })));
}

fetchProcessesDeployments(processName: string) {
Expand Down

0 comments on commit 94c0752

Please sign in to comment.