mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
use local storage to redirect to next waiting form
This commit is contained in:
parent
73d383d53d
commit
9883a7a53f
|
@ -735,6 +735,14 @@
|
|||
}
|
||||
|
||||
return;
|
||||
}).then(() => {
|
||||
window.addEventListener('storage', function(event) {
|
||||
if (event.key === 'n8n_redirect_to_next_form_test_page' && event.newValue) {
|
||||
const newUrl = event.newValue;
|
||||
localStorage.removeItem('n8n_redirect_to_next_form_test_page');
|
||||
window.location.replace(newUrl);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error('Error:', error);
|
||||
|
|
|
@ -20,7 +20,12 @@ import { NodeConnectionType } from 'n8n-workflow';
|
|||
import { useToast } from '@/composables/useToast';
|
||||
import { useNodeHelpers } from '@/composables/useNodeHelpers';
|
||||
|
||||
import { CHAT_TRIGGER_NODE_TYPE, WAIT_NODE_TYPE, WORKFLOW_LM_CHAT_MODAL_KEY } from '@/constants';
|
||||
import {
|
||||
CHAT_TRIGGER_NODE_TYPE,
|
||||
FORM_TRIGGER_NODE_TYPE,
|
||||
WAIT_NODE_TYPE,
|
||||
WORKFLOW_LM_CHAT_MODAL_KEY,
|
||||
} from '@/constants';
|
||||
import { useTitleChange } from '@/composables/useTitleChange';
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
|
@ -296,10 +301,10 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||
shouldShowForm,
|
||||
});
|
||||
|
||||
// await useExternalHooks().run('workflowRun.runWorkflow', {
|
||||
// nodeName: options.destinationNode,
|
||||
// source: options.source,
|
||||
// });
|
||||
await useExternalHooks().run('workflowRun.runWorkflow', {
|
||||
nodeName: options.destinationNode,
|
||||
source: options.source,
|
||||
});
|
||||
|
||||
return runWorkflowApiResponse;
|
||||
} catch (error) {
|
||||
|
@ -309,11 +314,11 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||
}
|
||||
}
|
||||
|
||||
function openWaitNodeFormResumeUrl(node: INode, executionId: string) {
|
||||
function gerWaitNodeFormResumeUrl(node: INode, executionId: string) {
|
||||
const { webhookSuffix } = (node.parameters.options ?? {}) as IDataObject;
|
||||
const suffix = webhookSuffix && typeof webhookSuffix !== 'object' ? `/${webhookSuffix}` : '';
|
||||
const testUrl = `${rootStore.formWaitingUrl}/${executionId}${suffix}`;
|
||||
openPopUpWindow(testUrl);
|
||||
return testUrl;
|
||||
}
|
||||
|
||||
async function runWorkflowAndResolveWaitingNodesData(options: {
|
||||
|
@ -346,6 +351,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||
if (!executionId) executionId = await waitForWebhook();
|
||||
|
||||
const shownForms: string[] = [];
|
||||
let isFormShown = workflowsStore.allNodes.some((node) => node.type === FORM_TRIGGER_NODE_TYPE);
|
||||
|
||||
const resolveWaitingNodesData = async (): Promise<void> => {
|
||||
return await new Promise<void>((resolve) => {
|
||||
|
@ -358,7 +364,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||
return;
|
||||
}
|
||||
|
||||
if (execution.finished) {
|
||||
if (execution.finished || ['error', 'canceled', 'crashed'].includes(execution.status)) {
|
||||
workflowsStore.setWorkflowExecutionData(execution);
|
||||
nodeHelpers.updateNodesExecutionIssues();
|
||||
clearInterval(interval);
|
||||
|
@ -379,7 +385,14 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||
waitingNode.parameters.resume === 'form' &&
|
||||
!shownForms.includes(waitingNode.name)
|
||||
) {
|
||||
openWaitNodeFormResumeUrl(waitingNode, executionId as string);
|
||||
const testUrl = gerWaitNodeFormResumeUrl(waitingNode, executionId as string);
|
||||
if (isFormShown) {
|
||||
localStorage.setItem('n8n_redirect_to_next_form_test_page', testUrl);
|
||||
} else {
|
||||
isFormShown = true;
|
||||
openPopUpWindow(testUrl);
|
||||
}
|
||||
|
||||
shownForms.push(waitingNode.name);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue