Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace "run now" CustomAction with standard action PerformSingleExecution #7165

Open
wants to merge 7 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion designer/client/src/components/Process/ProcessStateUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PredefinedActionName, ProcessStateType, Scenario } from "./types";
import { ActionName, PredefinedActionName, ProcessStateType, Scenario, ActionTooltip } from "./types";
import {
descriptionProcessArchived,
descriptionFragment,
Expand All @@ -18,6 +18,12 @@ class ProcessStateUtils {

public canArchive = (state: ProcessStateType): boolean => state?.allowedActions.includes(PredefinedActionName.Archive);

public canSeePerformSingleExecution = (state: ProcessStateType): boolean =>
state?.visibleActions.includes(PredefinedActionName.PerformSingleExecution);

public canPerformSingleExecution = (state: ProcessStateType): boolean =>
state?.allowedActions.includes(PredefinedActionName.PerformSingleExecution);

getStateDescription({ isArchived, isFragment }: Scenario, processState: ProcessStateType): string {
if (isArchived) {
return isFragment ? descriptionFragmentArchived() : descriptionProcessArchived();
Expand Down Expand Up @@ -60,6 +66,10 @@ class ProcessStateUtils {
}
return `${name}-${processState?.icon || state?.icon || unknownIcon}`;
}

getActionCustomTooltip(processState: ProcessStateType, actionName: ActionName): ActionTooltip | undefined {
return processState?.actionTooltips[actionName] || undefined;
}
}

export default new ProcessStateUtils();
11 changes: 10 additions & 1 deletion designer/client/src/components/Process/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum PredefinedActionName {
Archive = "ARCHIVE",
UnArchive = "UNARCHIVE",
Pause = "PAUSE",
PerformSingleExecution = "PERFORM_SINGLE_EXECUTION",
}

export type ActionName = string;
Expand Down Expand Up @@ -66,17 +67,25 @@ export interface Scenario {

export type ProcessName = Scenario["name"];

export enum ActionTooltip {
NotAllowedForDeployedVersion = "NOT_ALLOWED_FOR_DEPLOYED_VERSION",
NotAllowedInCurrentState = "NOT_ALLOWED_IN_CURRENT_STATE",
}

export type ProcessStateType = {
status: StatusType;
latestVersionId: number;
deployedVersionId?: number;
externalDeploymentId?: string;
visibleActions: Array<ActionName>;
allowedActions: Array<ActionName>;
actionTooltips: Record<ActionName, ActionTooltip>;
icon: string;
tooltip: string;
description: string;
startTime?: Date;
attributes?: UnknownRecord;
errors?: Array<string>;
version?: number | null;
};

export type StatusType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@ export function ActionButton({ name, type }: ActionButtonProps): JSX.Element {
const customActions = useSelector(getCustomActions);
const action = useMemo(() => customActions.find((a) => a.name === name), [customActions, name]);

// FIXME: This part requires further changes within periodic scenario engine.
// Currently we use experimental api of custom actions for periodic scenarios (an experimental engine).
// Part of this experimental engine allows to run immediately scheduled scenario. This activity will be moved inside core deployment operations and aligned with other deployment engines.
// Here we want to disable that one action button in confusing situation when user looks at scenario version that is not currently deployed.
const isDeployed = useSelector(isDeployedVersion);
const disabledValue = useMemo(() => !isDeployed, [isDeployed, name]);

return action ? (
<CustomActionButton
action={action}
processName={processName}
processStatus={status}
disabled={name === "run now" ? disabledValue : false}
type={type}
/>
<CustomActionButton action={action} processName={processName} disabled={false} processStatus={status} type={type} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see, there is no option to disable a custom action based on FE types. Do we need this disabled flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is part of common ToolbarButtonProps, used for all buttons. AFAIK this value must be provided. I guess at the moment it is the only button, that is never disabled on FE side, so constant false provided here

After Arek's comments I added internationalization of tooltip messages, I think it needs FE review too.

arkadius marked this conversation as resolved.
Show resolved Hide resolved
) : null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum BuiltinButtonTypes {
processSave = "process-save",
processDeploy = "process-deploy",
processCancel = "process-cancel",
processPerformSingleExecution = "process-perform-single-execution",
editUndo = "edit-undo",
editRedo = "edit-redo",
editCopy = "edit-copy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ZoomOutButton } from "../../toolbars/view/buttons/ZoomOutButton";
import { BuiltinButtonTypes } from "./BuiltinButtonTypes";
import { CustomButtonTypes } from "./CustomButtonTypes";
import { ToolbarButton, ToolbarButtonTypes } from "./types";
import PerformSingleExecutionButton from "../../toolbars/scenarioActions/buttons/PerformSingleExecutionButton";

export type PropsOfButton<T> = ToolbarButton & {
type: T;
Expand All @@ -44,6 +45,7 @@ export const TOOLBAR_BUTTONS_MAP: ToolbarButtonsMap = {
[BuiltinButtonTypes.processSave]: SaveButton,
[BuiltinButtonTypes.processDeploy]: DeployButton,
[BuiltinButtonTypes.processCancel]: CancelDeployButton,
[BuiltinButtonTypes.processPerformSingleExecution]: PerformSingleExecutionButton,
[BuiltinButtonTypes.viewZoomIn]: ZoomInButton,
[BuiltinButtonTypes.viewZoomOut]: ZoomOutButton,
[BuiltinButtonTypes.viewReset]: ResetViewButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function defaultToolbarsConfig(isFragment: boolean, isArchived: boolean):
{ type: BuiltinButtonTypes.processSave },
{ type: BuiltinButtonTypes.processDeploy },
{ type: BuiltinButtonTypes.processCancel },
{ type: BuiltinButtonTypes.processPerformSingleExecution },
],
},
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const ActivitiesPanelRow = memo(({ index, style, setRowHeight, handleShow
() => activities.findIndex((activeItem) => activeItem.uiType === "item" && activeItem.type === "SCENARIO_DEPLOYED"),
[activities],
);
const isRunning = firstDeployedIndex === index && scenarioState.status.name === "RUNNING";
const isRunning =
firstDeployedIndex === index && (scenarioState.status.name === "RUNNING" || scenarioState.status.name === "SCHEDULED");
const isFirstDateItem = activities.findIndex((activeItem) => activeItem.uiType === "date") === index;

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import { loadProcessState } from "../../../../actions/nk";
import Icon from "../../../../assets/img/toolbarButtons/perform-single-execution.svg";
import HttpService from "../../../../http/HttpService";
import { getProcessName, isPerformSingleExecutionPossible, isPerformSingleExecutionVisible } from "../../../../reducers/selectors/graph";
import { getCapabilities } from "../../../../reducers/selectors/other";
import { useWindows, WindowKind } from "../../../../windowManager";
import { ToggleProcessActionModalData } from "../../../modals/DeployProcessDialog";
import { ToolbarButton } from "../../../toolbarComponents/toolbarButtons";
import { ToolbarButtonProps } from "../../types";
import { ACTION_DIALOG_WIDTH } from "../../../../stylesheets/variables";
import ProcessStateUtils from "../../../Process/ProcessStateUtils";
import { RootState } from "../../../../reducers";
import { getProcessState } from "../../../../reducers/selectors/scenarioState";
import { ActionTooltip, PredefinedActionName } from "../../../Process/types";

export default function PerformSingleExecutionButton(props: ToolbarButtonProps) {
const { t } = useTranslation();
const dispatch = useDispatch();
const { disabled, type } = props;
const scenarioState = useSelector((state: RootState) => getProcessState(state));
const isVisible = useSelector(isPerformSingleExecutionVisible);
const isPossible = useSelector(isPerformSingleExecutionPossible);
const processName = useSelector(getProcessName);
const capabilities = useSelector(getCapabilities);
const available = !disabled && isPossible && capabilities.deploy;

const { open } = useWindows();
const action = (p, c) => HttpService.performSingleExecution(p, c).finally(() => dispatch(loadProcessState(processName)));
const message = t("panels.actions.perform-single-execution.dialog", "Perform single execution", { name: processName });

const actionTooltip = ProcessStateUtils.getActionCustomTooltip(scenarioState, PredefinedActionName.PerformSingleExecution);

const tooltip =
actionTooltip === ActionTooltip.NotAllowedForDeployedVersion
? t(
"panels.actions.perform-single-execution.tooltip.not-allowed-for-deployed-version",
"There is new version {{ latestVersion }} available.{{ deployedVersionDescription }}",
{
latestVersion: scenarioState.latestVersionId,
deployedVersionDescription: scenarioState?.deployedVersionId
? ` (version ${scenarioState.deployedVersionId} is deployed)`
: ``,
},
)
: actionTooltip === ActionTooltip.NotAllowedInCurrentState
? t("panels.actions.perform-single-execution.tooltip.not-allowed-in-current-state", "Disabled for {{ status }} status.", {
status: scenarioState.status.name,
})
: "run now";

if (isVisible) {
return (
<ToolbarButton
name={t("panels.actions.perform-single-execution.button", "run now")}
title={tooltip}
disabled={!available}
icon={<Icon />}
onClick={() =>
open<ToggleProcessActionModalData>({
title: message,
kind: WindowKind.deployProcess,
width: ACTION_DIALOG_WIDTH,
meta: { action },
})
}
type={type}
/>
);
} else return <></>;
}
3 changes: 3 additions & 0 deletions designer/client/src/containers/event-tracking/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export const mapToolbarButtonToStatisticsEvent = (
case BuiltinButtonTypes.processCancel: {
return EventTrackingSelector.ScenarioCancel;
}
case BuiltinButtonTypes.processPerformSingleExecution: {
return EventTrackingSelector.ScenarioPerformSingleExecution;
}
case BuiltinButtonTypes.processArchiveToggle: {
return EventTrackingSelector.ScenarioArchiveToggle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum ClickEventsSelector {
ScenarioSave = "SCENARIO_SAVE",
TestCounts = "TEST_COUNTS",
ScenarioCancel = "SCENARIO_CANCEL",
ScenarioPerformSingleExecution = "SCENARIO_PERFORM_SINGLE_EXECUTION",
ScenarioArchiveToggle = "SCENARIO_ARCHIVE_TOGGLE",
ScenarioUnarchive = "SCENARIO_UNARCHIVE",
ScenarioCustomAction = "SCENARIO_CUSTOM_ACTION",
Expand Down
25 changes: 25 additions & 0 deletions designer/client/src/http/HttpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,31 @@ class HttpService {
});
}

performSingleExecution(processName: string, comment?: string) {
const data = {
comment: comment,
};
return api
.post(`/processManagement/performSingleExecution/${encodeURIComponent(processName)}`, data)
.then((res) => {
const msg = res.data.msg;
this.#addInfo(msg);
return {
isSuccess: res.data.isSuccess,
msg: msg,
};
})
.catch((error) => {
const msg = error.response.data.msg || error.response.data;
const result = {
isSuccess: false,
msg: msg,
};
if (error?.response?.status != 400) return this.#addError(msg, error, false).then(() => result);
return result;
});
}
mgoworko marked this conversation as resolved.
Show resolved Hide resolved

customAction(processName: string, actionName: string, params: Record<string, unknown>, comment?: string) {
const data = {
actionName: actionName,
Expand Down
5 changes: 4 additions & 1 deletion designer/client/src/reducers/graph/utils.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ export const state: GraphState = {
status: {
name: "NOT_DEPLOYED",
},
version: null,
latestVersionId: 1,
deployedVersionId: 1,
visibleActions: ["DEPLOY", "ARCHIVE", "RENAME"],
allowedActions: ["DEPLOY", "ARCHIVE", "RENAME"],
actionTooltips: {},
icon: "/assets/states/not-deployed.svg",
tooltip: "The scenario is not deployed.",
description: "The scenario is not deployed.",
Expand Down
9 changes: 8 additions & 1 deletion designer/client/src/reducers/selectors/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ export const isDeployedVersion = createSelector(
[getProcessVersionId, createSelector(getScenario, (scenario) => scenario?.lastDeployedAction?.processVersionId)],
(visibleVersion, deployedVersion) => visibleVersion === deployedVersion,
);
export const isCancelPossible = createSelector(getProcessState, (state) => ProcessStateUtils.canCancel(state));
export const isPerformSingleExecutionVisible = createSelector([getProcessState], (state) =>
ProcessStateUtils.canSeePerformSingleExecution(state),
);
export const isPerformSingleExecutionPossible = createSelector(
[isSaveDisabled, hasError, getProcessState, isFragment],
(saveDisabled, error, state, fragment) => !fragment && saveDisabled && !error && ProcessStateUtils.canPerformSingleExecution(state),
);
export const isMigrationPossible = createSelector(
[isSaveDisabled, hasError, getProcessState, isFragment],
(saveDisabled, error, state, fragment) => saveDisabled && !error && (fragment || ProcessStateUtils.canDeploy(state)),
);
export const isCancelPossible = createSelector(getProcessState, (state) => ProcessStateUtils.canCancel(state));
export const isArchivePossible = createSelector(
[getProcessState, isFragment],
(state, isFragment) => isFragment || ProcessStateUtils.canArchive(state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import pl.touk.nussknacker.engine.api.ProcessVersion
import pl.touk.nussknacker.engine.api.process.ProcessName
import pl.touk.nussknacker.engine.api.test.ScenarioTestData
import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess
import pl.touk.nussknacker.engine.deployment.{
CustomActionResult,
DeploymentData,
DeploymentId,
ExternalDeploymentId,
User
}
import pl.touk.nussknacker.engine.deployment._
import pl.touk.nussknacker.engine.testmode.TestProcess.TestResults

// DM Prefix is from Deployment Manager, to distinguish from commands passed into the domain service layer (DeploymentService)
Expand Down Expand Up @@ -86,3 +80,9 @@ case class DMCancelScenarioCommand(scenarioName: ProcessName, user: User) extend

case class DMStopScenarioCommand(scenarioName: ProcessName, savepointDir: Option[String], user: User)
extends DMScenarioCommand[SavepointResult]

case class DMPerformSingleExecutionCommand(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What about custom actions? Can you write in the description the plan of changes that will be made in further PRs?
  2. Let's write a TODO describing further plan that won't be a part of currently planned changes. Do you agree that eventually we should extract some kind of a scheduler interface and in the deployment manager keep only logic related with the deployment? Or maybe you see it differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added in this PR description the general plan for periodics, especially the change that is already in progress.

I'm not sure ATM about the future of CustomAction's. We aren't using them internally anymore - "run now" was our only usage. They are left in the codebased and APIs right now, so Nu users can still use them.

I guess we need to decide, whether to leave CustomAction's as they are, or remove them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove custom actions. It was done only for this one thing. It complicates deployments mechanism and slow down development. Let's add a removal step to the plan

processVersion: ProcessVersion,
canonicalProcess: CanonicalProcess,
user: User,
) extends DMScenarioCommand[SingleExecutionResult]
Loading