Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(editor): Migrate part of the vuex store to pinia #4484

Merged
merged 44 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3bbd378
✨ Added pinia support. Migrated community nodes module.
MiloradFilipovic Oct 25, 2022
9395b23
✨ Added ui pinia store, moved some data from root store to it, update…
MiloradFilipovic Oct 25, 2022
10bb3bc
✨ Added ui pinia store and migrated a part of the root store
MiloradFilipovic Oct 25, 2022
360545d
✨ Migrated `settings` store to pinia
MiloradFilipovic Oct 26, 2022
221d1c6
✨ Removing vuex store refs from router
MiloradFilipovic Oct 26, 2022
55973de
✨ Migrated `users` module to pinia store
MiloradFilipovic Oct 26, 2022
a10201a
Merge branch 'master' into N8N-5190-pinia-migration-part1
MiloradFilipovic Oct 27, 2022
cd6467d
⚡ Fixing errors after sync with master
MiloradFilipovic Oct 27, 2022
2cd5495
⚡ One more error after merge
MiloradFilipovic Oct 27, 2022
363988d
⚡ Created `workflows` pinia store. Moved large part of root store to …
MiloradFilipovic Oct 27, 2022
a1c9bf7
✨ Finished migrating workflows store to pinia
MiloradFilipovic Oct 28, 2022
d591bcd
⚡ Renaming some getters and actions to make more sense
MiloradFilipovic Oct 28, 2022
c31ada6
✨ Finished migrating the root store to pinia
MiloradFilipovic Oct 28, 2022
81777b8
✨ Migrated ndv store to pinia
MiloradFilipovic Oct 28, 2022
d98b75d
⚡ Renaming main panel dimensions getter so it doesn't clash with data…
MiloradFilipovic Oct 28, 2022
a1b3bc1
Merge branch 'feature/pinia-migration' into N8N-5190-pinia-migration-…
MiloradFilipovic Oct 28, 2022
b3a5c45
✔️ Fixing lint errors
MiloradFilipovic Oct 29, 2022
b023241
✨ Migrated `templates` store to pinia
MiloradFilipovic Oct 29, 2022
f221754
✨ Migrated the `nodeTypes`store
MiloradFilipovic Oct 30, 2022
8d12931
⚡ Removed unused pieces of code and oold vuex modules
MiloradFilipovic Oct 31, 2022
f133559
✨ Adding vuex calls to pinia store, fi xing wrong references
MiloradFilipovic Oct 31, 2022
373d187
💄 Removing leftover $store refs
MiloradFilipovic Oct 31, 2022
6ac0691
⚡ Added legacy getters and mutations to store to support webhooks
MiloradFilipovic Oct 31, 2022
0abaeca
⚡ Added missing front-end hooks, updated vuex state subscriptions to …
MiloradFilipovic Oct 31, 2022
38a6fbb
✔️ Fixing linting errors
MiloradFilipovic Oct 31, 2022
5091160
Merge branch 'feature/pinia-migration' into N8N-5190-pinia-migration-…
MiloradFilipovic Oct 31, 2022
7019ce3
Removing vue composition api plugin
MiloradFilipovic Oct 31, 2022
4ff2159
⚡ Fixing main sidebar state when loading node view
MiloradFilipovic Nov 2, 2022
557a2d3
🐛 Fixing an error when activating workflows
MiloradFilipovic Nov 2, 2022
b7931a3
🐛 Fixing isses with workflow settings and executions auto-refresh
MiloradFilipovic Nov 2, 2022
e5d14bd
🐛 Removing duplicate listeners which cause import error
MiloradFilipovic Nov 2, 2022
af43749
🐛 Fixing route authentication
MiloradFilipovic Nov 2, 2022
53674f6
Merge branch 'master' into N8N-5190-pinia-migration-part1
MiloradFilipovic Nov 2, 2022
c943775
⚡ Updating freshly pulled $store refs
MiloradFilipovic Nov 2, 2022
d03c492
Adding deleted const
MiloradFilipovic Nov 2, 2022
e7c61b1
⚡ Updating store references in ee features. Reseting NodeView credent…
MiloradFilipovic Nov 2, 2022
3b0cc8b
⚡ Adding return type to email submission modal
MiloradFilipovic Nov 2, 2022
1829c1e
⚡ Making NodeView only react to paste event when active
MiloradFilipovic Nov 2, 2022
3a57695
🐛 Fixing signup view errors
MiloradFilipovic Nov 2, 2022
52aa20d
👌 Addressing PR review comments
MiloradFilipovic Nov 2, 2022
7cb7fa3
Merge branch 'master' into N8N-5190-pinia-migration-part1
MiloradFilipovic Nov 4, 2022
f24f498
👌 Addressing new PR comments
MiloradFilipovic Nov 4, 2022
b61f7f6
Merge branch 'master' into N8N-5190-pinia-migration-part1
MiloradFilipovic Nov 4, 2022
8619610
👌 Updating invite id logic in signup view
MiloradFilipovic Nov 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/editor-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"n8n-design-system": "~0.40.0",
"n8n-workflow": "~0.122.1",
"normalize-wheel": "^1.0.1",
"pinia": "^2.0.22",
"prismjs": "^1.17.1",
"quill": "2.0.0-dev.4",
"quill-autoformat": "^0.1.1",
Expand Down
55 changes: 33 additions & 22 deletions packages/editor-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
id="app"
:class="{
[$style.container]: true,
[$style.sidebarCollapsed]: sidebarMenuCollapsed
[$style.sidebarCollapsed]: uiStore.sidebarMenuCollapsed
}"
>
<div id="header" :class="$style.header">
Expand Down Expand Up @@ -35,11 +35,17 @@ import { HIRING_BANNER, LOCAL_STORAGE_THEME, VIEWS } from './constants';
import mixins from 'vue-typed-mixins';
import { showMessage } from './components/mixins/showMessage';
import { IUser } from './Interface';
import { mapGetters } from 'vuex';
import { userHelpers } from './components/mixins/userHelpers';
import { loadLanguage } from './plugins/i18n';
import { restApi } from '@/components/mixins/restApi';
import { globalLinkActions } from '@/components/mixins/globalLinkActions';
import { mapStores } from 'pinia';
import { useUIStore } from './stores/ui';
import { useSettingsStore } from './stores/settings';
import { useUsersStore } from './stores/users';
import { useRootStore } from './stores/n8nRootStore';
import { useTemplatesStore } from './stores/templates';
import { useNodeTypesStore } from './stores/nodeTypes';

export default mixins(
showMessage,
Expand All @@ -54,11 +60,16 @@ export default mixins(
Modals,
},
computed: {
...mapGetters('settings', ['isHiringBannerEnabled', 'isTemplatesEnabled', 'isTemplatesEndpointReachable', 'isUserManagementEnabled', 'showSetupPage']),
...mapGetters('users', ['currentUser']),
...mapGetters('ui', ['sidebarMenuCollapsed']),
...mapStores(
useNodeTypesStore,
useRootStore,
useSettingsStore,
useTemplatesStore,
useUIStore,
useUsersStore,
),
defaultLocale (): string {
return this.$store.getters.defaultLocale;
return this.rootStore.defaultLocale;
},
},
data() {
Expand All @@ -69,7 +80,7 @@ export default mixins(
methods: {
async initSettings(): Promise<void> {
try {
await this.$store.dispatch('settings/getSettings');
await this.settingsStore.getSettings();
} catch (e) {
this.$showToast({
title: this.$locale.baseText('startupError'),
Expand All @@ -81,44 +92,43 @@ export default mixins(
throw e;
}
},
async loginWithCookie(): Promise<void> {
loginWithCookie(): void {
try {
await this.$store.dispatch('users/loginWithCookie');
this.usersStore.loginWithCookie();
} catch (e) {}
},
async initTemplates(): Promise<void> {
if (!this.isTemplatesEnabled) {
if (!this.settingsStore.isTemplatesEnabled) {
return;
}

try {
await this.$store.dispatch('settings/testTemplatesEndpoint');
} catch (e) {
await this.settingsStore.testTemplatesEndpoint();
} catch (e) {
}
},
logHiringBanner() {
if (this.isHiringBannerEnabled && this.$route.name !== VIEWS.DEMO) {
if (this.settingsStore.isHiringBannerEnabled && this.$route.name !== VIEWS.DEMO) {
console.log(HIRING_BANNER); // eslint-disable-line no-console
}
},
async initialize(): Promise<void> {
await this.initSettings();
await Promise.all([this.loginWithCookie(), this.initTemplates()]);
},
trackPage() {
this.$store.commit('ui/setCurrentView', this.$route.name);
trackPage(): void {
this.uiStore.currentView = this.$route.name || '';
if (this.$route && this.$route.meta && this.$route.meta.templatesEnabled) {
this.$store.commit('templates/setSessionId');
this.templatesStore.setSessionId();
}
else {
this.$store.commit('templates/resetSessionId'); // reset telemetry session id when user leaves template pages
this.templatesStore.resetSessionId(); // reset telemetry session id when user leaves template pages
}

this.$telemetry.page(this.$route);
},
authenticate() {
// redirect to setup page. user should be redirected to this only once
if (this.isUserManagementEnabled && this.showSetupPage) {
if (this.settingsStore.isUserManagementEnabled && this.settingsStore.showSetupPage) {
if (this.$route.name === VIEWS.SETUP) {
return;
}
Expand All @@ -132,7 +142,7 @@ export default mixins(
}

// if cannot access page and not logged in, ask to sign in
const user = this.currentUser as IUser | null;
const user = this.usersStore.currentUser as IUser | null;
if (!user) {
const redirect =
this.$route.query.redirect ||
Expand All @@ -154,7 +164,7 @@ export default mixins(
this.$router.replace({ name: VIEWS.HOMEPAGE });
},
redirectIfNecessary() {
const redirect = this.$route.meta && typeof this.$route.meta.getRedirect === 'function' && this.$route.meta.getRedirect(this.$store);
const redirect = this.$route.meta && typeof this.$route.meta.getRedirect === 'function' && this.$route.meta.getRedirect();
if (redirect) {
this.$router.replace(redirect);
}
Expand All @@ -176,10 +186,11 @@ export default mixins(
this.loading = false;

this.trackPage();
// TODO: Un-comment once front-end hooks are updated to work with pinia store
this.$externalHooks().run('app.mount');

if (this.defaultLocale !== 'en') {
void this.$store.dispatch('nodeTypes/getNodeTranslationHeaders');
await this.nodeTypesStore.getNodeTranslationHeaders();
}
},
watch: {
Expand Down
102 changes: 94 additions & 8 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IMenuItem } from 'n8n-design-system';
import {
jsPlumbInstance,
DragOptions,
Expand Down Expand Up @@ -168,6 +169,7 @@ export interface INodeUpdatePropertiesInformation {
export type XYPosition = [number, number];

export interface INodeUi extends INode {
[x: string]: unknown;
mutdmour marked this conversation as resolved.
Show resolved Hide resolved
position: XYPosition;
color?: string;
notes?: string;
Expand Down Expand Up @@ -887,6 +889,47 @@ export interface INodeMetadata {
parametersLastUpdatedAt?: number;
}

export interface WorkflowsState {
activeExecutions: IExecutionsCurrentSummaryExtended[];
activeWorkflows: string[];
activeWorkflowExecution: IExecutionsSummary | null;
currentWorkflowExecutions: IExecutionsSummary[];
activeExecutionId: string | null;
executingNode: string | null;
executionWaitingForWebhook: boolean;
finishedExecutionsCount: number;
nodeMetadata: NodeMetadataMap;
subWorkflowExecutionError: Error | null;
workflow: IWorkflowDb;
workflowExecutionData: IExecutionResponse | null;
workflowExecutionPairedItemMappings: {[itemId: string]: Set<string>};
workflowsById: IWorkflowsMap;
}

export interface RootState {
baseUrl: string;
defaultLocale: string;
endpointWebhook: string;
endpointWebhookTest: string;
pushConnectionActive: boolean;
timezone: string;
executionTimeout: number;
maxExecutionTimeout: number;
versionCli: string;
oauthCallbackUrls: object;
n8nMetadata: {
[key: string]: string | number | undefined;
};
sessionId: string;
urlBaseWebhook: string;
urlBaseEditor: string;
instanceId: string;
isNpmAvailable: boolean;
}

export interface NodeMetadataMap {
[nodeName: string]: INodeMetadata;
}
export interface IRootState {
activeExecutions: IExecutionsCurrentSummaryExtended[];
activeWorkflows: string[];
Expand Down Expand Up @@ -924,12 +967,12 @@ export interface IRootState {
workflowsById: IWorkflowsMap;
sidebarMenuItems: IMenuItem[];
instanceId: string;
nodeMetadata: {[nodeName: string]: INodeMetadata};
nodeMetadata: NodeMetadataMap;
isNpmAvailable: boolean;
subworkflowExecutionError: Error | null;
}

export interface ICommunityPackageMap {
export interface CommunityPackageMap {
[name: string]: PublicInstalledPackage;
}

Expand Down Expand Up @@ -1023,6 +1066,37 @@ export interface IUiState {
executionSidebarAutoRefresh: boolean;
}

export interface UIState {
activeActions: string[];
activeCredentialType: string | null;
sidebarMenuCollapsed: boolean;
modalStack: string[];
modals: {
[key: string]: IModalState;
};
isPageLoading: boolean;
currentView: string;
mainPanelPosition: number;
fakeDoorFeatures: IFakeDoor[];
draggable: {
isDragging: boolean;
type: string;
data: string;
canDrop: boolean;
stickyPosition: null | XYPosition;
};
stateIsDirty: boolean;
lastSelectedNode: string | null;
lastSelectedNodeOutputIndex: number | null;
nodeViewOffsetPosition: XYPosition;
nodeViewMoveInProgress: boolean;
selectedNodes: INodeUi[];
sidebarMenuItems: IMenuItem[];
nodeViewInitialized: boolean;
addFirstStepOnLoad: boolean;
executionSidebarAutoRefresh: boolean;
}

export type ILogLevel = 'info' | 'debug' | 'warn' | 'error' | 'verbose';

export type IFakeDoor = {
Expand Down Expand Up @@ -1059,6 +1133,9 @@ export interface ISettingsState {
path: string;
};
onboardingCallPromptEnabled: boolean;
saveDataErrorExecution: string;
saveDataSuccessExecution: string;
saveManualExecutions: boolean;
}

export interface INodeTypesState {
Expand Down Expand Up @@ -1109,11 +1186,9 @@ export interface IWorkflowsState {
[name: string]: IWorkflowDb;
}

export interface IWorkflowsState {}

export interface ICommunityNodesState {
export interface CommunityNodesState {
availablePackageCount: number;
installedPackages: ICommunityPackageMap;
installedPackages: CommunityPackageMap;
}

export interface IRestApiContext {
Expand Down Expand Up @@ -1149,8 +1224,8 @@ export interface IOnboardingCallPromptResponse {

export interface IOnboardingCallPrompt {
title: string;
body: string;
index: number;
description: string;
toast_sequence_number: number;
}

export interface ITab {
Expand Down Expand Up @@ -1182,3 +1257,14 @@ export interface IResourceLocatorReqParams {
export interface IResourceLocatorResultExpanded extends INodeListSearchItems {
linkAlt?: string;
}

export interface CurlToJSONResponse {
"parameters.url": string;
"parameters.authentication": string;
"parameters.method": string;
"parameters.sendHeaders": boolean;
"parameters.headerParameters.parameters.0.name": string;
"parameters.headerParameters.parameters.0.value": string;
"parameters.sendQuery": boolean;
"parameters.sendBody": boolean;
}
2 changes: 1 addition & 1 deletion packages/editor-ui/src/api/communityNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function uninstallPackage(context: IRestApiContext, name: string):
return await makeRestApiRequest(context, 'DELETE', '/nodes', { name });
}

export async function updatePackage(context: IRestApiContext, name: string): Promise<void> {
export async function updatePackage(context: IRestApiContext, name: string): Promise<PublicInstalledPackage> {
return await makeRestApiRequest(context, 'PATCH', '/nodes', { name });
}
4 changes: 2 additions & 2 deletions packages/editor-ui/src/api/curlHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IRestApiContext} from "@/Interface";
import {CurlToJSONResponse, IRestApiContext} from "@/Interface";
import {makeRestApiRequest} from "@/api/helpers";

export function getCurlToJson(context: IRestApiContext, curlCommand: string): Promise<{ curlCommand: string | null }> {
export function getCurlToJson(context: IRestApiContext, curlCommand: string): Promise<CurlToJSONResponse> {
return makeRestApiRequest(context, 'POST', '/curl-to-json', { curlCommand });
}
4 changes: 2 additions & 2 deletions packages/editor-ui/src/api/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IRestApiContext, IN8nPrompts, IN8nValueSurveyData, IN8nUISettings } from '../Interface';
import { IRestApiContext, IN8nPrompts, IN8nValueSurveyData, IN8nUISettings, IN8nPromptResponse } from '../Interface';
import { makeRestApiRequest, get, post } from './helpers';
import { N8N_IO_BASE_URL, NPM_COMMUNITY_NODE_SEARCH_API_URL } from '@/constants';

Expand All @@ -14,7 +14,7 @@ export async function submitContactInfo(instanceId: string, userId: string, emai
return await post(N8N_IO_BASE_URL, '/prompt', { email }, {'n8n-instance-id': instanceId, 'n8n-user-id': userId});
}

export async function submitValueSurvey(instanceId: string, userId: string, params: IN8nValueSurveyData): Promise<IN8nPrompts> {
export async function submitValueSurvey(instanceId: string, userId: string, params: IN8nValueSurveyData): Promise<IN8nPromptResponse> {
return await post(N8N_IO_BASE_URL, '/value-survey', params, {'n8n-instance-id': instanceId, 'n8n-user-id': userId});
}

Expand Down
6 changes: 3 additions & 3 deletions packages/editor-ui/src/api/workflow-webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IOnboardingCallPromptResponse, IUser } from "@/Interface";
import { IOnboardingCallPrompt, IOnboardingCallPromptResponse, IUser } from "@/Interface";
import { get, post } from "./helpers";

const N8N_API_BASE_URL = 'https://api.n8n.io/api';
const ONBOARDING_PROMPTS_ENDPOINT = '/prompts/onboarding';
const CONTACT_EMAIL_SUBMISSION_ENDPOINT = '/accounts/onboarding';

export async function fetchNextOnboardingPrompt(instanceId: string, currentUer: IUser): Promise<IOnboardingCallPromptResponse> {
export async function fetchNextOnboardingPrompt(instanceId: string, currentUer: IUser): Promise<IOnboardingCallPrompt> {
return await get(
N8N_API_BASE_URL,
ONBOARDING_PROMPTS_ENDPOINT,
Expand Down Expand Up @@ -35,7 +35,7 @@ export async function applyForOnboardingCall(instanceId: string, currentUer: IUs
}
}

export async function submitEmailOnSignup(instanceId: string, currentUer: IUser, email: string, agree: boolean): Promise<string> {
export async function submitEmailOnSignup(instanceId: string, currentUer: IUser, email: string | undefined, agree: boolean): Promise<string> {
return await post(
N8N_API_BASE_URL,
CONTACT_EMAIL_SUBMISSION_ENDPOINT,
Expand Down
Loading