Skip to content

Commit

Permalink
separate modal
Browse files Browse the repository at this point in the history
  • Loading branch information
gskrobisz committed Jan 9, 2025
1 parent 36f60aa commit d74804b
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 55 deletions.
55 changes: 3 additions & 52 deletions designer/client/src/components/modals/DeployProcessDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,26 @@ 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 { getActivityParameters, getProcessName } from "../../reducers/selectors/graph";
import { getProcessName } from "../../reducers/selectors/graph";
import { getFeatureSettings } from "../../reducers/selectors/settings";
import { ProcessName } from "../Process/types";
import { PromptContent, WindowKind } from "../../windowManager";
import CommentInput from "../comment/CommentInput";
import ProcessDialogWarnings from "./ProcessDialogWarnings";
import { FormHelperText, Typography } from "@mui/material";
import { LoadingButtonTypes } from "../../windowManager/LoadingButton";
import { ActivityNodeParameters } from "../../types/activity";
import { AdvancedParametersSection } from "./AdvancedParametersSection";
import { mapValues } from "lodash";
import { NodesDeploymentData } from "../../http/HttpService";
import { ActivityProperty } from "./ActivityProperty";
import { NodeTable } from "../graph/node-modal/NodeDetailsContent/NodeTable";

export type ToggleProcessActionModalData = {
action: (processName: ProcessName, comment: string, nodeData: NodesDeploymentData) => Promise<unknown>;
action: (processName: ProcessName, comment: string) => Promise<unknown>;
displayWarnings?: boolean;
};

function initialNodesData(params: ActivityNodeParameters[]) {
return params.reduce(
(paramObj, { nodeId, parameters }) => ({
...paramObj,
[nodeId]: mapValues(parameters, (value) => value.defaultValue || ""),
}),
{},
);
}

