feat(editor): Improve performance by importing routes dynamically and add route guards (no-changelog) (#7567)

**Before:**
<img width="657" alt="image"
src="https://github.com/n8n-io/n8n/assets/6179477/0bcced2b-9d3a-43b3-80d7-3c72619941fa">


**After:**
<img width="660" alt="image"
src="https://github.com/n8n-io/n8n/assets/6179477/e74e0bbf-bf33-49b4-ae11-65f640405ac8">
This commit is contained in:
Alex Grozav
2023-11-03 16:22:37 +02:00
committed by GitHub
parent c92402a3ca
commit 24dfc95974
21 changed files with 387 additions and 294 deletions

View File

@@ -31,9 +31,13 @@ import { useUIStore } from './ui.store';
import { useUsersStore } from './users.store';
import { useVersionsStore } from './versions.store';
import { makeRestApiRequest } from '@/utils';
import { useTitleChange, useToast } from '@/composables';
import { ExpressionEvaluatorProxy } from 'n8n-workflow';
import { i18n } from '@/plugins/i18n';
export const useSettingsStore = defineStore(STORES.SETTINGS, {
state: (): ISettingsState => ({
initialized: false,
settings: {} as IN8nUISettings,
promptsData: {} as IN8nPrompts,
userManagement: {
@@ -69,7 +73,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, {
}),
getters: {
isEnterpriseFeatureEnabled() {
return (feature: EnterpriseEditionFeature): boolean => this.settings.enterprise[feature];
return (feature: EnterpriseEditionFeature): boolean => this.settings.enterprise?.[feature];
},
versionCli(): string {
return this.settings.versionCli;
@@ -190,6 +194,33 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, {
},
},
actions: {
async initialize() {
if (this.initialized) {
return;
}
const { showToast } = useToast();
try {
await this.getSettings();
ExpressionEvaluatorProxy.setEvaluator(this.settings.expressions.evaluator);
// Re-compute title since settings are now available
useTitleChange().titleReset();
this.initialized = true;
} catch (e) {
showToast({
title: i18n.baseText('startupError'),
message: i18n.baseText('startupError.message'),
type: 'error',
duration: 0,
dangerouslyUseHTMLString: true,
});
throw e;
}
},
setSettings(settings: IN8nUISettings): void {
this.settings = settings;
this.userManagement = settings.userManagement;

View File

@@ -52,6 +52,7 @@ const isInstanceOwner = (user: IUserResponse | null) =>
export const useUsersStore = defineStore(STORES.USERS, {
state: (): IUsersState => ({
initialized: false,
currentUserId: null,
users: {},
currentUserCloudInfo: null,
@@ -122,6 +123,16 @@ export const useUsersStore = defineStore(STORES.USERS, {
},
},
actions: {
async initialize() {
if (this.initialized) {
return;
}
try {
await this.loginWithCookie();
this.initialized = true;
} catch (e) {}
},
addUsers(users: IUserResponse[]) {
users.forEach((userResponse: IUserResponse) => {
const prevUser = this.users[userResponse.id] || {};