refactor(editor): Migrate n8nRootStore to use composition API (no-changelog) (#9770)
This commit is contained in:
@@ -21,7 +21,7 @@ vi.mock('@/stores/ndv.store', () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock('@/stores/n8nRoot.store', () => ({
|
||||
vi.mock('@/stores/root.store', () => ({
|
||||
useRootStore: vi.fn(() => ({
|
||||
instanceId: 'test-instance-id',
|
||||
})),
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ExpressionExtensions } from 'n8n-workflow';
|
||||
import { EditorView, type ViewUpdate } from '@codemirror/view';
|
||||
|
||||
import { useNDVStore } from '@/stores/ndv.store';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { useTelemetry } from '../composables/useTelemetry';
|
||||
import type { Compartment } from '@codemirror/state';
|
||||
import { debounce } from 'lodash-es';
|
||||
|
||||
@@ -14,7 +14,7 @@ import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
import { useTelemetry } from './useTelemetry';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { isFullExecutionResponse } from '@/utils/typeGuards';
|
||||
|
||||
export const useExecutionDebugging = () => {
|
||||
|
||||
@@ -15,8 +15,7 @@ import { useExternalHooks } from '@/composables/useExternalHooks';
|
||||
import { useTelemetry } from '@/composables/useTelemetry';
|
||||
import type { MaybeRef } from 'vue';
|
||||
import { computed, unref } from 'vue';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { useNodeType } from '@/composables/useNodeType';
|
||||
import { useDataSchema } from './useDataSchema';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
@@ -52,7 +51,6 @@ export function usePinnedData(
|
||||
const externalHooks = useExternalHooks();
|
||||
const { getInputDataWithPinned } = useDataSchema();
|
||||
|
||||
const { pushRef } = storeToRefs(rootStore);
|
||||
const { isSubNodeType, isMultipleOutputsNodeType } = useNodeType({
|
||||
node,
|
||||
});
|
||||
@@ -197,7 +195,7 @@ export function usePinnedData(
|
||||
const telemetryPayload = {
|
||||
pinning_source: source,
|
||||
node_type: targetNode?.type,
|
||||
push_ref: pushRef.value,
|
||||
push_ref: rootStore.pushRef,
|
||||
data_size: stringSizeInBytes(data.value),
|
||||
view: displayMode,
|
||||
run_index: runIndex,
|
||||
@@ -221,7 +219,7 @@ export function usePinnedData(
|
||||
telemetry.track('Ndv data pinning failure', {
|
||||
pinning_source: source,
|
||||
node_type: targetNode?.type,
|
||||
push_ref: pushRef.value,
|
||||
push_ref: rootStore.pushRef,
|
||||
data_size: stringSizeInBytes(data.value),
|
||||
view: displayMode,
|
||||
run_index: runIndex,
|
||||
@@ -259,7 +257,7 @@ export function usePinnedData(
|
||||
|
||||
telemetry.track('User unpinned ndv data', {
|
||||
node_type: targetNode?.type,
|
||||
push_ref: pushRef.value,
|
||||
push_ref: rootStore.pushRef,
|
||||
run_index: runIndex,
|
||||
source,
|
||||
data_size: stringSizeInBytes(data.value),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { useRunWorkflow } from '@/composables/useRunWorkflow';
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { setActivePinia } from 'pinia';
|
||||
@@ -10,10 +10,6 @@ import { useRouter } from 'vue-router';
|
||||
import { ExpressionError, type IPinData, type IRunData, type Workflow } from 'n8n-workflow';
|
||||
import type * as router from 'vue-router';
|
||||
|
||||
vi.mock('@/stores/n8nRoot.store', () => ({
|
||||
useRootStore: vi.fn().mockReturnValue({ pushConnectionActive: true }),
|
||||
}));
|
||||
|
||||
vi.mock('@/stores/workflows.store', () => ({
|
||||
useWorkflowsStore: vi.fn().mockReturnValue({
|
||||
runWorkflow: vi.fn(),
|
||||
@@ -95,7 +91,7 @@ describe('useRunWorkflow({ router })', () => {
|
||||
let workflowHelpers: ReturnType<typeof useWorkflowHelpers>;
|
||||
|
||||
beforeAll(() => {
|
||||
const pinia = createTestingPinia();
|
||||
const pinia = createTestingPinia({ stubActions: false });
|
||||
|
||||
setActivePinia(pinia);
|
||||
|
||||
@@ -110,7 +106,8 @@ describe('useRunWorkflow({ router })', () => {
|
||||
describe('runWorkflowApi()', () => {
|
||||
it('should throw an error if push connection is not active', async () => {
|
||||
const { runWorkflowApi } = useRunWorkflow({ router });
|
||||
rootStore.pushConnectionActive = false;
|
||||
|
||||
rootStore.setPushConnectionInactive();
|
||||
|
||||
await expect(runWorkflowApi({} as IStartRunData)).rejects.toThrow(
|
||||
'workflowRun.noActiveConnectionToTheServer',
|
||||
@@ -119,7 +116,8 @@ describe('useRunWorkflow({ router })', () => {
|
||||
|
||||
it('should successfully run a workflow', async () => {
|
||||
const { runWorkflowApi } = useRunWorkflow({ router });
|
||||
rootStore.pushConnectionActive = true;
|
||||
|
||||
rootStore.setPushConnectionActive();
|
||||
|
||||
const mockResponse = { executionId: '123', waitingForWebhook: false };
|
||||
vi.mocked(workflowsStore).runWorkflow.mockResolvedValue(mockResponse);
|
||||
@@ -135,7 +133,7 @@ describe('useRunWorkflow({ router })', () => {
|
||||
it('should handle workflow run failure', async () => {
|
||||
const { runWorkflowApi } = useRunWorkflow({ router });
|
||||
|
||||
rootStore.pushConnectionActive = true;
|
||||
rootStore.setPushConnectionActive();
|
||||
vi.mocked(workflowsStore).runWorkflow.mockRejectedValue(new Error('Failed to run workflow'));
|
||||
|
||||
await expect(runWorkflowApi({} as IStartRunData)).rejects.toThrow('Failed to run workflow');
|
||||
@@ -145,7 +143,7 @@ describe('useRunWorkflow({ router })', () => {
|
||||
it('should set waitingForWebhook if response indicates waiting', async () => {
|
||||
const { runWorkflowApi } = useRunWorkflow({ router });
|
||||
|
||||
rootStore.pushConnectionActive = true;
|
||||
rootStore.setPushConnectionActive();
|
||||
const mockResponse = { executionId: '123', waitingForWebhook: true };
|
||||
vi.mocked(workflowsStore).runWorkflow.mockResolvedValue(mockResponse);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
WORKFLOW_LM_CHAT_MODAL_KEY,
|
||||
} from '@/constants';
|
||||
import { useTitleChange } from '@/composables/useTitleChange';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { openPopUpWindow } from '@/utils/executionUtils';
|
||||
@@ -279,12 +279,12 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
||||
|
||||
if (node.type === FORM_TRIGGER_NODE_TYPE && node.typeVersion === 1) {
|
||||
const webhookPath = (node.parameters.path as string) || node.webhookId;
|
||||
testUrl = `${rootStore.getWebhookTestUrl}/${webhookPath}/${FORM_TRIGGER_PATH_IDENTIFIER}`;
|
||||
testUrl = `${rootStore.webhookTestUrl}/${webhookPath}/${FORM_TRIGGER_PATH_IDENTIFIER}`;
|
||||
}
|
||||
|
||||
if (node.type === FORM_TRIGGER_NODE_TYPE && node.typeVersion > 1) {
|
||||
const webhookPath = (node.parameters.path as string) || node.webhookId;
|
||||
testUrl = `${rootStore.getFormTestUrl}/${webhookPath}`;
|
||||
testUrl = `${rootStore.formTestUrl}/${webhookPath}`;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -308,7 +308,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
||||
const { webhookSuffix } = (node.parameters.options ?? {}) as IDataObject;
|
||||
const suffix =
|
||||
webhookSuffix && typeof webhookSuffix !== 'object' ? `/${webhookSuffix}` : '';
|
||||
testUrl = `${rootStore.getFormWaitingUrl}/${runWorkflowApiResponse.executionId}${suffix}`;
|
||||
testUrl = `${rootStore.formWaitingUrl}/${runWorkflowApiResponse.executionId}${suffix}`;
|
||||
}
|
||||
|
||||
if (testUrl) openPopUpWindow(testUrl);
|
||||
|
||||
@@ -50,7 +50,7 @@ import { useNodeHelpers } from '@/composables/useNodeHelpers';
|
||||
import { get, isEqual } from 'lodash-es';
|
||||
|
||||
import { useEnvironmentsStore } from '@/stores/environments.ee.store';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { useNDVStore } from '@/stores/ndv.store';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
import { useTemplatesStore } from '@/stores/templates.store';
|
||||
@@ -779,9 +779,9 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
|
||||
|
||||
let baseUrl;
|
||||
if (showUrlFor === 'test') {
|
||||
baseUrl = isForm ? rootStore.getFormTestUrl : rootStore.getWebhookTestUrl;
|
||||
baseUrl = isForm ? rootStore.formTestUrl : rootStore.webhookTestUrl;
|
||||
} else {
|
||||
baseUrl = isForm ? rootStore.getFormUrl : rootStore.getWebhookUrl;
|
||||
baseUrl = isForm ? rootStore.formUrl : rootStore.webhookUrl;
|
||||
}
|
||||
|
||||
const workflowId = workflowsStore.workflowId;
|
||||
|
||||
Reference in New Issue
Block a user