Skip to content
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
6 changes: 3 additions & 3 deletions src/ui/src/builder/settings/useBuilderSettingsActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("useBuilderSettingsActions", () => {
wfbm,
);

expect(dropdownOptions.value).toHaveLength(8);
expect(dropdownOptions.value).toHaveLength(9);

for (const option of dropdownOptions.value) {
expect(option.disabled).toBe(true);
Expand All @@ -52,7 +52,7 @@ describe("useBuilderSettingsActions", () => {
wfbm,
);

expect(dropdownOptions.value).toHaveLength(8);
expect(dropdownOptions.value).toHaveLength(9);

expect(
dropdownOptions.value.find(
Expand Down Expand Up @@ -89,7 +89,7 @@ describe("useBuilderSettingsActions", () => {
wfbm,
);

expect(dropdownOptions.value).toHaveLength(8);
expect(dropdownOptions.value).toHaveLength(9);

expect(
dropdownOptions.value.find(
Expand Down
39 changes: 39 additions & 0 deletions src/ui/src/builder/settings/useBuilderSettingsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Option } from "@/components/shared/SharedMoreDropdown.vue";

export enum BuilderSettingsDropdownActions {
Add = "add",
Run = "run",
MoveUp = "moveUp",
MoveDown = "moveDown",
Cut = "cut",
Expand Down Expand Up @@ -42,9 +43,13 @@ export function useBuilderSettingsActions(
moveComponentUp,
moveComponentDown,
cutComponent,
runBlueprintFromComponent,
stopBlueprintFromComponent,
isBlueprintRunning,
pasteComponent,
copyComponent,
isAddAllowed,
isRunAllowed,
isCopyAllowed,
isCutAllowed,
isGoToParentAllowed,
Expand Down Expand Up @@ -77,6 +82,7 @@ export function useBuilderSettingsActions(
isAddEnabled: isAddAllowed(componentId.value),
componentTypeName: wf.getComponentDefinition(component.type)?.name,
toolkit: wf.getComponentDefinition(component.type)?.toolkit,
isRunEnabled: isRunAllowed(componentId.value),
isMoveUpEnabled,
isMoveDownEnabled,
isCopyEnabled: isCopyAllowed(componentId.value),
Expand All @@ -99,6 +105,22 @@ export function useBuilderSettingsActions(
}
}

async function handleRunBlueprint() {
try {
await runBlueprintFromComponent(componentId.value);
} catch (error) {
toasts.pushToast({ type: "error", message: String(error) });
}
}

async function handleStopBlueprint() {
try {
await stopBlueprintFromComponent(componentId.value);
} catch (error) {
toasts.pushToast({ type: "error", message: String(error) });
}
}

function deleteComponent() {
if (!shortcutsInfo.value.isDeleteEnabled) return;
if (targetComponent) {
Expand All @@ -118,6 +140,16 @@ export function useBuilderSettingsActions(
icon: "plus",
disabled: !shortcutsInfo.value.isAddEnabled,
},
{
value: BuilderSettingsDropdownActions.Run,
label: isBlueprintRunning(componentId.value)
? "Stop run"
: "Run from here",
icon: isBlueprintRunning(componentId.value) ? "square" : "play",
disabled: isBlueprintRunning(componentId.value)
? false
: !shortcutsInfo.value.isRunEnabled,
},
{
value: BuilderSettingsDropdownActions.MoveUp,
label: `Move up`,
Expand Down Expand Up @@ -178,6 +210,13 @@ export function useBuilderSettingsActions(
case BuilderSettingsDropdownActions.Add:
// Handled by callback
break;
case BuilderSettingsDropdownActions.Run:
if (isBlueprintRunning(componentId.value)) {
handleStopBlueprint();
} else {
handleRunBlueprint();
}
break;
case BuilderSettingsDropdownActions.MoveUp:
moveComponentUp(componentId.value);
break;
Expand Down
40 changes: 40 additions & 0 deletions src/ui/src/builder/useComponentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useComponentClipboard } from "./useComponentClipboard";
import { COMPONENT_TYPES_ROOT } from "@/constants/component";
import { getComponentPage } from "@/composables/useComponentPage";
import { SHARED_BLUEPRINT_FLAG_VALUE } from "@/utils/sharedBlueprint";
import { useBlueprintRun } from "@/composables/useBlueprintRun";

export function useComponentActions(
wf: Core,
Expand Down Expand Up @@ -420,6 +421,35 @@ export function useComponentActions(
return removeComponentsSubtree(componentId);
}

/**
* Runs a blueprint from a target component.
*/
async function runBlueprintFromComponent(
componentId: Component["id"],
): Promise<void> {
const { run } = useBlueprintRun(wf, ssbm, componentId);
await run(componentId);
}

/**
* Stops a running blueprint.
*/
async function stopBlueprintFromComponent(
componentId: Component["id"],
): Promise<void> {
const { stop } = useBlueprintRun(wf, ssbm, componentId);
await stop();
}

/**
* Checks if a blueprint is currently running.
* Note: This checks if any blueprint is running, not specifically for the given component.
*/
function isBlueprintRunning(_componentId: Component["id"]): boolean {
const { isRunning } = useBlueprintRun(wf, ssbm, _componentId);
return isRunning.value !== null;
}

/**
* Whether a target component is the root
*/
Expand All @@ -446,6 +476,12 @@ export function useComponentActions(
);
}

/**
* Whether the blueprint can be run from the target component.
*/
function isRunAllowed(targetId: Component["id"]): boolean {
return !isRoot(targetId);
}
/**
* Whether a component can be copied into the clipboard.
*/
Expand Down Expand Up @@ -1227,6 +1263,9 @@ export function useComponentActions(
copyComponent,
pasteComponent,
createAndInsertComponent,
runBlueprintFromComponent,
stopBlueprintFromComponent,
isBlueprintRunning,
createAndInsertComponentsTree,
removeComponentSubtree,
removeComponentsSubtree,
Expand All @@ -1243,6 +1282,7 @@ export function useComponentActions(
getUndoRedoSnapshot,
setHandlerValue,
isAddAllowed,
isRunAllowed,
isCopyAllowed,
isCutAllowed,
isDeleteAllowed,
Expand Down
1 change: 1 addition & 0 deletions src/ui/src/components/blueprints/base/BlueprintToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ async function runBlueprint(componentId?: string) {
<WdsIcon name="rocket" />
Publish blueprint
</WdsButton>

<WdsButtonSplit
v-if="triggerComponents.length && !isRunning"
ref="runBlueprintBtn"
Expand Down
14 changes: 3 additions & 11 deletions src/ui/src/composables/useBlueprintRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,17 @@ export function useBlueprintRun(
wfbm: BuilderManager,
blueprintComponentId: string | Ref<string>,
) {
const isRunning = ref(false);

async function run(branchId?: string) {
if (isRunning.value) return;
isRunning.value = true;
try {
await runBlueprint(wf, unref(blueprintComponentId), branchId);
} finally {
isRunning.value = false;
}
if (wfbm.activeBlueprintRunId.value) return;
await runBlueprint(wf, unref(blueprintComponentId), branchId);
}

async function stop() {
const activeRunId = wfbm.activeBlueprintRunId.value;
if (!activeRunId) return;
await stopBlueprintRun(wf, activeRunId);
}

return { isRunning: readonly(isRunning), run, stop };
return { isRunning: readonly(wfbm.activeBlueprintRunId), run, stop };
}

export type BlueprintsRunListItem = { blueprintId: string; branchId: string };
Expand Down
5 changes: 5 additions & 0 deletions src/writer/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def _get_blueprint_nodes(self, component_id):
current_node_id = node.parentId
return []


def run_branch(
self,
start_node_id: str,
Expand All @@ -321,6 +322,7 @@ def run_branch(
execution_environment, self, title=title
).run()


def run_branch_batch(
self, base_component_id: str, base_outcome: str, execution_environments: List[Dict]
):
Expand All @@ -333,6 +335,9 @@ def run_branch_batch(
results.append(result)

return results




def run_blueprint(
self, component_id: str, execution_environment: Dict, title="Blueprint execution"
Expand Down