refactor(editor): Finish pinia migration, remove all vuex dependancies (#4533)
* ✨ Added pinia support. Migrated community nodes module. * ✨ Added ui pinia store, moved some data from root store to it, updated modals to work with pinia stores * ✨ Added ui pinia store and migrated a part of the root store * ✨ Migrated `settings` store to pinia * ✨ Removing vuex store refs from router * ✨ Migrated `users` module to pinia store * ⚡ Fixing errors after sync with master * ⚡ One more error after merge * ⚡ Created `workflows` pinia store. Moved large part of root store to it. Started updating references. * ✨ Finished migrating workflows store to pinia * ⚡ Renaming some getters and actions to make more sense * ✨ Finished migrating the root store to pinia * ✨ Migrated ndv store to pinia * ⚡ Renaming main panel dimensions getter so it doesn't clash with data prop name * ✔️ Fixing lint errors * ✨ Migrated `templates` store to pinia * ✨ Migrated the `nodeTypes`store * ⚡ Removed unused pieces of code and oold vuex modules * ✨ Adding vuex calls to pinia store, fixing wrong references * 💄 Removing leftover $store refs * ⚡ Added legacy getters and mutations to store to support webhooks * ⚡ Added missing front-end hooks, updated vuex state subscriptions to pinia * ✔️ Fixing linting errors * ⚡ Removing vue composition api plugin * ⚡ Fixing main sidebar state when loading node view * 🐛 Fixing an error when activating workflows * 🐛 Fixing isses with workflow settings and executions auto-refresh * 🐛 Removing duplicate listeners which cause import error * 🐛 Fixing route authentication * ⚡ Updating freshly pulled $store refs * ⚡ Adding deleted const * ⚡ Updating store references in ee features. Reseting NodeView credentials update flag when resetting workspace * ⚡ Adding return type to email submission modal * ⚡ Making NodeView only react to paste event when active * 🐛 Fixing signup view errors * ✨ Started migrating the `credentials` module to pinia * 👌 Addressing PR review comments * ✨ Migrated permissions module to pinia * ✨ Migrated `nodeCreator`, `tags` and `versions` modules to pinia * ✨ Implemented webhooks pinia store * ⚡ Removing all leftover vuex files and references * ✨ Removing final vuex refs * ⚡ Updating expected credentialId type * ⚡ Removing node credentials subscription code, reducing node click debounce timeout * 🐛 Fixing pushing nodes downstream when inserting new node * ✔️ Fixing a lint error in new type guard * ⚡ Updating helper reference * ✔️ Removing unnecessary awaits * ⚡ fix(editor): remove unnecessary imports from NDV * ⚡ Merging mapStores blocks in NodeView * ⚡ fix(editor): make sure JS Plumb not loaded earlier than needed * ⚡ Updating type guard nad credentials subscriptions * ⚡ Updating type guard so it doesn't use `any` type Co-authored-by: Csaba Tuncsik <csaba@n8n.io>
This commit is contained in:
committed by
GitHub
parent
825637f02a
commit
bae3098e4e
305
packages/editor-ui/src/stores/credentials.ts
Normal file
305
packages/editor-ui/src/stores/credentials.ts
Normal file
@@ -0,0 +1,305 @@
|
||||
import { createNewCredential, deleteCredential, getAllCredentials, getCredentialData, getCredentialsNewName, getCredentialTypes, getForeignCredentials, oAuth1CredentialAuthorize, oAuth2CredentialAuthorize, testCredential, updateCredential } from "@/api/credentials";
|
||||
import { setCredentialSharedWith } from "@/api/credentials.ee";
|
||||
import { getAppNameFromCredType } from "@/components/helpers";
|
||||
import { EnterpriseEditionFeature, STORES } from "@/constants";
|
||||
import { ICredentialMap, ICredentialsDecryptedResponse, ICredentialsResponse, ICredentialsState, ICredentialTypeMap } from "@/Interface";
|
||||
import { i18n } from "@/plugins/i18n";
|
||||
import { ICredentialsDecrypted, ICredentialType, INodeCredentialTestResult, INodeProperties, INodeTypeDescription, IUser } from "n8n-workflow";
|
||||
import { defineStore } from "pinia";
|
||||
import Vue from "vue";
|
||||
import { useRootStore } from "./n8nRootStore";
|
||||
import { useNodeTypesStore } from "./nodeTypes";
|
||||
import { useSettingsStore } from "./settings";
|
||||
import { useUsersStore } from "./users";
|
||||
|
||||
const DEFAULT_CREDENTIAL_NAME = 'Unnamed credential';
|
||||
const DEFAULT_CREDENTIAL_POSTFIX = 'account';
|
||||
const TYPES_WITH_DEFAULT_NAME = ['httpBasicAuth', 'oAuth2Api', 'httpDigestAuth', 'oAuth1Api'];
|
||||
|
||||
export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
|
||||
state: (): ICredentialsState => ({
|
||||
credentialTypes: {},
|
||||
credentials: {},
|
||||
}),
|
||||
getters: {
|
||||
credentialTypesById(): Record<ICredentialType['name'], ICredentialType> {
|
||||
return this.credentialTypes;
|
||||
},
|
||||
allCredentialTypes(): ICredentialType[] {
|
||||
return Object.values(this.credentialTypes)
|
||||
.sort((a, b) => a.displayName.localeCompare(b.displayName));
|
||||
},
|
||||
allCredentials(): ICredentialsResponse[] {
|
||||
return Object.values(this.credentials)
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
},
|
||||
allForeignCredentials(): ICredentialsResponse[] {
|
||||
return Object.values(this.foreignCredentials || {})
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
},
|
||||
allCredentialsByType(): {[type: string]: ICredentialsResponse[]} {
|
||||
const credentials = this.allCredentials;
|
||||
const types = this.allCredentialTypes;
|
||||
|
||||
return types.reduce((accu: {[type: string]: ICredentialsResponse[]}, type: ICredentialType) => {
|
||||
accu[type.name] = credentials.filter((cred: ICredentialsResponse) => cred.type === type.name);
|
||||
|
||||
return accu;
|
||||
}, {});
|
||||
},
|
||||
getCredentialTypeByName() {
|
||||
return (type: string): ICredentialType => this.credentialTypes[type];
|
||||
},
|
||||
getCredentialById() {
|
||||
return (id: string): ICredentialsResponse => this.credentials[id];
|
||||
},
|
||||
getCredentialByIdAndType() {
|
||||
return (id: string, type: string): ICredentialsResponse | undefined => {
|
||||
const credential = this.credentials[id];
|
||||
return !credential || credential.type !== type ? undefined : credential;
|
||||
};
|
||||
},
|
||||
getCredentialsByType() {
|
||||
return (credentialType: string): ICredentialsResponse[] => {
|
||||
return (this.allCredentialsByType[credentialType] || []);
|
||||
};
|
||||
},
|
||||
getNodesWithAccess() {
|
||||
return (credentialTypeName: string) => {
|
||||
const nodeTypesStore = useNodeTypesStore();
|
||||
const allLatestNodeTypes: INodeTypeDescription[] = nodeTypesStore.allLatestNodeTypes;
|
||||
|
||||
return allLatestNodeTypes.filter((nodeType: INodeTypeDescription) => {
|
||||
if (!nodeType.credentials) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const credentialTypeDescription of nodeType.credentials) {
|
||||
if (credentialTypeDescription.name === credentialTypeName ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
};
|
||||
},
|
||||
getScopesByCredentialType() {
|
||||
return (credentialTypeName: string) => {
|
||||
const credentialType = this.getCredentialTypeByName(credentialTypeName) as {
|
||||
properties: INodeProperties[];
|
||||
};
|
||||
|
||||
const scopeProperty = credentialType.properties.find((p) => p.name === 'scope');
|
||||
|
||||
if (
|
||||
!scopeProperty ||
|
||||
!scopeProperty.default ||
|
||||
typeof scopeProperty.default !== 'string' ||
|
||||
scopeProperty.default === ''
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let { default: scopeDefault } = scopeProperty;
|
||||
|
||||
// disregard expressions for display
|
||||
scopeDefault = scopeDefault.replace(/^=/, '').replace(/\{\{.*\}\}/, '');
|
||||
|
||||
if (/ /.test(scopeDefault)) return scopeDefault.split(' ');
|
||||
|
||||
if (/,/.test(scopeDefault)) return scopeDefault.split(',');
|
||||
|
||||
return [scopeDefault];
|
||||
};
|
||||
},
|
||||
getCredentialOwnerName() {
|
||||
return (credentialId: string): string => {
|
||||
const credential = this.getCredentialById(credentialId);
|
||||
return credential && credential.ownedBy && credential.ownedBy.firstName
|
||||
? `${credential.ownedBy.firstName} ${credential.ownedBy.lastName} (${credential.ownedBy.email})`
|
||||
: i18n.baseText('credentialEdit.credentialSharing.info.sharee.fallback');
|
||||
};
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setCredentialTypes(credentialTypes: ICredentialType[]): void {
|
||||
this.credentialTypes = credentialTypes.reduce((accu: ICredentialTypeMap, cred: ICredentialType) => {
|
||||
accu[cred.name] = cred;
|
||||
|
||||
return accu;
|
||||
}, {});
|
||||
},
|
||||
setCredentials(credentials: ICredentialsResponse[]): void {
|
||||
this.credentials = credentials.reduce((accu: ICredentialMap, cred: ICredentialsResponse) => {
|
||||
if (cred.id) {
|
||||
accu[cred.id] = cred;
|
||||
}
|
||||
return accu;
|
||||
}, {});
|
||||
},
|
||||
setForeignCredentials(credentials: ICredentialsResponse[]): void {
|
||||
this.foreignCredentials = credentials.reduce((accu: ICredentialMap, cred: ICredentialsResponse) => {
|
||||
if (cred.id) {
|
||||
accu[cred.id] = cred;
|
||||
}
|
||||
return accu;
|
||||
}, {});
|
||||
},
|
||||
upsertCredential(credential: ICredentialsResponse): void {
|
||||
if (credential.id) {
|
||||
Vue.set(this.credentials, credential.id, { ...this.credentials[credential.id], ...credential });
|
||||
}
|
||||
},
|
||||
enableOAuthCredential(credential: ICredentialsResponse): void {
|
||||
// enable oauth event to track change between modals
|
||||
},
|
||||
async fetchCredentialTypes(forceFetch: boolean): Promise<void> {
|
||||
if (this.allCredentialTypes.length > 0 && forceFetch !== true) {
|
||||
return;
|
||||
}
|
||||
const rootStore = useRootStore();
|
||||
const credentialTypes = await getCredentialTypes(rootStore.getRestApiContext);
|
||||
this.setCredentialTypes(credentialTypes);
|
||||
},
|
||||
async fetchAllCredentials(): Promise<ICredentialsResponse[]> {
|
||||
const rootStore = useRootStore();
|
||||
const credentials = await getAllCredentials(rootStore.getRestApiContext);
|
||||
this.setCredentials(credentials);
|
||||
return credentials;
|
||||
},
|
||||
async fetchForeignCredentials(): Promise<ICredentialsResponse[]> {
|
||||
const rootStore = useRootStore();
|
||||
const credentials = await getForeignCredentials(rootStore.getRestApiContext);
|
||||
this.setForeignCredentials(credentials);
|
||||
return credentials;
|
||||
},
|
||||
async getCredentialData({ id }: {id: string}): Promise<ICredentialsResponse | ICredentialsDecryptedResponse | undefined> {
|
||||
const rootStore = useRootStore();
|
||||
return await getCredentialData(rootStore.getRestApiContext, id);
|
||||
},
|
||||
async createNewCredential(data: ICredentialsDecrypted): Promise<ICredentialsResponse> {
|
||||
const rootStore = useRootStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const credential = await createNewCredential(rootStore.getRestApiContext, data);
|
||||
|
||||
if (settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
|
||||
this.upsertCredential(credential);
|
||||
|
||||
if (data.ownedBy) {
|
||||
this.setCredentialOwnedBy({
|
||||
credentialId: credential.id,
|
||||
ownedBy: data.ownedBy,
|
||||
});
|
||||
|
||||
const usersStore = useUsersStore();
|
||||
if (data.sharedWith && data.ownedBy.id === usersStore.currentUserId) {
|
||||
this.setCredentialSharedWith({
|
||||
credentialId: credential.id,
|
||||
sharedWith: data.sharedWith,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.upsertCredential(credential);
|
||||
}
|
||||
return credential;
|
||||
},
|
||||
async updateCredential(params: {data: ICredentialsDecrypted, id: string}): Promise<ICredentialsResponse> {
|
||||
const { id, data } = params;
|
||||
const rootStore = useRootStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const credential = await updateCredential(rootStore.getRestApiContext, id, data);
|
||||
|
||||
if (settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
|
||||
this.upsertCredential(credential);
|
||||
|
||||
if (data.ownedBy) {
|
||||
this.setCredentialOwnedBy({
|
||||
credentialId: credential.id,
|
||||
ownedBy: data.ownedBy,
|
||||
});
|
||||
|
||||
const usersStore = useUsersStore();
|
||||
if (data.sharedWith && data.ownedBy.id === usersStore.currentUserId) {
|
||||
this.setCredentialSharedWith({
|
||||
credentialId: credential.id,
|
||||
sharedWith: data.sharedWith,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.upsertCredential(credential);
|
||||
}
|
||||
|
||||
return credential;
|
||||
},
|
||||
async deleteCredential({ id }: {id: string}): void {
|
||||
const rootStore = useRootStore();
|
||||
const deleted = await deleteCredential(rootStore.getRestApiContext, id);
|
||||
if (deleted) {
|
||||
Vue.delete(this.credentials, id);
|
||||
}
|
||||
},
|
||||
async oAuth2Authorize(data: ICredentialsResponse): Promise<string> {
|
||||
const rootStore = useRootStore();
|
||||
return oAuth2CredentialAuthorize(rootStore.getRestApiContext, data);
|
||||
},
|
||||
async oAuth1Authorize(data: ICredentialsResponse): Promise<string> {
|
||||
const rootStore = useRootStore();
|
||||
return oAuth1CredentialAuthorize(rootStore.getRestApiContext, data);
|
||||
},
|
||||
async testCredential(data: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
|
||||
const rootStore = useRootStore();
|
||||
return testCredential(rootStore.getRestApiContext, { credentials: data });
|
||||
},
|
||||
async getNewCredentialName(params: { credentialTypeName: string }): Promise<string> {
|
||||
try {
|
||||
const { credentialTypeName } = params;
|
||||
let newName = DEFAULT_CREDENTIAL_NAME;
|
||||
if (!TYPES_WITH_DEFAULT_NAME.includes(credentialTypeName)) {
|
||||
const { displayName } = this.getCredentialTypeByName(credentialTypeName);
|
||||
newName = getAppNameFromCredType(displayName);
|
||||
newName = newName.length > 0 ? `${newName} ${DEFAULT_CREDENTIAL_POSTFIX}` : DEFAULT_CREDENTIAL_NAME;
|
||||
}
|
||||
const rootStore = useRootStore();
|
||||
const res = await getCredentialsNewName(rootStore.getRestApiContext, newName);
|
||||
return res.name;
|
||||
} catch (e) {
|
||||
return DEFAULT_CREDENTIAL_NAME;
|
||||
}
|
||||
},
|
||||
|
||||
// Enterprise edition actions
|
||||
setCredentialOwnedBy(payload: { credentialId: string, ownedBy: Partial<IUser> }): void {
|
||||
Vue.set(this.credentials[payload.credentialId], 'ownedBy', payload.ownedBy);
|
||||
},
|
||||
async setCredentialSharedWith(payload: { sharedWith: IUser[]; credentialId: string; }): void {
|
||||
if(useSettingsStore().isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
|
||||
await setCredentialSharedWith(
|
||||
useRootStore().getRestApiContext,
|
||||
payload.credentialId,
|
||||
{
|
||||
shareWithIds: payload.sharedWith.map((sharee) => sharee.id),
|
||||
},
|
||||
);
|
||||
Vue.set(this.credentials[payload.credentialId], 'sharedWith', payload.sharedWith);
|
||||
}
|
||||
},
|
||||
addCredentialSharee(payload: { credentialId: string, sharee: Partial<IUser> }): void {
|
||||
Vue.set(
|
||||
this.credentials[payload.credentialId],
|
||||
'sharedWith',
|
||||
(this.credentials[payload.credentialId].sharedWith || []).concat([payload.sharee]),
|
||||
);
|
||||
},
|
||||
removeCredentialSharee(payload: { credentialId: string, sharee: Partial<IUser> }): void {
|
||||
Vue.set(
|
||||
this.credentials[payload.credentialId],
|
||||
'sharedWith',
|
||||
(this.credentials[payload.credentialId].sharedWith || [])
|
||||
.filter((sharee) => sharee.id !== payload.sharee.id),
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
12
packages/editor-ui/src/stores/nodeCreator.ts
Normal file
12
packages/editor-ui/src/stores/nodeCreator.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ALL_NODE_FILTER, STORES } from "@/constants";
|
||||
import { INodeCreatorState } from "@/Interface";
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
export const useNodeCreatorStore = defineStore(STORES.NODE_CREATOR, {
|
||||
state: (): INodeCreatorState => ({
|
||||
itemsFilter: '',
|
||||
showTabs: true,
|
||||
showScrim: false,
|
||||
selectedType: ALL_NODE_FILTER,
|
||||
}),
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
import { getNodeParameterOptions, getNodesInformation, getNodeTranslationHeaders, getNodeTypes, getResourceLocatorResults } from "@/api/nodeTypes";
|
||||
import { DEFAULT_NODETYPE_VERSION, STORES } from "@/constants";
|
||||
import { ICategoriesWithNodes, INodeCreateElement, INodeTypesState, IResourceLocatorReqParams } from "@/Interface";
|
||||
import { getCategoriesWithNodes, getCategorizedList } from "@/modules/nodeTypesHelpers";
|
||||
import { getCategoriesWithNodes, getCategorizedList } from "@/stores/nodeTypesHelpers";
|
||||
import { addHeaders, addNodeTranslation } from "@/plugins/i18n";
|
||||
import { store } from "@/store";
|
||||
import { omit } from "@/utils";
|
||||
import { ILoadOptions, INodeCredentials, INodeListSearchResult, INodeParameters, INodePropertyOptions, INodeTypeDescription, INodeTypeNameVersion } from 'n8n-workflow';
|
||||
import { defineStore } from "pinia";
|
||||
import Vue from "vue";
|
||||
import { useCredentialsStore } from "./credentials";
|
||||
import { useRootStore } from "./n8nRootStore";
|
||||
import { useUsersStore } from "./users";
|
||||
|
||||
@@ -115,8 +115,8 @@ export const useNodeTypesStore = defineStore(STORES.NODE_TYPES, {
|
||||
this.setNodeTypes(nodesInformation);
|
||||
},
|
||||
async getFullNodesProperties(nodesToBeFetched: INodeTypeNameVersion[]): Promise<void> {
|
||||
const vuexStore = store;
|
||||
vuexStore.dispatch('credentials/fetchCredentialTypes', true);
|
||||
const credentialsStore = useCredentialsStore();
|
||||
credentialsStore.fetchCredentialTypes(true);
|
||||
await this.getNodesInformation(nodesToBeFetched);
|
||||
},
|
||||
async getNodeTypes(): Promise<void> {
|
||||
|
||||
150
packages/editor-ui/src/stores/nodeTypesHelpers.ts
Normal file
150
packages/editor-ui/src/stores/nodeTypesHelpers.ts
Normal file
@@ -0,0 +1,150 @@
|
||||
import { CORE_NODES_CATEGORY, CUSTOM_NODES_CATEGORY, SUBCATEGORY_DESCRIPTIONS, UNCATEGORIZED_CATEGORY, UNCATEGORIZED_SUBCATEGORY, PERSONALIZED_CATEGORY } from '@/constants';
|
||||
import { INodeCreateElement, ICategoriesWithNodes } from '@/Interface';
|
||||
import { INodeTypeDescription } from 'n8n-workflow';
|
||||
|
||||
const addNodeToCategory = (accu: ICategoriesWithNodes, nodeType: INodeTypeDescription, category: string, subcategory: string) => {
|
||||
if (!accu[category]) {
|
||||
accu[category] = {};
|
||||
}
|
||||
if (!accu[category][subcategory]) {
|
||||
accu[category][subcategory] = {
|
||||
triggerCount: 0,
|
||||
regularCount: 0,
|
||||
nodes: [],
|
||||
};
|
||||
}
|
||||
const isTrigger = nodeType.group.includes('trigger');
|
||||
if (isTrigger) {
|
||||
accu[category][subcategory].triggerCount++;
|
||||
}
|
||||
if (!isTrigger) {
|
||||
accu[category][subcategory].regularCount++;
|
||||
}
|
||||
accu[category][subcategory].nodes.push({
|
||||
type: 'node',
|
||||
key: `${category}_${nodeType.name}`,
|
||||
category,
|
||||
properties: {
|
||||
nodeType,
|
||||
subcategory,
|
||||
},
|
||||
includedByTrigger: isTrigger,
|
||||
includedByRegular: !isTrigger,
|
||||
});
|
||||
};
|
||||
|
||||
export const getCategoriesWithNodes = (nodeTypes: INodeTypeDescription[], personalizedNodeTypes: string[]): ICategoriesWithNodes => {
|
||||
const sorted = [...nodeTypes].sort((a: INodeTypeDescription, b: INodeTypeDescription) => a.displayName > b.displayName? 1 : -1);
|
||||
return sorted.reduce(
|
||||
(accu: ICategoriesWithNodes, nodeType: INodeTypeDescription) => {
|
||||
if (personalizedNodeTypes.includes(nodeType.name)) {
|
||||
addNodeToCategory(accu, nodeType, PERSONALIZED_CATEGORY, UNCATEGORIZED_SUBCATEGORY);
|
||||
}
|
||||
|
||||
if (!nodeType.codex || !nodeType.codex.categories) {
|
||||
addNodeToCategory(accu, nodeType, UNCATEGORIZED_CATEGORY, UNCATEGORIZED_SUBCATEGORY);
|
||||
return accu;
|
||||
}
|
||||
|
||||
nodeType.codex.categories.forEach((_category: string) => {
|
||||
const category = _category.trim();
|
||||
const subcategories =
|
||||
nodeType.codex &&
|
||||
nodeType.codex.subcategories &&
|
||||
nodeType.codex.subcategories[category]
|
||||
? nodeType.codex.subcategories[category]
|
||||
: null;
|
||||
|
||||
if(subcategories === null || subcategories.length === 0) {
|
||||
addNodeToCategory(accu, nodeType, category, UNCATEGORIZED_SUBCATEGORY);
|
||||
return;
|
||||
}
|
||||
|
||||
subcategories.forEach(subcategory => {
|
||||
addNodeToCategory(accu, nodeType, category, subcategory);
|
||||
});
|
||||
|
||||
});
|
||||
return accu;
|
||||
},
|
||||
{},
|
||||
);
|
||||
};
|
||||
|
||||
const getCategories = (categoriesWithNodes: ICategoriesWithNodes): string[] => {
|
||||
const excludeFromSort = [CORE_NODES_CATEGORY, CUSTOM_NODES_CATEGORY, UNCATEGORIZED_CATEGORY, PERSONALIZED_CATEGORY];
|
||||
const categories = Object.keys(categoriesWithNodes);
|
||||
const sorted = categories.filter(
|
||||
(category: string) =>
|
||||
!excludeFromSort.includes(category),
|
||||
);
|
||||
sorted.sort();
|
||||
|
||||
return [CORE_NODES_CATEGORY, CUSTOM_NODES_CATEGORY, PERSONALIZED_CATEGORY, ...sorted, UNCATEGORIZED_CATEGORY];
|
||||
};
|
||||
|
||||
export const getCategorizedList = (categoriesWithNodes: ICategoriesWithNodes): INodeCreateElement[] => {
|
||||
const categories = getCategories(categoriesWithNodes);
|
||||
|
||||
return categories.reduce(
|
||||
(accu: INodeCreateElement[], category: string) => {
|
||||
if (!categoriesWithNodes[category]) {
|
||||
return accu;
|
||||
}
|
||||
|
||||
const categoryEl: INodeCreateElement = {
|
||||
type: 'category',
|
||||
key: category,
|
||||
category,
|
||||
properties: {
|
||||
expanded: false,
|
||||
},
|
||||
};
|
||||
|
||||
const subcategories = Object.keys(categoriesWithNodes[category]);
|
||||
if (subcategories.length === 1) {
|
||||
const subcategory = categoriesWithNodes[category][
|
||||
subcategories[0]
|
||||
];
|
||||
if (subcategory.triggerCount > 0) {
|
||||
categoryEl.includedByTrigger = subcategory.triggerCount > 0;
|
||||
}
|
||||
if (subcategory.regularCount > 0) {
|
||||
categoryEl.includedByRegular = subcategory.regularCount > 0;
|
||||
}
|
||||
return [...accu, categoryEl, ...subcategory.nodes];
|
||||
}
|
||||
|
||||
subcategories.sort();
|
||||
const subcategorized = subcategories.reduce(
|
||||
(accu: INodeCreateElement[], subcategory: string) => {
|
||||
const subcategoryEl: INodeCreateElement = {
|
||||
type: 'subcategory',
|
||||
key: `${category}_${subcategory}`,
|
||||
category,
|
||||
properties: {
|
||||
subcategory,
|
||||
description: SUBCATEGORY_DESCRIPTIONS[category][subcategory],
|
||||
},
|
||||
includedByTrigger: categoriesWithNodes[category][subcategory].triggerCount > 0,
|
||||
includedByRegular: categoriesWithNodes[category][subcategory].regularCount > 0,
|
||||
};
|
||||
|
||||
if (subcategoryEl.includedByTrigger) {
|
||||
categoryEl.includedByTrigger = true;
|
||||
}
|
||||
if (subcategoryEl.includedByRegular) {
|
||||
categoryEl.includedByRegular = true;
|
||||
}
|
||||
|
||||
accu.push(subcategoryEl);
|
||||
return accu;
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return [...accu, categoryEl, ...subcategorized];
|
||||
},
|
||||
[],
|
||||
);
|
||||
};
|
||||
@@ -10,6 +10,7 @@ import Vue from "vue";
|
||||
import { useRootStore } from "./n8nRootStore";
|
||||
import { useUIStore } from "./ui";
|
||||
import { useUsersStore } from "./users";
|
||||
import { useVersionsStore } from "./versions";
|
||||
|
||||
export const useSettingsStore = defineStore(STORES.SETTINGS, {
|
||||
state: (): ISettingsState => ({
|
||||
@@ -129,7 +130,6 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, {
|
||||
async getSettings(): Promise<void> {
|
||||
const rootStore = useRootStore();
|
||||
const settings = await getSettings(rootStore.getRestApiContext);
|
||||
const vuexStore = store;
|
||||
|
||||
this.setSettings(settings);
|
||||
this.settings.communityNodesEnabled = settings.communityNodesEnabled;
|
||||
@@ -151,7 +151,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, {
|
||||
rootStore.setN8nMetadata(settings.n8nMetadata || {});
|
||||
rootStore.setDefaultLocale(settings.defaultLocale);
|
||||
rootStore.setIsNpmAvailable(settings.isNpmAvailable);
|
||||
vuexStore.commit('versions/setVersionNotificationSettings', settings.versionNotifications, {root: true});
|
||||
useVersionsStore().setVersionNotificationSettings(settings.versionNotifications);
|
||||
},
|
||||
stopShowingSetupPage(): void {
|
||||
Vue.set(this.userManagement, 'showSetupOnFirstLoad', false);
|
||||
|
||||
102
packages/editor-ui/src/stores/tags.ts
Normal file
102
packages/editor-ui/src/stores/tags.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { createTag, deleteTag, getTags, updateTag } from "@/api/tags";
|
||||
import { STORES } from "@/constants";
|
||||
import { ITag, ITagsState } from "@/Interface";
|
||||
import { defineStore } from "pinia";
|
||||
import Vue from "vue";
|
||||
import { useRootStore } from "./n8nRootStore";
|
||||
import { useWorkflowsStore } from "./workflows";
|
||||
|
||||
export const useTagsStore = defineStore(STORES.TAGS, {
|
||||
state: (): ITagsState => ({
|
||||
tags: {},
|
||||
loading: false,
|
||||
fetchedAll: false,
|
||||
fetchedUsageCount: false,
|
||||
}),
|
||||
getters: {
|
||||
allTags(): ITag[] {
|
||||
return Object.values(this.tags)
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
},
|
||||
isLoading(): boolean {
|
||||
return this.loading;
|
||||
},
|
||||
hasTags(): boolean {
|
||||
return Object.keys(this.tags).length > 0;
|
||||
},
|
||||
getTagById() {
|
||||
return (id: string) => this.tags[id];
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setAllTags(tags: ITag[]): void {
|
||||
this.tags = tags
|
||||
.reduce((accu: { [id: string]: ITag }, tag: ITag) => {
|
||||
accu[tag.id] = tag;
|
||||
|
||||
return accu;
|
||||
}, {});
|
||||
this.fetchedAll = true;
|
||||
},
|
||||
upsertTags(tags: ITag[]): void {
|
||||
tags.forEach((tag) => {
|
||||
const tagId = tag.id;
|
||||
const currentTag = this.tags[tagId];
|
||||
if (currentTag) {
|
||||
const newTag = {
|
||||
...currentTag,
|
||||
...tag,
|
||||
};
|
||||
Vue.set(this.tags, tagId, newTag);
|
||||
}
|
||||
else {
|
||||
Vue.set(this.tags, tagId, tag);
|
||||
}
|
||||
});
|
||||
},
|
||||
deleteTag(id: string): void {
|
||||
Vue.delete(this.tags, id);
|
||||
},
|
||||
|
||||
async fetchAll(params?: { force?: boolean, withUsageCount?: boolean }): Promise<ITag[]> {
|
||||
const { force = false, withUsageCount = false } = params || {};
|
||||
if (!force && this.fetchedAll && this.fetchedUsageCount === withUsageCount) {
|
||||
return Object.values(this.tags);
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
const rootStore = useRootStore();
|
||||
const tags = await getTags(rootStore.getRestApiContext, Boolean(withUsageCount));
|
||||
this.setAllTags(tags);
|
||||
this.loading = false;
|
||||
|
||||
return tags;
|
||||
},
|
||||
async create(name: string): Promise<ITag> {
|
||||
const rootStore = useRootStore();
|
||||
const tag = await createTag(rootStore.getRestApiContext, { name });
|
||||
this.upsertTags([tag]);
|
||||
|
||||
return tag;
|
||||
},
|
||||
async rename({ id, name }: { id: string, name: string }) {
|
||||
const rootStore = useRootStore();
|
||||
const tag = await updateTag(rootStore.getRestApiContext, id, { name });
|
||||
this.upsertTags([tag]);
|
||||
|
||||
return tag;
|
||||
},
|
||||
async delete(id: string) {
|
||||
const rootStore = useRootStore();
|
||||
const deleted = await deleteTag(rootStore.getRestApiContext, id);
|
||||
|
||||
if (deleted) {
|
||||
this.deleteTag(id);
|
||||
const workflowsStore = useWorkflowsStore();
|
||||
workflowsStore.removeWorkflowTagId(id);
|
||||
}
|
||||
|
||||
return deleted;
|
||||
},
|
||||
},
|
||||
});
|
||||
329
packages/editor-ui/src/stores/userHelpers.ts
Normal file
329
packages/editor-ui/src/stores/userHelpers.ts
Normal file
@@ -0,0 +1,329 @@
|
||||
|
||||
import { CALENDLY_TRIGGER_NODE_TYPE, CLEARBIT_NODE_TYPE, COMPANY_SIZE_1000_OR_MORE, COMPANY_SIZE_500_999, SCHEDULE_TRIGGER_NODE_TYPE, ELASTIC_SECURITY_NODE_TYPE, EMAIL_SEND_NODE_TYPE, EXECUTE_COMMAND_NODE_TYPE, FINANCE_WORK_AREA, GITHUB_TRIGGER_NODE_TYPE, HTTP_REQUEST_NODE_TYPE, IF_NODE_TYPE, ITEM_LISTS_NODE_TYPE, IT_ENGINEERING_WORK_AREA, JIRA_TRIGGER_NODE_TYPE, MICROSOFT_EXCEL_NODE_TYPE, MICROSOFT_TEAMS_NODE_TYPE, PAGERDUTY_NODE_TYPE, PRODUCT_WORK_AREA, QUICKBOOKS_NODE_TYPE, SALESFORCE_NODE_TYPE, SALES_BUSINESSDEV_WORK_AREA, SECURITY_WORK_AREA, SEGMENT_NODE_TYPE, SET_NODE_TYPE, SLACK_NODE_TYPE, SPREADSHEET_FILE_NODE_TYPE, SWITCH_NODE_TYPE, WEBHOOK_NODE_TYPE, XERO_NODE_TYPE, COMPANY_SIZE_KEY, WORK_AREA_KEY, CODING_SKILL_KEY, COMPANY_TYPE_KEY, ECOMMERCE_COMPANY_TYPE, MSP_COMPANY_TYPE, PERSONAL_COMPANY_TYPE, AUTOMATION_GOAL_KEY, OTHER_AUTOMATION_GOAL, NOT_SURE_YET_GOAL, CUSTOMER_INTEGRATIONS_GOAL, CUSTOMER_SUPPORT_GOAL, FINANCE_ACCOUNTING_GOAL, ZENDESK_TRIGGER_NODE_TYPE, WOOCOMMERCE_TRIGGER_NODE_TYPE, SALES_MARKETING_GOAL, HUBSPOT_TRIGGER_NODE_TYPE, HR_GOAL, WORKABLE_TRIGGER_NODE_TYPE, OPERATIONS_GOAL, PRODUCT_GOAL, NOTION_TRIGGER_NODE_TYPE, SECURITY_GOAL, THE_HIVE_TRIGGER_NODE_TYPE, ZENDESK_NODE_TYPE, SERVICENOW_NODE_TYPE, JIRA_NODE_TYPE, BAMBOO_HR_NODE_TYPE, GOOGLE_SHEETS_NODE_TYPE, CODE_NODE_TYPE } from '@/constants';
|
||||
import { IPermissions, IPersonalizationSurveyAnswersV1, IPersonalizationSurveyAnswersV2, IPersonalizationSurveyAnswersV3, IPersonalizationSurveyVersions, IUser } from '@/Interface';
|
||||
|
||||
import { ILogInStatus, IRole, IUserPermissions } from "@/Interface";
|
||||
|
||||
function isPersonalizationV2OrV3(data: IPersonalizationSurveyVersions): data is IPersonalizationSurveyAnswersV2 | IPersonalizationSurveyAnswersV3 {
|
||||
return "version" in data;
|
||||
}
|
||||
|
||||
export const ROLE: {Owner: IRole, Member: IRole, Default: IRole} = {
|
||||
Owner: 'owner',
|
||||
Member: 'member',
|
||||
Default: 'default', // default user with no email when setting up instance
|
||||
};
|
||||
|
||||
export const LOGIN_STATUS: {LoggedIn: ILogInStatus, LoggedOut: ILogInStatus} = {
|
||||
LoggedIn: 'LoggedIn', // Can be owner or member or default user
|
||||
LoggedOut: 'LoggedOut', // Can only be logged out if UM has been setup
|
||||
};
|
||||
|
||||
export const PERMISSIONS: IUserPermissions = {
|
||||
TAGS: {
|
||||
CAN_DELETE_TAGS: {
|
||||
allow: {
|
||||
role: [ROLE.Owner, ROLE.Default],
|
||||
},
|
||||
},
|
||||
},
|
||||
PRIMARY_MENU: {
|
||||
CAN_ACCESS_USER_INFO: {
|
||||
allow: {
|
||||
loginStatus: [LOGIN_STATUS.LoggedIn],
|
||||
},
|
||||
deny: {
|
||||
role: [ROLE.Default],
|
||||
},
|
||||
},
|
||||
},
|
||||
USER_SETTINGS: {
|
||||
VIEW_UM_SETUP_WARNING: {
|
||||
allow: {
|
||||
role: [ROLE.Default],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* To be authorized, user must pass all deny rules and pass any of the allow rules.
|
||||
*
|
||||
*/
|
||||
export const isAuthorized = (permissions: IPermissions, currentUser: IUser | null): boolean => {
|
||||
const loginStatus = currentUser ? LOGIN_STATUS.LoggedIn : LOGIN_STATUS.LoggedOut;
|
||||
// big AND block
|
||||
// if any of these are false, block user
|
||||
if (permissions.deny) {
|
||||
if (permissions.deny.shouldDeny && permissions.deny.shouldDeny()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (permissions.deny.loginStatus && permissions.deny.loginStatus.includes(loginStatus)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentUser && currentUser.globalRole) {
|
||||
const role = currentUser.isDefaultUser ? ROLE.Default : currentUser.globalRole.name;
|
||||
if (permissions.deny.role && permissions.deny.role.includes(role)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (permissions.deny.role) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// big OR block
|
||||
// if any of these are true, allow user
|
||||
if (permissions.allow) {
|
||||
if (permissions.allow.shouldAllow && permissions.allow.shouldAllow()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (permissions.allow.loginStatus && permissions.allow.loginStatus.includes(loginStatus)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (currentUser && currentUser.globalRole) {
|
||||
const role = currentUser.isDefaultUser ? ROLE.Default : currentUser.globalRole.name;
|
||||
if (permissions.allow.role && permissions.allow.role.includes(role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export function getPersonalizedNodeTypes(answers: IPersonalizationSurveyAnswersV1 | IPersonalizationSurveyAnswersV2 | IPersonalizationSurveyAnswersV3 | null): string[] {
|
||||
if (!answers) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (isPersonalizationV2OrV3(answers)) {
|
||||
return getPersonalizationV2(answers);
|
||||
}
|
||||
|
||||
return getPersonalizationV1(answers);
|
||||
}
|
||||
|
||||
export function getAccountAge(currentUser: IUser): number {
|
||||
if(currentUser.createdAt) {
|
||||
const accountCreatedAt = new Date(currentUser.createdAt);
|
||||
const today = new Date();
|
||||
|
||||
return Math.ceil((today.getTime() - accountCreatedAt.getTime()) / (1000* 3600 * 24));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function getPersonalizationV2(answers: IPersonalizationSurveyAnswersV2 | IPersonalizationSurveyAnswersV3) {
|
||||
let nodeTypes: string[] = [];
|
||||
|
||||
const {version, ...data} = answers;
|
||||
if (Object.keys(data).length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const companySize = answers[COMPANY_SIZE_KEY];
|
||||
const companyType = answers[COMPANY_TYPE_KEY];
|
||||
const automationGoal = answers[AUTOMATION_GOAL_KEY];
|
||||
|
||||
let codingSkill = null;
|
||||
if (CODING_SKILL_KEY in answers && answers[CODING_SKILL_KEY]) {
|
||||
codingSkill = parseInt(answers[CODING_SKILL_KEY] as string, 10);
|
||||
codingSkill = isNaN(codingSkill)? 0 : codingSkill;
|
||||
}
|
||||
|
||||
// slot 1 trigger
|
||||
if (companyType === ECOMMERCE_COMPANY_TYPE) {
|
||||
nodeTypes = nodeTypes.concat(WOOCOMMERCE_TRIGGER_NODE_TYPE);
|
||||
} else if (companyType === MSP_COMPANY_TYPE) {
|
||||
nodeTypes = nodeTypes.concat(JIRA_TRIGGER_NODE_TYPE);
|
||||
} else if((companyType === PERSONAL_COMPANY_TYPE || automationGoal === OTHER_AUTOMATION_GOAL || automationGoal === NOT_SURE_YET_GOAL) && codingSkill !== null && codingSkill >= 4) {
|
||||
nodeTypes = nodeTypes.concat(WEBHOOK_NODE_TYPE);
|
||||
} else if((companyType === PERSONAL_COMPANY_TYPE || automationGoal === OTHER_AUTOMATION_GOAL || automationGoal === NOT_SURE_YET_GOAL) && codingSkill !== null && codingSkill < 3) {
|
||||
nodeTypes = nodeTypes.concat(SCHEDULE_TRIGGER_NODE_TYPE);
|
||||
} else if (automationGoal === CUSTOMER_INTEGRATIONS_GOAL) {
|
||||
nodeTypes = nodeTypes.concat(WEBHOOK_NODE_TYPE);
|
||||
} else if (automationGoal === CUSTOMER_SUPPORT_GOAL || automationGoal === FINANCE_ACCOUNTING_GOAL) {
|
||||
nodeTypes = nodeTypes.concat(ZENDESK_TRIGGER_NODE_TYPE);
|
||||
} else if (automationGoal === SALES_MARKETING_GOAL) {
|
||||
nodeTypes = nodeTypes.concat(HUBSPOT_TRIGGER_NODE_TYPE);
|
||||
} else if (automationGoal === HR_GOAL) {
|
||||
nodeTypes = nodeTypes.concat(WORKABLE_TRIGGER_NODE_TYPE);
|
||||
} else if (automationGoal === OPERATIONS_GOAL) {
|
||||
nodeTypes = nodeTypes.concat(SCHEDULE_TRIGGER_NODE_TYPE);
|
||||
} else if (automationGoal === PRODUCT_GOAL) {
|
||||
nodeTypes = nodeTypes.concat(NOTION_TRIGGER_NODE_TYPE);
|
||||
} else if (automationGoal === SECURITY_GOAL) {
|
||||
nodeTypes = nodeTypes.concat(THE_HIVE_TRIGGER_NODE_TYPE);
|
||||
} else {
|
||||
nodeTypes = nodeTypes.concat(WEBHOOK_NODE_TYPE);
|
||||
}
|
||||
|
||||
// slot 2 data transformation
|
||||
if (codingSkill !== null && codingSkill >= 4) {
|
||||
nodeTypes = nodeTypes.concat(CODE_NODE_TYPE);
|
||||
} else {
|
||||
nodeTypes = nodeTypes.concat(ITEM_LISTS_NODE_TYPE);
|
||||
}
|
||||
|
||||
// slot 3 logic node
|
||||
if (codingSkill !== null && codingSkill < 3) {
|
||||
nodeTypes = nodeTypes.concat(IF_NODE_TYPE);
|
||||
}
|
||||
else {
|
||||
nodeTypes = nodeTypes.concat(SWITCH_NODE_TYPE);
|
||||
}
|
||||
|
||||
// slot 4 use case #1
|
||||
if (companySize === COMPANY_SIZE_500_999 || companySize === COMPANY_SIZE_1000_OR_MORE) {
|
||||
switch (automationGoal) {
|
||||
case CUSTOMER_INTEGRATIONS_GOAL:
|
||||
nodeTypes = nodeTypes.concat(HTTP_REQUEST_NODE_TYPE);
|
||||
break;
|
||||
case CUSTOMER_SUPPORT_GOAL:
|
||||
nodeTypes = nodeTypes.concat(ZENDESK_NODE_TYPE);
|
||||
break;
|
||||
case SALES_MARKETING_GOAL:
|
||||
nodeTypes = nodeTypes.concat(SALESFORCE_NODE_TYPE);
|
||||
break;
|
||||
case HR_GOAL:
|
||||
nodeTypes = nodeTypes.concat(SERVICENOW_NODE_TYPE);
|
||||
break;
|
||||
case PRODUCT_GOAL:
|
||||
nodeTypes = nodeTypes.concat(JIRA_NODE_TYPE);
|
||||
break;
|
||||
case FINANCE_ACCOUNTING_GOAL:
|
||||
nodeTypes = nodeTypes.concat(SPREADSHEET_FILE_NODE_TYPE);
|
||||
break;
|
||||
case SECURITY_GOAL:
|
||||
nodeTypes = nodeTypes.concat(ELASTIC_SECURITY_NODE_TYPE);
|
||||
break;
|
||||
default:
|
||||
nodeTypes = nodeTypes.concat(SLACK_NODE_TYPE);
|
||||
}
|
||||
} else {
|
||||
switch (automationGoal) {
|
||||
case CUSTOMER_INTEGRATIONS_GOAL:
|
||||
nodeTypes = nodeTypes.concat(HTTP_REQUEST_NODE_TYPE);
|
||||
break;
|
||||
case CUSTOMER_SUPPORT_GOAL:
|
||||
nodeTypes = nodeTypes.concat(ZENDESK_NODE_TYPE);
|
||||
break;
|
||||
case FINANCE_ACCOUNTING_GOAL:
|
||||
nodeTypes = nodeTypes.concat(QUICKBOOKS_NODE_TYPE);
|
||||
break;
|
||||
case HR_GOAL:
|
||||
nodeTypes = nodeTypes.concat(BAMBOO_HR_NODE_TYPE);
|
||||
break;
|
||||
case PRODUCT_GOAL:
|
||||
nodeTypes = nodeTypes.concat(JIRA_NODE_TYPE);
|
||||
break;
|
||||
case SALES_MARKETING_GOAL:
|
||||
nodeTypes = nodeTypes.concat(GOOGLE_SHEETS_NODE_TYPE);
|
||||
break;
|
||||
case SECURITY_GOAL:
|
||||
nodeTypes = nodeTypes.concat(ELASTIC_SECURITY_NODE_TYPE);
|
||||
break;
|
||||
default:
|
||||
nodeTypes = nodeTypes.concat(SLACK_NODE_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
// slot 4
|
||||
nodeTypes = nodeTypes.concat(SET_NODE_TYPE);
|
||||
|
||||
return nodeTypes;
|
||||
}
|
||||
|
||||
function getPersonalizationV1(answers: IPersonalizationSurveyAnswersV1) {
|
||||
const companySize = answers[COMPANY_SIZE_KEY];
|
||||
const workArea = answers[WORK_AREA_KEY];
|
||||
|
||||
function isWorkAreaAnswer(name: string) {
|
||||
if (Array.isArray(workArea)) {
|
||||
return workArea.includes(name);
|
||||
} else {
|
||||
return workArea === name;
|
||||
}
|
||||
}
|
||||
|
||||
const workAreaIsEmpty = !workArea|| workArea.length === 0;
|
||||
|
||||
if (companySize === null && workAreaIsEmpty && answers[CODING_SKILL_KEY] === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let codingSkill = null;
|
||||
if (answers[CODING_SKILL_KEY]) {
|
||||
codingSkill = parseInt(answers[CODING_SKILL_KEY] as string, 10);
|
||||
codingSkill = isNaN(codingSkill)? 0 : codingSkill;
|
||||
}
|
||||
|
||||
let nodeTypes = [] as string[];
|
||||
if (isWorkAreaAnswer(IT_ENGINEERING_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat(WEBHOOK_NODE_TYPE);
|
||||
}
|
||||
else {
|
||||
nodeTypes = nodeTypes.concat(SCHEDULE_TRIGGER_NODE_TYPE);
|
||||
}
|
||||
|
||||
if (codingSkill !== null && codingSkill >= 4) {
|
||||
nodeTypes = nodeTypes.concat(CODE_NODE_TYPE);
|
||||
}
|
||||
else {
|
||||
nodeTypes = nodeTypes.concat(ITEM_LISTS_NODE_TYPE);
|
||||
}
|
||||
|
||||
if (codingSkill !== null && codingSkill < 3) {
|
||||
nodeTypes = nodeTypes.concat(IF_NODE_TYPE);
|
||||
}
|
||||
else {
|
||||
nodeTypes = nodeTypes.concat(SWITCH_NODE_TYPE);
|
||||
}
|
||||
|
||||
if (companySize === COMPANY_SIZE_500_999 || companySize === COMPANY_SIZE_1000_OR_MORE) {
|
||||
if (isWorkAreaAnswer(SALES_BUSINESSDEV_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat(SALESFORCE_NODE_TYPE);
|
||||
}
|
||||
else if (isWorkAreaAnswer(SECURITY_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat([ELASTIC_SECURITY_NODE_TYPE, HTTP_REQUEST_NODE_TYPE]);
|
||||
}
|
||||
else if (isWorkAreaAnswer(PRODUCT_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat([JIRA_TRIGGER_NODE_TYPE, SEGMENT_NODE_TYPE]);
|
||||
}
|
||||
else if (isWorkAreaAnswer(IT_ENGINEERING_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat([GITHUB_TRIGGER_NODE_TYPE, HTTP_REQUEST_NODE_TYPE]);
|
||||
}
|
||||
else {
|
||||
nodeTypes = nodeTypes.concat([MICROSOFT_EXCEL_NODE_TYPE, MICROSOFT_TEAMS_NODE_TYPE]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isWorkAreaAnswer(SALES_BUSINESSDEV_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat(CLEARBIT_NODE_TYPE);
|
||||
}
|
||||
else if (isWorkAreaAnswer(SECURITY_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat([PAGERDUTY_NODE_TYPE, HTTP_REQUEST_NODE_TYPE]);
|
||||
}
|
||||
else if (isWorkAreaAnswer(PRODUCT_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat([JIRA_TRIGGER_NODE_TYPE, CALENDLY_TRIGGER_NODE_TYPE]);
|
||||
}
|
||||
else if (isWorkAreaAnswer(IT_ENGINEERING_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat([EXECUTE_COMMAND_NODE_TYPE, HTTP_REQUEST_NODE_TYPE]);
|
||||
}
|
||||
else if (isWorkAreaAnswer(FINANCE_WORK_AREA)) {
|
||||
nodeTypes = nodeTypes.concat([XERO_NODE_TYPE, QUICKBOOKS_NODE_TYPE, SPREADSHEET_FILE_NODE_TYPE]);
|
||||
}
|
||||
else {
|
||||
nodeTypes = nodeTypes.concat([EMAIL_SEND_NODE_TYPE, SLACK_NODE_TYPE]);
|
||||
}
|
||||
}
|
||||
|
||||
nodeTypes = nodeTypes.concat(SET_NODE_TYPE);
|
||||
|
||||
return nodeTypes;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { changePassword, deleteUser, getCurrentUser, getUsers, inviteUsers, login, loginCurrentUser, logout, reinvite, sendForgotPasswordEmail, setupOwner, signup, skipOwnerSetup, submitPersonalizationSurvey, updateCurrentUser, updateCurrentUserPassword, validatePasswordToken, validateSignupToken } from "@/api/users";
|
||||
import { PERSONALIZATION_MODAL_KEY, STORES } from "@/constants";
|
||||
import { IInviteResponse, IPersonalizationLatestVersion, IUser, IUserResponse, IUsersState } from "@/Interface";
|
||||
import { getPersonalizedNodeTypes, isAuthorized, PERMISSIONS, ROLE } from "@/modules/userHelpers";
|
||||
import { getPersonalizedNodeTypes, isAuthorized, PERMISSIONS, ROLE } from "@/stores/userHelpers";
|
||||
import { defineStore } from "pinia";
|
||||
import Vue from "vue";
|
||||
import { useRootStore } from "./n8nRootStore";
|
||||
|
||||
50
packages/editor-ui/src/stores/versions.ts
Normal file
50
packages/editor-ui/src/stores/versions.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { getNextVersions } from "@/api/versions";
|
||||
import { STORES } from "@/constants";
|
||||
import { IVersion, IVersionNotificationSettings, IVersionsState } from "@/Interface";
|
||||
import { defineStore } from "pinia";
|
||||
import { useRootStore } from "./n8nRootStore";
|
||||
|
||||
export const useVersionsStore = defineStore(STORES.VERSIONS, {
|
||||
state: (): IVersionsState => ({
|
||||
versionNotificationSettings: {
|
||||
enabled: false,
|
||||
endpoint: '',
|
||||
infoUrl: '',
|
||||
},
|
||||
nextVersions: [],
|
||||
currentVersion: undefined,
|
||||
}),
|
||||
getters: {
|
||||
hasVersionUpdates(): boolean {
|
||||
return this.nextVersions.length > 0;
|
||||
},
|
||||
areNotificationsEnabled(): boolean {
|
||||
return this.versionNotificationSettings.enabled;
|
||||
},
|
||||
infoUrl(): string {
|
||||
return this.versionNotificationSettings.infoUrl;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setVersions({versions, currentVersion}: {versions: IVersion[], currentVersion: string}) {
|
||||
this.nextVersions = versions.filter((version) => version.name !== currentVersion);
|
||||
this.currentVersion = versions.find((version) => version.name === currentVersion);
|
||||
},
|
||||
setVersionNotificationSettings(settings: IVersionNotificationSettings) {
|
||||
this.versionNotificationSettings = settings;
|
||||
},
|
||||
async fetchVersions() {
|
||||
try {
|
||||
const { enabled, endpoint } = this.versionNotificationSettings;
|
||||
if (enabled && endpoint) {
|
||||
const rootStore = useRootStore();
|
||||
const currentVersion = rootStore.versionCli;
|
||||
const instanceId = rootStore.instanceId;
|
||||
const versions = await getNextVersions(endpoint, currentVersion, instanceId);
|
||||
this.setVersions({ versions, currentVersion });
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
65
packages/editor-ui/src/stores/webhooks.ts
Normal file
65
packages/editor-ui/src/stores/webhooks.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { STORES } from "@/constants";
|
||||
import { IFakeDoor, INodeUi, IRootState } from "@/Interface";
|
||||
import { IMenuItem } from "n8n-design-system";
|
||||
import { IWorkflowSettings } from "n8n-workflow";
|
||||
import { defineStore } from "pinia";
|
||||
import { useRootStore } from "./n8nRootStore";
|
||||
import { useNDVStore } from "./ndv";
|
||||
import { useSettingsStore } from "./settings";
|
||||
import { useUIStore } from "./ui";
|
||||
import { useUsersStore } from "./users";
|
||||
import { useWorkflowsStore } from "./workflows";
|
||||
|
||||
export const useWebhooksStore = defineStore(STORES.WEBHOOKS, {
|
||||
getters: {
|
||||
globalRoleName(): string {
|
||||
return useUsersStore().globalRoleName;
|
||||
},
|
||||
getFakeDoorFeatures () {
|
||||
return useUIStore().fakeDoorFeatures;
|
||||
},
|
||||
isUserManagementEnabled () {
|
||||
return useSettingsStore().isUserManagementEnabled;
|
||||
},
|
||||
getFakeDoorItems(): IFakeDoor[] {
|
||||
return useUIStore().fakeDoorFeatures;
|
||||
},
|
||||
n8nMetadata(): IRootState['n8nMetadata'] {
|
||||
return useRootStore().n8nMetadata;
|
||||
},
|
||||
instanceId(): string {
|
||||
return useRootStore().instanceId;
|
||||
},
|
||||
workflowId(): string {
|
||||
return useWorkflowsStore().workflowId;
|
||||
},
|
||||
workflowName(): string {
|
||||
return useWorkflowsStore().workflowName;
|
||||
},
|
||||
activeNode(): INodeUi | null {
|
||||
return useNDVStore().activeNode;
|
||||
},
|
||||
workflowSettings(): IWorkflowSettings {
|
||||
return useWorkflowsStore().workflowSettings;
|
||||
},
|
||||
activeExecutionId(): string {
|
||||
return useWorkflowsStore().activeExecutionId || '';
|
||||
},
|
||||
nodeByName: (state: IRootState) => (nodeName: string): INodeUi | null => {
|
||||
return useWorkflowsStore().getNodeByName(nodeName);
|
||||
},
|
||||
allNodes(): INodeUi[] {
|
||||
return useWorkflowsStore().allNodes;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
addSidebarMenuItems(menuItems: IMenuItem[]) {
|
||||
const uiStore = useUIStore();
|
||||
const updated = uiStore.sidebarMenuItems.concat(menuItems);
|
||||
uiStore.sidebarMenuItems = updated;
|
||||
},
|
||||
setFakeDoorFeatures(fakeDoors: IFakeDoor[]): void {
|
||||
useUIStore().fakeDoorFeatures = fakeDoors;
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -649,7 +649,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
|
||||
return node.name === updateInformation.name;
|
||||
});
|
||||
|
||||
if (node === undefined || node === null) {
|
||||
if (node === undefined || node === null || !updateInformation.key) {
|
||||
throw new Error(`Node with the name "${updateInformation.name}" could not be found to set parameter.`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user