Skip to content

Commit

Permalink
fe getActivityParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
gskrobisz committed Sep 25, 2024
1 parent 758b5d2 commit e0b7858
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions designer/client/src/actions/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type ActionTypes =
| "PROCESS_RENAME"
| "EDIT_LABELS"
| "SHOW_METRICS"
| "UPDATE_ACTIVITY_PARAMETERS"
| "UPDATE_TEST_CAPABILITIES"
| "UPDATE_TEST_FORM_PARAMETERS"
| "DISPLAY_PROCESS"
Expand Down
10 changes: 10 additions & 0 deletions designer/client/src/actions/nk/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export function loadProcessState(processName: ProcessName): ThunkAction {
);
}

export function fetchActivityFormParameters(processName: ProcessName, scenarioGraph: ScenarioGraph) {
return (dispatch) =>
HttpService.getActivityParameters(processName, scenarioGraph).then(({ data }) => {
dispatch({
type: "UPDATE_ACTIVITY_PARAMETERS",
activityParameters: data,
});
});
}

export function fetchTestFormParameters(processName: ProcessName, scenarioGraph: ScenarioGraph) {
return (dispatch) =>
HttpService.getTestFormParameters(processName, scenarioGraph).then(({ data }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WindowButtonProps, WindowContentProps } from "@touk/window-manager";
import React, { useCallback, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import { getProcessName } from "../../reducers/selectors/graph";
import { getActivityParameters, getProcessName } from "../../reducers/selectors/graph";
import { getFeatureSettings } from "../../reducers/selectors/settings";
import { ProcessName } from "../Process/types";
import { PromptContent, WindowKind } from "../../windowManager";
Expand All @@ -23,6 +23,11 @@ export function DeployProcessDialog(props: WindowContentProps<WindowKind, Toggle
meta: { action, displayWarnings },
} = props.data;
const processName = useSelector(getProcessName);

const activityParameters = useSelector(getActivityParameters);
const activityNodeParameters = activityParameters["DEPLOY"] || [];
console.log(activityNodeParameters);

const [comment, setComment] = useState("");
const [validationError, setValidationError] = useState("");
const featureSettings = useSelector(getFeatureSettings);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useDispatch, useSelector } from "react-redux";
import { getProcessName, getScenarioGraph, isProcessRenamed } from "../../../reducers/selectors/graph";
import { useEffect } from "react";
import { fetchActivityFormParameters } from "../../../actions/nk";

export function useActivityCapabilities() {
const dispatch = useDispatch();

const isRenamed = useSelector(isProcessRenamed);
const scenarioName = useSelector(getProcessName);
const scenarioGraph = useSelector(getScenarioGraph);

useEffect(() => {
if (isRenamed) return;
dispatch(fetchActivityFormParameters(scenarioName, scenarioGraph));
}, [dispatch, isRenamed, scenarioName, scenarioGraph]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { ToolbarButton } from "../../../toolbarComponents/toolbarButtons";
import { ToolbarButtonProps } from "../../types";
import { ACTION_DIALOG_WIDTH } from "../../../../stylesheets/variables";

import { useActivityCapabilities } from "../../../modals/GenericAction/useActivityCapabilities";

export default function DeployButton(props: ToolbarButtonProps) {
const dispatch = useDispatch();
const deployPossible = useSelector(isDeployPossible);
Expand All @@ -22,6 +24,9 @@ export default function DeployButton(props: ToolbarButtonProps) {
const capabilities = useSelector(getCapabilities);
const { disabled, type } = props;

// TODO: find better place to reload activity capabilities and properties
useActivityCapabilities();

const available = !disabled && deployPossible && capabilities.deploy;

const { t } = useTranslation();
Expand Down
15 changes: 15 additions & 0 deletions designer/client/src/http/HttpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,21 @@ class HttpService {
return promise;
}

getActivityParameters(processName: string, scenarioGraph: ScenarioGraph) {
const promise = api.post(
`/activityInfo/${encodeURIComponent(processName)}/activityParameters`,
this.#sanitizeScenarioGraph(scenarioGraph),
);
promise.catch((error) =>
this.#addError(
i18next.t("notification.error.failedToGetTestParameters", "Failed to get activity parameters definition"),
error,
true,
),
);
return promise;
}

generateTestData(processName: string, testSampleSize: string, scenarioGraph: ScenarioGraph): Promise<AxiosResponse> {
const promise = api.post(
`/testInfo/${encodeURIComponent(processName)}/generate/${testSampleSize}`,
Expand Down
6 changes: 6 additions & 0 deletions designer/client/src/reducers/graph/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ const graphReducer: Reducer<GraphState> = (state = emptyGraphState, action) => {
testFormParameters: action.testFormParameters,
};
}
case "UPDATE_ACTIVITY_PARAMETERS": {
return {
...state,
activityParameters: action.activityParameters,
};
}
case "DISPLAY_PROCESS": {
const { scenario } = action;
return {
Expand Down
2 changes: 2 additions & 0 deletions designer/client/src/reducers/graph/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Layout, RefreshData } from "../../actions/nk";
import { Scenario } from "../../components/Process/types";
import { TestCapabilities, TestFormParameters, TestResults } from "../../common/TestResultUtils";
import { ActivityParameters } from "../../types/activity";

export interface NodeCounts {
errors?: number;
Expand All @@ -15,6 +16,7 @@ export type GraphState = {
scenario?: Scenario;
selectionState?: string[];
layout: Layout;
activityParameters?: ActivityParameters;
testCapabilities?: TestCapabilities;
testFormParameters?: TestFormParameters[];
testResults: TestResults;
Expand Down
2 changes: 2 additions & 0 deletions designer/client/src/reducers/selectors/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ProcessCounts } from "../graph";
import { RootState } from "../index";
import { getProcessState } from "./scenarioState";
import { TestFormParameters } from "../../common/TestResultUtils";
import { ActivityParameters } from "../../types/activity";

export const getGraph = (state: RootState) => state.graphReducer.history.present;

Expand Down Expand Up @@ -65,6 +66,7 @@ export const isArchivePossible = createSelector(
[getProcessState, isFragment],
(state, isFragment) => isFragment || ProcessStateUtils.canArchive(state),
);
export const getActivityParameters = createSelector(getGraph, (g) => g.activityParameters || ({} as ActivityParameters));
export const getTestCapabilities = createSelector(getGraph, (g) => g.testCapabilities);
export const getTestParameters = createSelector(getGraph, (g) => g.testFormParameters || ([] as TestFormParameters[]));
export const getTestResults = createSelector(getGraph, (g) => g.testResults);
Expand Down
17 changes: 17 additions & 0 deletions designer/client/src/types/activity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NodeId } from "./node";

export interface ActivityParameterConfig {
editor: any;
label: string;
defaultValue: string | null;
hintText: string | null;
}

export interface ActivityNodeParameters {
nodeId: NodeId;
parameters: Record<string, ActivityParameterConfig>;
}

export type ActivityName = string;

export type ActivityParameters = Record<ActivityName, ActivityNodeParameters[]>;

0 comments on commit e0b7858

Please sign in to comment.