export function DeployProcessDialog(props: WindowContentProps<WindowKind, ToggleProcessActionModalData>): JSX.Element {
// TODO: get rid of meta
const {
meta: { action, displayWarnings },
} = props.data;
const processName = useSelector(getProcessName);

const activityParameters = useSelector(getActivityParameters);
const activityNodeParameters = activityParameters["DEPLOY"] || ([] as ActivityNodeParameters[]);
const initialValues = useMemo(() => initialNodesData(activityNodeParameters), [activityNodeParameters]);
const [values, setValues] = useState(initialValues);

const [comment, setComment] = useState("");
const [validationError, setValidationError] = useState("");
const featureSettings = useSelector(getFeatureSettings);
Expand All @@ -54,7 +32,7 @@ export function DeployProcessDialog(props: WindowContentProps<WindowKind, Toggle

const confirmAction = useCallback(async () => {
try {
await action(processName, comment, values);
await action(processName, comment);
props.close();
} catch (error) {
setValidationError(error?.response?.data);
Expand Down Expand Up @@ -90,33 +68,6 @@ export function DeployProcessDialog(props: WindowContentProps<WindowKind, Toggle
<FormHelperText title={validationError} error>
{validationError}
</FormHelperText>
{activityNodeParameters.map((anp: ActivityNodeParameters) => (
<AdvancedParametersSection key={anp.nodeId} nodeId={anp.nodeId}>
<NodeTable>
{Object.entries(anp.parameters).map(([paramName, paramConfig]) => {
return (
<ActivityProperty
key={paramName}
nodeName={anp.nodeId}
propertyName={paramName}
propertyConfig={paramConfig}
errors={[]}
onChange={(nodeId, paramName, newValue) => {
setValues({
...values,
[nodeId]: {
...values[nodeId],
[paramName]: newValue,
},
});
}}
nodesData={values}
/>
);
})}
</NodeTable>
</AdvancedParametersSection>
))}
</div>
</PromptContent>
);
Expand Down
125 changes: 125 additions & 0 deletions designer/client/src/components/modals/DeployWithParametersDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { css, cx } from "@emotion/css";
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 { getActivityParameters, getProcessName } from "../../reducers/selectors/graph";
import { getFeatureSettings } from "../../reducers/selectors/settings";
import { ProcessName } from "../Process/types";
import { PromptContent, WindowKind } from "../../windowManager";
import CommentInput from "../comment/CommentInput";
import ProcessDialogWarnings from "./ProcessDialogWarnings";
import { FormHelperText, Typography } from "@mui/material";
import { LoadingButtonTypes } from "../../windowManager/LoadingButton";
import { ActivityNodeParameters } from "../../types/activity";
import { AdvancedParametersSection } from "./AdvancedParametersSection";
import { mapValues } from "lodash";
import { NodesDeploymentData } from "../../http/HttpService";
import { ActivityProperty } from "./ActivityProperty";
import { NodeTable } from "../graph/node-modal/NodeDetailsContent/NodeTable";

export type ToggleProcessActionModalData = {
action: (processName: ProcessName, comment: string, nodeData: NodesDeploymentData) => Promise<unknown>;
displayWarnings?: boolean;
};

function initialNodesData(params: ActivityNodeParameters[]) {
return params.reduce(
(paramObj, { nodeId, parameters }) => ({
...paramObj,
[nodeId]: mapValues(parameters, (value) => value.defaultValue || ""),
}),
{},
);
}

export function DeployWithParametersDialog(props: WindowContentProps<WindowKind, ToggleProcessActionModalData>): JSX.Element {
// TODO: get rid of meta
const {
meta: { action, displayWarnings },
} = props.data;
const processName = useSelector(getProcessName);

const activityParameters = useSelector(getActivityParameters);
const activityNodeParameters = activityParameters["DEPLOY"] || ([] as ActivityNodeParameters[]);
const initialValues = useMemo(() => initialNodesData(activityNodeParameters), [activityNodeParameters]);
const [values, setValues] = useState(initialValues);

const [comment, setComment] = useState("");
const [validationError, setValidationError] = useState("");
const featureSettings = useSelector(getFeatureSettings);
const deploymentCommentSettings = featureSettings.deploymentCommentSettings;

const dispatch = useDispatch();

const confirmAction = useCallback(async () => {
try {
await action(processName, comment, values);
props.close();
} catch (error) {
setValidationError(error?.response?.data);
}
}, [action, comment, dispatch, processName, props]);

const { t } = useTranslation();
const buttons: WindowButtonProps[] = useMemo(
() => [
{ title: t("dialog.button.cancel", "Cancel"), action: () => props.close(), classname: LoadingButtonTypes.secondaryButton },
{ title: t("dialog.button.ok", "Ok"), action: () => confirmAction() },
],
[confirmAction, props, t],
);

return (
<PromptContent {...props} buttons={buttons}>
<div className={cx("modalContentDark")}>
<Typography variant={"h3"}>{props.data.title}</Typography>
{displayWarnings && <ProcessDialogWarnings />}
<CommentInput
onChange={(e) => setComment(e.target.value)}
value={comment}
defaultValue={deploymentCommentSettings?.exampleComment}
className={cx(
css({
minWidth: 600,
minHeight: 80,
}),
)}
autoFocus
/>
<FormHelperText title={validationError} error>
{validationError}
</FormHelperText>
{activityNodeParameters.map((anp: ActivityNodeParameters) => (
<AdvancedParametersSection key={anp.nodeId} nodeId={anp.nodeId}>
<NodeTable>
{Object.entries(anp.parameters).map(([paramName, paramConfig]) => {
return (
<ActivityProperty
key={paramName}
nodeName={anp.nodeId}
propertyName={paramName}
propertyConfig={paramConfig}
errors={[]}
onChange={(nodeId, paramName, newValue) => {
setValues({
...values,
[nodeId]: {
...values[nodeId],
[paramName]: newValue,
},
});
}}
nodesData={values}
/>
);
})}
</NodeTable>
</AdvancedParametersSection>
))}
</div>
</PromptContent>
);
}

export default DeployWithParametersDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getProcessName, getProcessVersionId, hasError, isDeployPossible, isSave
import { getCapabilities } from "../../../../reducers/selectors/other";
import { useWindows } from "../../../../windowManager";
import { WindowKind } from "../../../../windowManager";
import { ToggleProcessActionModalData } from "../../../modals/DeployProcessDialog";
import { ToggleProcessActionModalData } from "../../../modals/DeployWithParametersDialog";
import { ToolbarButton } from "../../../toolbarComponents/toolbarButtons";
import { ToolbarButtonProps } from "../../types";
import { ACTION_DIALOG_WIDTH } from "../../../../stylesheets/variables";
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function DeployButton(props: ToolbarButtonProps) {
onClick={() =>
open<ToggleProcessActionModalData>({
title: message,
kind: WindowKind.deployProcess,
kind: WindowKind.deployWithParameters,
width: ACTION_DIALOG_WIDTH,
meta: { action, displayWarnings: true },
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "../../../../reducers/selectors/graph";
import { getCapabilities } from "../../../../reducers/selectors/other";
import { useWindows, WindowKind } from "../../../../windowManager";
import { ToggleProcessActionModalData } from "../../../modals/DeployProcessDialog";
import { ToggleProcessActionModalData } from "../../../modals/DeployWithParametersDialog";
import { ToolbarButton } from "../../../toolbarComponents/toolbarButtons";
import { ToolbarButtonProps } from "../../types";
import { ACTION_DIALOG_WIDTH } from "../../../../stylesheets/variables";
Expand Down
5 changes: 5 additions & 0 deletions designer/client/src/windowManager/ContentGetter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const AdhocTestingDialog = loadable(() => import("../components/modals/AdhocTest
const DeployProcessDialog = loadable(() => import("../components/modals/DeployProcessDialog"), {
fallback: <LoaderSpinner show />,
});
const DeployWithParametersDialog = loadable(() => import("../components/modals/DeployWithParametersDialog"), {
fallback: <LoaderSpinner show />,
});
const GenericConfirmDialog = loadable(() => import("../components/modals/GenericConfirmDialog"), {
fallback: <LoaderSpinner show />,
});
Expand Down Expand Up @@ -69,6 +72,8 @@ const contentGetter: React.FC<WindowContentProps<WindowKind>> = (props) => {
return <SaveProcessDialog {...props} />;
case WindowKind.deployProcess:
return <DeployProcessDialog {...props} />;
case WindowKind.deployWithParameters:
return <DeployWithParametersDialog {...props} />;
case WindowKind.calculateCounts:
return <CountsDialog {...props} />;
case WindowKind.generateTestData:
Expand Down
1 change: 1 addition & 0 deletions designer/client/src/windowManager/WindowKind.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum WindowKind {
addFragment,
saveProcess,
deployProcess,
deployWithParameters,
calculateCounts,
generateTestData,
generateDataAndTest,
Expand Down

0 comments on commit d74804b

Please sign in to comment.