Skip to content

Commit

Permalink
refactor(editor): Migrate n8nRootStore to use composition API (no-c…
Browse files Browse the repository at this point in the history
…hangelog) (n8n-io#9770)
  • Loading branch information
RicardoE105 authored and adrian-martinez-onestic committed Jun 20, 2024
1 parent f9a7a3f commit 2ce9aa4
Show file tree
Hide file tree
Showing 83 changed files with 486 additions and 410 deletions.
2 changes: 1 addition & 1 deletion packages/editor-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { useExternalHooks } from '@/composables/useExternalHooks';
import { useToast } from '@/composables/useToast';
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useTemplatesStore } from '@/stores/templates.store';
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useUsersStore } from '@/stores/users.store';
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { initializeAuthenticatedFeatures, initializeCore } from '@/init';
import { createTestingPinia } from '@pinia/testing';
import { setActivePinia } from 'pinia';
Expand All @@ -13,7 +13,7 @@ vi.mock('@/stores/users.store', () => ({
useUsersStore: vi.fn().mockReturnValue({ initialize: vi.fn() }),
}));

vi.mock('@/stores/n8nRoot.store', () => ({
vi.mock('@/stores/root.store', () => ({
useRootStore: vi.fn(),
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/AboutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { createEventBus } from 'n8n-design-system/utils';
import Modal from './Modal.vue';
import { ABOUT_MODAL_KEY } from '../constants';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
export default defineComponent({
name: 'About',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { computed, ref } from 'vue';
import { STORES } from '@/constants';
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
import { useStorage } from '@/composables/useStorage';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { getBecomeCreatorCta } from '@/api/ctas';

const LOCAL_STORAGE_KEY = 'N8N_BECOME_TEMPLATE_CREATOR_CTA_DISMISSED_AT';
Expand Down Expand Up @@ -42,7 +42,7 @@ export const useBecomeTemplateCreatorStore = defineStore(STORES.BECOME_TEMPLATE_
};

const fetchBecomeCreatorCta = async () => {
const becomeCreatorCta = await getBecomeCreatorCta(rootStore.getRestApiContext);
const becomeCreatorCta = await getBecomeCreatorCta(rootStore.restApiContext);

ctaMeetsCriteria.value = becomeCreatorCta;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/components/ChatEmbedModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { EventBus } from 'n8n-design-system/utils';
import { createEventBus } from 'n8n-design-system/utils';
import Modal from './Modal.vue';
import { CHAT_EMBED_MODAL_KEY, CHAT_TRIGGER_NODE_TYPE, WEBHOOK_NODE_TYPE } from '../constants';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import HtmlEditor from '@/components/HtmlEditor/HtmlEditor.vue';
import JsEditor from '@/components/JsEditor/JsEditor.vue';
Expand Down Expand Up @@ -68,7 +68,7 @@ const webhookNode = computed(() => {
});
const webhookUrl = computed(() => {
const url = `${rootStore.getWebhookUrl}${
const url = `${rootStore.webhookUrl}${
webhookNode.value ? `/${webhookNode.value.node.webhookId}` : ''
}`;
Expand Down
12 changes: 7 additions & 5 deletions packages/editor-ui/src/components/CodeNodeEditor/AskAI/AskAI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useMessage } from '@/composables/useMessage';
import { useToast } from '@/composables/useToast';
import { useNDVStore } from '@/stores/ndv.store';
import { usePostHog } from '@/stores/posthog.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { executionDataToJson } from '@/utils/nodeTypesUtils';
import {
Expand Down Expand Up @@ -131,7 +131,7 @@ function stopLoading() {
}
async function onSubmit() {
const { getRestApiContext } = useRootStore();
const { restApiContext } = useRootStore();
const { activeNode } = useNDVStore();
const { showMessage } = useToast();
const { alert } = useMessage();
Expand All @@ -153,20 +153,22 @@ async function onSubmit() {
startLoading();
const rootStore = useRootStore();
try {
const version = useRootStore().versionCli;
const version = rootStore.versionCli;
const model =
usePostHog().getVariant(ASK_AI_EXPERIMENT.name) === ASK_AI_EXPERIMENT.gpt4
? 'gpt-4'
: 'gpt-3.5-turbo-16k';
const { code } = await generateCodeForPrompt(getRestApiContext, {
const { code } = await generateCodeForPrompt(restApiContext, {
question: prompt.value,
context: {
schema: schemas.parentNodesSchemas,
inputSchema: schemas.inputSchema!,
ndvPushRef: useNDVStore().pushRef,
pushRef: useRootStore().pushRef,
pushRef: rootStore.pushRef,
},
model,
n8nVersion: version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { CODE_EXECUTION_MODES, CODE_LANGUAGES } from 'n8n-workflow';
import { ASK_AI_EXPERIMENT, CODE_NODE_TYPE } from '@/constants';
import { codeNodeEditorEventBus } from '@/event-bus';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { usePostHog } from '@/stores/posthog.store';
import { readOnlyEditorExtensions, writableEditorExtensions } from './baseExtensions';
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/ContactPromptModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import type { IN8nPromptResponse, ModalKey } from '@/Interface';
import { VALID_EMAIL_REGEX } from '@/constants';
import Modal from '@/components/Modal.vue';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { createEventBus } from 'n8n-design-system/utils';
import { useToast } from '@/composables/useToast';
import { useNpsSurveyStore } from '@/stores/npsSurvey.store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ import type { PermissionsMap } from '@/permissions';
import type { CredentialScope } from '@n8n/permissions';
import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useNDVStore } from '@/stores/ndv.store';
import { useCredentialsStore } from '@/stores/credentials.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
Expand Down Expand Up @@ -338,7 +338,7 @@ export default defineComponent({
this.credentialTypeName === 'oAuth2Api' || this.parentTypes.includes('oAuth2Api')
? 'oauth2'
: 'oauth1';
return this.rootStore.oauthCallbackUrls[oauthType as keyof {}];
return this.rootStore.OAuthCallbackUrls[oauthType as keyof {}];
},
showOAuthSuccessBanner(): boolean {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<script lang="ts" setup>
import { useUIStore } from '@/stores/ui.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
const { baseUrl } = useRootStore();
const type = useUIStore().appliedTheme === 'dark' ? '.dark.png' : '.png';
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/components/CredentialIcon.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue';
import { useCredentialsStore } from '@/stores/credentials.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import type { ICredentialType } from 'n8n-workflow';
import NodeIcon from '@/components/NodeIcon.vue';
Expand All @@ -26,7 +26,7 @@ const filePath = computed(() => {
return null;
}
return rootStore.getBaseUrl + themeIconUrl;
return rootStore.baseUrl + themeIconUrl;
});
const relevantNode = computed(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/Error/NodeErrorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useClipboard } from '@/composables/useClipboard';
import { useToast } from '@/composables/useToast';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useNDVStore } from '@/stores/ndv.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import type {
IDataObject,
INodeProperties,
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/FeatureComingSoon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import type { IFakeDoor } from '@/Interface';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useUIStore } from '@/stores/ui.store';
import { useUsersStore } from '@/stores/users.store';
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/components/HoverableNodeIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { type StyleValue, defineComponent, type PropType } from 'vue';
import type { ITemplatesNode } from '@/Interface';
import type { INodeTypeDescription } from 'n8n-workflow';
import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
interface NodeIconData {
type: string;
Expand Down Expand Up @@ -124,7 +124,7 @@ export default defineComponent({
return (nodeType as ITemplatesNode).iconData;
}
const restUrl = this.rootStore.getRestUrl;
const restUrl = this.rootStore.restUrl;
if (typeof nodeType.icon === 'string') {
const [type, path] = nodeType.icon.split(':');
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/Logo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useUIStore } from '@/stores/ui.store';
export default defineComponent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import InlineTextEdit from '@/components/InlineTextEdit.vue';
import BreakpointsObserver from '@/components/BreakpointsObserver.vue';
import CollaborationPane from '@/components/MainHeader/CollaborationPane.vue';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useTagsStore } from '@/stores/tags.store';
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/MainSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import { useUserHelpers } from '@/composables/useUserHelpers';
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useUIStore } from '@/stores/ui.store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@/constants';
import type { BaseTextKey } from '@/plugins/i18n';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useNodeCreatorStore } from '@/stores/nodeCreator.store';
import { TriggerView, RegularView, AIView, AINodesView } from '../viewsData';
Expand Down
6 changes: 3 additions & 3 deletions packages/editor-ui/src/components/NodeIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<script setup lang="ts">
import type { IVersionNode, SimplifiedNodeType } from '@/Interface';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useUIStore } from '@/stores/ui.store';
import {
getBadgeIconUrl,
Expand Down Expand Up @@ -84,7 +84,7 @@ const color = computed(() => getNodeIconColor(props.nodeType) ?? props.colorDefa
const iconSource = computed<NodeIconSource>(() => {
const nodeType = props.nodeType;
const baseUrl = rootStore.getBaseUrl;
const baseUrl = rootStore.baseUrl;
if (nodeType) {
// If node type has icon data, use it
Expand Down Expand Up @@ -122,7 +122,7 @@ const badge = computed(() => {
if (nodeType && 'badgeIconUrl' in nodeType && nodeType.badgeIconUrl) {
return {
type: 'file',
src: rootStore.getBaseUrl + getBadgeIconUrl(nodeType, uiStore.appliedTheme),
src: rootStore.baseUrl + getBadgeIconUrl(nodeType, uiStore.appliedTheme),
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/NpsSurvey.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { VALID_EMAIL_REGEX, NPS_SURVEY_MODAL_KEY } from '@/constants';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import ModalDrawer from '@/components/ModalDrawer.vue';
import { useToast } from '@/composables/useToast';
import { useI18n } from '@/composables/useI18n';
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/PersonalizationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ import { getAccountAge } from '@/utils/userUtils';
import type { GenericValue } from 'n8n-workflow';
import { useUIStore } from '@/stores/ui.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useUsersStore } from '@/stores/users.store';
import { createEventBus } from 'n8n-design-system/utils';
import { usePostHog } from '@/stores/posthog.store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
export default defineComponent({
name: 'PushConnectionTracker',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ import type { DynamicNodeParameters, IResourceLocatorResultExpanded } from '@/In
import DraggableTarget from '@/components/DraggableTarget.vue';
import ExpressionParameterInput from '@/components/ExpressionParameterInput.vue';
import ParameterIssues from '@/components/ParameterIssues.vue';
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 { useUIStore } from '@/stores/ui.store';
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/RunData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ import { useToast } from '@/composables/useToast';
import { isEqual, isObject } from 'lodash-es';
import { useExternalHooks } from '@/composables/useExternalHooks';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import RunDataPinButton from '@/components/RunDataPinButton.vue';
const RunDataTable = defineAsyncComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ import EventSelection from '@/components/SettingsLogStreaming/EventSelection.ee.
import type { EventBus } from 'n8n-design-system';
import { createEventBus } from 'n8n-design-system/utils';
import { useTelemetry } from '@/composables/useTelemetry';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
export default defineComponent({
name: 'EventDestinationSettingsModal',
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/SettingsSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type { IMenuItem } from 'n8n-design-system';
import type { BaseTextKey } from '@/plugins/i18n';
import { useUIStore } from '@/stores/ui.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { hasPermission } from '@/utils/rbac/permissions';
import { useRoute, useRouter } from 'vue-router';
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/Telemetry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useUsersStore } from '@/stores/users.store';
import type { ITelemetrySettings } from 'n8n-workflow';
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/TimeAgo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { format, register } from 'timeago.js';
import { convertToHumanReadableDate } from '@/utils/typesUtils';
import { computed, onBeforeMount } from 'vue';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useI18n } from '@/composables/useI18n';
type Props = {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/VariableSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import VariableSelectorItem from '@/components/VariableSelectorItem.vue';
import type { INodeUi, IVariableItemSelected, IVariableSelectorOption } from '@/Interface';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useNDVStore } from '@/stores/ndv.store';
import { useRouter } from 'vue-router';
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/WorkerList.ee.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import WorkerCard from './Workers/WorkerCard.ee.vue';
import { usePushConnection } from '@/composables/usePushConnection';
import { useRouter } from 'vue-router';
import { usePushConnectionStore } from '@/stores/pushConnection.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
// eslint-disable-next-line import/no-default-export
export default defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/WorkflowSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ import type { WorkflowSettings } from 'n8n-workflow';
import { deepCopy } from 'n8n-workflow';
import { useSettingsStore } from '@/stores/settings.store';
import { useUsersStore } from '@/stores/users.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useRootStore } from '@/stores/root.store';
import { useWorkflowsEEStore } from '@/stores/workflows.ee.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { createEventBus } from 'n8n-design-system/utils';
Expand Down
Loading

0 comments on commit 2ce9aa4

Please sign in to comment.