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

feat: Workflow tools #570

Merged
merged 31 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2fc9d2c
chore: Support for unselectable
ramedina86 Sep 27, 2024
e27bfe2
chore: Hide config for workflow components
ramedina86 Sep 27, 2024
63ed3a9
chore: Added support to run workflows
ramedina86 Sep 27, 2024
bdad647
chore: Workflow operations
ramedina86 Sep 27, 2024
57b0d06
chore: Handle node deletion, refine drag, debounce
ramedina86 Sep 27, 2024
f4f8b2e
chore: Handle delete
ramedina86 Sep 27, 2024
e9e133f
chore: Support workflows
ramedina86 Sep 27, 2024
a56856b
feat: Workflows module
ramedina86 Sep 27, 2024
214cbf8
chore: Clean up abstract
ramedina86 Sep 27, 2024
de8cbfb
chore: Support workflows as handlers
ramedina86 Sep 27, 2024
acd3ad9
chore: Moved import
ramedina86 Sep 27, 2024
4f5a83d
feat: Workflow blocks
ramedina86 Sep 27, 2024
f17a349
chore: Clean up print statements
ramedina86 Sep 27, 2024
6402495
chore: Send payload for workflows
ramedina86 Sep 30, 2024
1ed99a0
Update src/ui/src/components/workflows/base/WorkflowArrow.vue
ramedina86 Sep 30, 2024
cde86a1
Update src/ui/src/components/workflows/WorkflowsWorkflow.vue
ramedina86 Sep 30, 2024
262c3a9
Update src/ui/src/builder/useComponentActions.ts
ramedina86 Sep 30, 2024
9e4f638
Update src/ui/src/builder/useComponentActions.ts
ramedina86 Sep 30, 2024
2ee1c64
chore: Refresh arrows after removing
ramedina86 Sep 30, 2024
7fc7b8c
chore: Set allowed parent type to workflow only at node level
ramedina86 Sep 30, 2024
5adc442
chore: Add toolkit restriction
ramedina86 Sep 30, 2024
44f3829
fix: Default inside JSON parsing
ramedina86 Sep 30, 2024
2118c61
chore: Execution env for running workflows
ramedina86 Sep 30, 2024
a533a7a
chore: Blocks
ramedina86 Sep 30, 2024
adfd003
Merge remote-tracking branch 'origin/feat-workflow-tools1' into feat-…
ramedina86 Sep 30, 2024
7a073f4
fix: Whitespace
ramedina86 Sep 30, 2024
ac02d74
fix: Outs difference calc
ramedina86 Sep 30, 2024
3237d8a
chore: More restrictive type for initProperties
ramedina86 Sep 30, 2024
9f26fba
fix: Mypy typing fixes
ramedina86 Sep 30, 2024
3c00960
fix: Ruff linter fixes
ramedina86 Sep 30, 2024
e4495c1
chore: Pass execution env and item
ramedina86 Sep 30, 2024
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
5 changes: 5 additions & 0 deletions src/ui/src/builder/BuilderApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ function handleRendererDrop(ev: DragEvent) {
function handleRendererClick(ev: PointerEvent): void {
if (builderMode.value === "preview") return;

const unselectableEl: HTMLElement = (ev.target as HTMLElement).closest(
"[data-writer-unselectable]",
);
if (unselectableEl) return;

const targetEl: HTMLElement = (ev.target as HTMLElement).closest(
"[data-writer-id]",
);
Expand Down
19 changes: 13 additions & 6 deletions src/ui/src/builder/BuilderSettings.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<template>
<div v-if="ssbm.isSelectionActive()" class="BuilderSettings">
<div class="windowBar">
<div class="title">
{{ componentDefinition.name }}
</div>
<div class="title">{{ componentDefinition.name }}</div>
<button
v-if="description || docsString"
class="windowAction"
Expand Down Expand Up @@ -46,9 +44,18 @@

<div class="sections" :inert="readonly">
<BuilderSettingsProperties></BuilderSettingsProperties>
<BuilderSettingsBinding v-if="isBindable"></BuilderSettingsBinding>
<BuilderSettingsHandlers></BuilderSettingsHandlers>
<BuilderSettingsVisibility></BuilderSettingsVisibility>
<template
v-if="
!componentDefinition.toolkit ||
componentDefinition.toolkit == 'core'
"
>
<BuilderSettingsBinding
v-if="isBindable"
></BuilderSettingsBinding>
<BuilderSettingsHandlers></BuilderSettingsHandlers>
<BuilderSettingsVisibility></BuilderSettingsVisibility>
</template>
</div>

<div class="debug">
Expand Down
25 changes: 25 additions & 0 deletions src/ui/src/builder/BuilderSettingsHandlers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
>
Go to page "{{ pageKey }}"
</option>
<option
v-for="workflowKey in workflowKeys"
:key="`$runWorkflow_${workflowKey}`"
:value="`$runWorkflow_${workflowKey}`"
>
Run workflow "{{ workflowKey }}"
</option>
<template v-if="isHandlerInvalid(eventType)">
<option
:value="component.handlers?.[eventType]"
Expand Down Expand Up @@ -140,6 +147,13 @@
>
Go to page "{{ pageKey }}"
</option>
<option
v-for="workflowKey in workflowKeys"
:key="`$runWorkflow_${workflowKey}`"
:value="`$runWorkflow_${workflowKey}`"
>
Run workflow "{{ workflowKey }}"
</option>
</select>
<span class="desc"
>The function that will handle the event.</span
Expand Down Expand Up @@ -186,14 +200,25 @@ const recognisedEvents: ComputedRef<WriterComponentDefinition["events"]> =
});

const userFunctions = computed(() => wf.getUserFunctions());

const pageKeys = computed(() => {
const pages = wf.getComponents("root");
const pageKeys = pages
.filter((page) => page.type == "page")
.map((page) => page.content["key"])
.filter((pageKey) => Boolean(pageKey));
return pageKeys;
});

const workflowKeys = computed(() => {
const workflows = wf.getComponents("workflows_root");
const workflowKeys = workflows
.filter((workflow) => workflow.type == "workflows_workflow")
.map((workflow) => workflow.content["key"])
.filter((workflowKey) => Boolean(workflowKey));
return workflowKeys;
});

const isHandlerInvalid = (eventType: string) => {
const handlerFunctionName = component.value.handlers?.[eventType];
if (!handlerFunctionName) return false;
Expand Down
88 changes: 87 additions & 1 deletion src/ui/src/builder/useComponentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) {
type: string,
parentId: Component["id"],
position?: number,
initProperties?: Partial<
Omit<
Component,
"id" | "type" | "parent" | "content" | "handlers" | "position"
>
>,
) {
const newId = generateNewComponentId();
const definition = wf.getComponentDefinition(type);
Expand All @@ -137,6 +143,7 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) {
});

const component = {
...(initProperties ?? {}),
id: newId,
type,
parentId,
Expand All @@ -160,8 +167,19 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) {
type: string,
parentId: Component["id"],
position?: number,
initProperties?: Partial<
Omit<
Component,
"id" | "type" | "parent" | "content" | "handlers" | "position"
>
>,
): Component["id"] {
const component = createComponent(type, parentId, position);
const component = createComponent(
type,
parentId,
position,
initProperties,
);
const transactionId = `create-${component.id}`;
ssbm.openMutationTransaction(transactionId, `Create`);
wf.addComponent(component);
Expand Down Expand Up @@ -688,6 +706,71 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) {
wf.sendComponentUpdate();
}

/**
* Add an out
*/
function addOut(
componentId: Component["id"],
out: Component["outs"][number],
) {
const component = wf.getComponentById(componentId);
if (!component) return;
const transactionId = `add-${componentId}-out-${out.outId}-${out.toNodeId}`;
ssbm.openMutationTransaction(transactionId, `Add out`, true);
ssbm.registerPreMutation(component);

component.outs = [...(component.outs ?? []), out];

ssbm.registerPostMutation(component);
ssbm.closeMutationTransaction(transactionId);
wf.sendComponentUpdate();
}

/**
* Remove an out
*/
function removeOut(
componentId: Component["id"],
out: Component["outs"][number],
) {
const component = wf.getComponentById(componentId);
if (!component) return;
const transactionId = `edit-${componentId}-out-${out.outId}-${out.toNodeId}`;
ssbm.openMutationTransaction(transactionId, `Edit out`, true);
ssbm.registerPreMutation(component);

component.outs = component.outs.filter(
(o) => !(out.outId === o.outId && out.toNodeId === o.toNodeId),
);

ssbm.registerPostMutation(component);
ssbm.closeMutationTransaction(transactionId);
wf.sendComponentUpdate();
}

/**
* Change coordinates
*/
function changeCoordinates(
componentId: Component["id"],
x: number,
y: number,
) {
const component = wf.getComponentById(componentId);
if (!component) return;

const transactionId = `change-${componentId}-coordinates`;
ssbm.openMutationTransaction(transactionId, `Change coordinates`, true);
ssbm.registerPreMutation(component);

component.x = Math.floor(x);
component.y = Math.floor(y);

ssbm.registerPostMutation(component);
ssbm.closeMutationTransaction(transactionId);
wf.sendComponentUpdate();
}

/**
* Set the value for a component's visibility.
*/
Expand Down Expand Up @@ -833,6 +916,9 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) {
undo,
redo,
setContentValue,
addOut,
removeOut,
changeCoordinates,
setVisibleValue,
setBinding,
getUndoRedoSnapshot,
Expand Down
Loading
Loading