Skip to content

Commit

Permalink
alternative proposal for node-2026
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Nov 27, 2024
1 parent a8df221 commit a3958da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
13 changes: 3 additions & 10 deletions packages/editor-ui/src/stores/workflows.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import { TelemetryHelpers } from 'n8n-workflow';
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
import { useRouter } from 'vue-router';
import { useSettingsStore } from './settings.store';
import { openPopUpWindow } from '@/utils/executionUtils';
import { closeFormPopupWindow, openFormPopupWindow } from '@/utils/executionUtils';
import { useNodeHelpers } from '@/composables/useNodeHelpers';

const defaults: Omit<IWorkflowDb, 'id'> & { settings: NonNullable<IWorkflowDb['settings']> } = {
Expand Down Expand Up @@ -143,7 +143,6 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
const chatMessages = ref<string[]>([]);
const isChatPanelOpen = ref(false);
const isLogsPanelOpen = ref(false);
const formPopupWindow = ref<Window | null>(null);

const workflowName = computed(() => workflow.value.name);

Expand Down Expand Up @@ -1319,12 +1318,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
(node.type === WAIT_NODE_TYPE && node.parameters.resume === 'form')
) {
const testUrl = getFormResumeUrl(node, executionId);
if (!formPopupWindow.value || formPopupWindow.value.closed) {
formPopupWindow.value = openPopUpWindow(testUrl);
} else {
formPopupWindow.value.location = testUrl;
formPopupWindow.value.focus();
}
openFormPopupWindow(testUrl);
}
} else {
if (tasksData.length && tasksData[tasksData.length - 1].executionStatus === 'waiting') {
Expand Down Expand Up @@ -1577,8 +1571,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
uiStore.removeActiveAction('workflowRunning');
workflowHelpers.setDocumentTitle(workflowName.value, 'IDLE');

formPopupWindow.value?.close();
formPopupWindow.value = null;
closeFormPopupWindow();

const runData = workflowExecutionData.value?.data?.resultData.runData ?? {};
for (const nodeName in runData) {
Expand Down
29 changes: 16 additions & 13 deletions packages/editor-ui/src/utils/executionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,28 @@ export const executionFilterToQueryFilter = (
return queryFilter;
};

export const openPopUpWindow = (
url: string,
options?: { width?: number; height?: number; alwaysInNewTab?: boolean },
) => {
const windowWidth = window.innerWidth;
const smallScreen = windowWidth <= 800;
if (options?.alwaysInNewTab || smallScreen) {
return window.open(url, '_blank');
} else {
const height = options?.width || 700;
const width = options?.height || window.innerHeight - 50;
let formPopupWindow: Window | null = null;

export const openFormPopupWindow = (url: string) => {
if (!formPopupWindow || formPopupWindow.closed) {
const height = 700;
const width = window.innerHeight - 50;
const left = (window.innerWidth - height) / 2;
const top = 50;
const features = `width=${height},height=${width},left=${left},top=${top},resizable=yes,scrollbars=yes`;
const windowName = `form-waiting-since-${Date.now()}`;
return window.open(url, windowName, features);
formPopupWindow = window.open(url, windowName, features);
} else {
formPopupWindow.location = url;
formPopupWindow.focus();
}
};

export const closeFormPopupWindow = () => {
formPopupWindow?.close();
formPopupWindow = null;
};

export function displayForm({
nodes,
runData,
Expand Down Expand Up @@ -131,7 +134,7 @@ export function displayForm({
if (node.name === destinationNode || !node.disabled) {
let testUrl = '';
if (node.type === FORM_TRIGGER_NODE_TYPE) testUrl = getTestUrl(node);
if (testUrl && source !== 'RunData.ManualChatMessage') openPopUpWindow(testUrl);
if (testUrl && source !== 'RunData.ManualChatMessage') openFormPopupWindow(testUrl);
}
}
}
Expand Down

0 comments on commit a3958da

Please sign in to comment.