Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: allows deeplinking of a workflow node (#42502)

Joffrey JAFFEUXc37cf0f27299
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjs
index c15a95a119b..fcb6bfe562f 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjs
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjs
@@ -506,6 +506,7 @@ export default class WorkflowCanvas extends Component {
await this.#queueSync();
this.isLoading = false;
element.focus();
+ this.args.onReady?.();
}
// Left clicks are trapped on the canvas and never reach the document
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs
index 6d3dc395b31..e4a556ab6e4 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs
@@ -5,6 +5,7 @@ import { service } from "@ember/service";
import Form from "discourse/components/form";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { bind } from "discourse/lib/decorators";
+import DiscourseURL from "discourse/lib/url";
import { i18n } from "discourse-i18n";
import WorkflowEditorSession from "../../../lib/workflows/editor-session";
import {
@@ -23,6 +24,7 @@ import {
typeVersionForNode,
} from "../../../lib/workflows/node-types";
import { mergeImportedStaticData } from "../../../lib/workflows/static-data";
+import { workflowNodeUrl, workflowUrl } from "../../../lib/workflows/urls";
import StickyNote, { STICKY_NOTE_TYPE } from "../../../models/sticky-note";
import { deserializeConnections } from "../../../models/workflow-connection";
import WorkflowNode from "../../../models/workflow-node";
@@ -143,6 +145,7 @@ export default class WorkflowsEditor extends Component {
currentSavePromise = null;
pendingGraphSnapshot = null;
pendingSaveOptions = null;
+ initialNodeHandled = false;
workflowSession = new WorkflowEditorSession({
workflowId: this.args.workflow?.id,
lastExecutionRunData: this.args.workflow?.lastExecutionRunData || null,
@@ -297,6 +300,27 @@ export default class WorkflowsEditor extends Component {
this.formApi = api;
}
+ @action
+ openInitialNode() {
+ if (
+ !this.args.initialNodeId ||
+ this.initialNodeHandled ||
+ this.isDestroying ||
+ this.isDestroyed
+ ) {
+ return;
+ }
+
+ this.initialNodeHandled = true;
+
+ if (!this.editNode(this.args.initialNodeId, { updateUrl: false })) {
+ this.router.replaceWith(
+ "adminPlugins.show.discourse-workflows.show.index",
+ this.args.workflow.id
+ );
+ }
+ }
+
#refreshUndoState() {
this.canUndo = this.undoManager.canUndo;
this.canRedo = this.undoManager.canRedo;
@@ -711,34 +735,53 @@ export default class WorkflowsEditor extends Component {
}
@action
- editNode(clientId) {
+ editNode(clientId, { updateUrl = true } = {}) {
const nodes = this.formApi.get("nodes");
const connections = this.formApi.get("connections");
const node = nodes.find((n) => n.clientId === clientId);
if (!node) {
- return;
+ return false;
}
if (isNodeUnavailable(this.workflowsNodeTypes, node)) {
- return;
+ return false;
}
const triggerNode = nodes.find((n) => n.type?.startsWith("trigger:"));
this.workflowSession.setEditingContext(node, nodes, connections);
- this.modal.show(NodeConfigurator, {
- model: {
- node,
- nodes,
- connections,
- session: this.workflowSession,
- triggerType: triggerNode?.type,
- onSave: (configuration, name, options) =>
- this.updateNodeConfiguration(clientId, configuration, name, options),
- onRemove: () => this.removeNodes([clientId]),
- },
- });
+ if (updateUrl) {
+ DiscourseURL.replaceState(
+ workflowNodeUrl(this.args.workflow.id, clientId)
+ );
+ }
+
+ this.modal
+ .show(NodeConfigurator, {
+ model: {
+ node,
+ nodes,
+ connections,
+ session: this.workflowSession,
+ triggerType: triggerNode?.type,
+ onSave: (configuration, name, options) =>
+ this.updateNodeConfiguration(
+ clientId,
+ configuration,
+ name,
+ options
+ ),
+ onRemove: () => this.removeNodes([clientId]),
+ },
+ })
+ .finally(() => {
+ if (!this.isDestroying && !this.isDestroyed) {
+ DiscourseURL.replaceState(workflowUrl(this.args.workflow.id));
+ }
+ });
+
+ return true;
}
@action
@@ -1495,6 +1538,7 @@ export default class WorkflowsEditor extends Component {
@onConnectionDelete={{this.deleteConnection}}
@onNodeDragEnd={{this.handleSubmit}}
@onAreaReady={{this.initializeUndo}}
+ @onReady={{this.openInitialNode}}
@onUndo={{this.undo}}
@onRedo={{this.redo}}
@canUndo={{this.canUndo}}
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/discourse-workflows-route-map.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/discourse-workflows-route-map.js
index 0a9efecc07d..a90767a6428 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/discourse-workflows-route-map.js
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/discourse-workflows-route-map.js
@@ -5,6 +5,7 @@ export default {
this.route("discourse-workflows", { path: "workflows" }, function () {
this.route("new");
this.route("show", { path: "/:id" }, function () {
+ this.route("node", { path: "/nodes/:node_id" });
this.route("executions", function () {
this.route("show", { path: "/:execution_id" });
});
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/urls.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/urls.js
new file mode 100644
index 00000000000..93aa47b8a58
--- /dev/null
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/urls.js
@@ -0,0 +1,9 @@
+const WORKFLOWS_PATH = "/admin/plugins/discourse-workflows/workflows";
+
+export function workflowUrl(workflowId) {
+ return `${WORKFLOWS_PATH}/${encodeURIComponent(workflowId)}`;
+}
+
+export function workflowNodeUrl(workflowId, nodeId) {
+ return `${workflowUrl(workflowId)}/nodes/${encodeURIComponent(nodeId)}`;
+}
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-workflows/show/node.js b/plugins/discourse-workflows/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-workflows/show/node.js
new file mode 100644
index 00000000000..de93999656c
--- /dev/null
+++ b/plugins/discourse-workflows/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-workflows/show/node.js
@@ -0,0 +1,12 @@
+import DiscourseRoute from "discourse/routes/discourse";
+
+const WORKFLOW_ROUTE = "adminPlugins.show.discourse-workflows.show";
+
+export default class DiscourseWorkflowsShowNodeRoute extends DiscourseRoute {
+ model(params) {
+ return {
+ ...this.modelFor(WORKFLOW_ROUTE),
+ initialNodeId: params.node_id,
+ };
+ }
+}
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-workflows/show.gjs b/plugins/discourse-workflows/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-workflows/show.gjs
index 0d95b2d0370..27c4ce9e36c 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-workflows/show.gjs
+++ b/plugins/discourse-workflows/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-workflows/show.gjs
@@ -9,6 +9,7 @@ import DNavItem from "discourse/ui-kit/d-nav-item";
import WorkflowEditableTitle from "discourse/plugins/discourse-workflows/admin/components/workflows/editable-title";
import Stats from "discourse/plugins/discourse-workflows/admin/components/workflows/stats";
import WorkflowTagsEditor from "discourse/plugins/discourse-workflows/admin/components/workflows/tags-editor";
+import { workflowUrl } from "discourse/plugins/discourse-workflows/admin/lib/workflows/urls";
class WorkflowShowPage extends Component {
get workflow() {
@@ -19,6 +20,10 @@ class WorkflowShowPage extends Component {
return this.args.controller.model.stats;
}
+ get workflowPath() {
+ return workflowUrl(this.workflow.id);
+ }
+
@action
async updateName(name) {
try {
@@ -35,7 +40,7 @@ class WorkflowShowPage extends Component {
<template>
{{htmlClass "workflows-page"}}
<DBreadcrumbsItem
- @path="/admin/plugins/discourse-workflows/workflows/{{this.workflow.id}}"
+ @path={{this.workflowPath}}
@label={{this.workflow.name}}
/>
@@ -57,6 +62,7 @@ class WorkflowShowPage extends Component {
<DHorizontalOverflowNav>
<DNavItem
@route="adminPlugins.show.discourse-workflows.show.index"
+ @currentWhen="adminPlugins.show.discourse-workflows.show.index adminPlugins.show.discourse-workflows.show.node"
@label="discourse_workflows.tabs.workflow"
/>
<DNavItem
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-workflows/show/node.gjs b/plugins/discourse-workflows/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-workflows/show/node.gjs
new file mode 100644
index 00000000000..1948900f5ef
--- /dev/null
+++ b/plugins/discourse-workflows/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-workflows/show/node.gjs
@@ -0,0 +1,8 @@
+import WorkflowsEditor from "discourse/plugins/discourse-workflows/admin/components/workflows/editor";
+
+export default <template>
+ <WorkflowsEditor
+ @workflow={{@controller.model.workflow}}
+ @initialNodeId={{@controller.model.initialNodeId}}
+ />
+</template>
diff --git a/plugins/discourse-workflows/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js b/plugins/discourse-workflows/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js
index 1518f8ef53d..2a6d4b1f12d 100644
--- a/plugins/discourse-workflows/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js
+++ b/plugins/discourse-workflows/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js
@@ -17,7 +17,7 @@ export default {
label: "discourse_workflows.title",
route: "adminPlugins.show.discourse-workflows.index",
currentWhen:
- "adminPlugins.show.discourse-workflows.index adminPlugins.show.discourse-workflows.new adminPlugins.show.discourse-workflows.show.index adminPlugins.show.discourse-workflows.show.executions.index adminPlugins.show.discourse-workflows.show.executions.show adminPlugins.show.discourse-workflows.show.settings",
+ "adminPlugins.show.discourse-workflows.index adminPlugins.show.discourse-workflows.new adminPlugins.show.discourse-workflows.show.index adminPlugins.show.discourse-workflows.show.node adminPlugins.show.discourse-workflows.show.executions.index adminPlugins.show.discourse-workflows.show.executions.show adminPlugins.show.discourse-workflows.show.settings",
},
{
label: "discourse_workflows.variables.title",
diff --git a/plugins/discourse-workflows/config/routes.rb b/plugins/discourse-workflows/config/routes.rb
index 1e98c073842..e800311021a 100644
--- a/plugins/discourse-workflows/config/routes.rb
+++ b/plugins/discourse-workflows/config/routes.rb
@@ -14,6 +14,11 @@ DiscourseWorkflows::Engine.routes.draw do
get "/credentials" => "admin#index"
get "/workflows/new" => "admin#index"
get "/workflows/:id" => "admin#index", :constraints => { id: /\d+/ }
+ get "/workflows/:id/nodes/:node_id" => "admin#index",
+ :constraints => {
+ id: /\d+/,
+ node_id: %r{[^/]+},
+ }
get "/workflows/:id/executions" => "admin#index", :constraints => { id: /\d+/ }
get "/workflows/:id/executions/:execution_id" => "admin#index",
:constraints => {
diff --git a/plugins/discourse-workflows/spec/system/page_objects/pages/workflow_editor.rb b/plugins/discourse-workflows/spec/system/page_objects/pages/workflow_editor.rb
index c200ad30550..ae25c9058b9 100644
--- a/plugins/discourse-workflows/spec/system/page_objects/pages/workflow_editor.rb
+++ b/plugins/discourse-workflows/spec/system/page_objects/pages/workflow_editor.rb
@@ -4,13 +4,20 @@ module PageObjects
module Pages
module DiscourseWorkflows
class WorkflowEditor < PageObjects::Pages::Base
+ WORKFLOWS_PATH = "/admin/plugins/discourse-workflows/workflows"
+
def visit_new
- page.visit("/admin/plugins/discourse-workflows/workflows/new")
+ page.visit("#{WORKFLOWS_PATH}/new")
self
end
def visit(workflow_id)
- page.visit("/admin/plugins/discourse-workflows/workflows/#{workflow_id}")
+ page.visit("#{WORKFLOWS_PATH}/#{workflow_id}")
+ self
+ end
+
+ def visit_node(workflow, node_id)
+ page.visit(node_path(workflow, node_id))
self
end
@@ -34,14 +41,40 @@ module PageObjects
page.has_css?(".workflows-tags-editor .d-table-badge", text: tag)
end
- def has_node_configurator?
- page.has_css?(".workflows-configurator-modal")
+ def rename_configured_node(name)
+ find(".workflows-configurator-modal__name").click
+ find(".workflows-configurator-modal__name-input").fill_in(with: name)
+ find(".workflows-configurator-modal__save-name").click
+ self
+ end
+
+ def has_node_configurator?(name: nil)
+ if name
+ page.has_css?(
+ ".workflows-configurator-modal .workflows-configurator-modal__name",
+ exact_text: name,
+ )
+ else
+ page.has_css?(".workflows-configurator-modal")
+ end
end
def has_no_node_configurator?
page.has_no_css?(".workflows-configurator-modal")
end
+ def has_saved_node_configuration?
+ page.has_css?(".workflows-configurator-modal__save-status--saved")
+ end
+
+ def has_workflow_path?(workflow)
+ page.has_current_path?(workflow_path(workflow))
+ end
+
+ def has_node_path?(workflow, node_id)
+ page.has_current_path?(node_path(workflow, node_id))
+ end
+
def edit_name(name)
find(".workflows-editable-title__text").click
find(".workflows-editable-title__input").fill_in(with: name)
@@ -155,6 +188,16 @@ module PageObjects
page.has_css?(".workflow-rete-node__port-pill", text: "true", wait: 10) &&
page.has_css?(".workflow-rete-node__port-pill", text: "false", wait: 10)
end
+
+ private
+
+ def workflow_path(workflow)
+ "#{WORKFLOWS_PATH}/#{workflow.id}"
+ end
+
+ def node_path(workflow, node_id)
+ "#{workflow_path(workflow)}/nodes/#{ERB::Util.url_encode(node_id)}"
+ end
end
end
end
diff --git a/plugins/discourse-workflows/spec/system/workflows_spec.rb b/plugins/discourse-workflows/spec/system/workflows_spec.rb
index d1984094504..85237404cf9 100644
--- a/plugins/discourse-workflows/spec/system/workflows_spec.rb
+++ b/plugins/discourse-workflows/spec/system/workflows_spec.rb
@@ -110,14 +110,40 @@ RSpec.describe "Discourse Workflows" do
end
end
- context "when closing the node configurator" do
+ context "with a persisted workflow node" do
fab!(:workflow) { Fabricate(:discourse_workflows_workflow, created_by: admin) }
+ fab!(:unavailable_workflow) do
+ Fabricate(
+ :discourse_workflows_workflow,
+ created_by: admin,
+ nodes: [
+ {
+ "id" => "unavailable-1",
+ "type" => "action:disabled_plugin_node",
+ "typeVersion" => "1.0",
+ "name" => "Unavailable node",
+ "position" => {
+ "x" => 100,
+ "y" => 100,
+ },
+ "parameters" => {
+ },
+ "credentials" => {
+ },
+ },
+ ],
+ connections: {
+ },
+ )
+ end
+
+ let(:node_id) { "trigger.1" }
before do
workflow.update!(
nodes: [
{
- "id" => "trigger-1",
+ "id" => node_id,
"type" => "trigger:manual",
"typeVersion" => "1.0",
"name" => "Manual trigger",
@@ -158,13 +184,45 @@ RSpec.describe "Discourse Workflows" do
count_workflow_updates do
editor_page.visit(workflow.id)
expect(editor_page).to have_node_count(1)
+ expect(editor_page).to have_workflow_path(workflow)
+
editor_page.double_click_node(0)
expect(editor_page).to have_node_configurator
+ expect(editor_page).to have_node_path(workflow, node_id)
+
editor_page.close_node_configurator
expect(editor_page).to have_no_node_configurator
+ expect(editor_page).to have_workflow_path(workflow)
end
expect(updates).to eq(0)
end
+
+ it "lets an admin reopen the same configured node after a refresh" do
+ editor_page.visit_node(workflow, node_id)
+
+ expect(editor_page).to have_node_path(workflow, node_id)
+ expect(editor_page).to have_node_configurator(name: "Manual trigger")
+
+ editor_page.rename_configured_node("Refreshable manual trigger")
+ expect(editor_page).to have_saved_node_configuration
+
+ page.refresh
+
+ expect(editor_page).to have_node_path(workflow, node_id)
+ expect(editor_page).to have_node_configurator(name: "Refreshable manual trigger")
+ end
+
+ it "returns an admin to the workflow when a linked node is missing or unavailable" do
+ editor_page.visit_node(workflow, "missing-node")
+
+ expect(editor_page).to have_workflow_path(workflow)
+ expect(editor_page).to have_no_node_configurator
+
+ editor_page.visit_node(unavailable_workflow, "unavailable-1")
+
+ expect(editor_page).to have_workflow_path(unavailable_workflow)
+ expect(editor_page).to have_no_node_configurator
+ end
end
end