fix(editor): Fix credential icon for old node type version (#7843)

If a credential was for a node's older version, its icon was not shown.
This commit is contained in:
Tomi Turtiainen
2023-11-28 15:14:22 +02:00
committed by GitHub
parent a37f1cb0ba
commit 4074107511
7 changed files with 1115 additions and 47 deletions

View File

@@ -132,9 +132,9 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
getNodesWithAccess() {
return (credentialTypeName: string) => {
const nodeTypesStore = useNodeTypesStore();
const allLatestNodeTypes: INodeTypeDescription[] = nodeTypesStore.allLatestNodeTypes;
const allNodeTypes: INodeTypeDescription[] = nodeTypesStore.allNodeTypes;
return allLatestNodeTypes.filter((nodeType: INodeTypeDescription) => {
return allNodeTypes.filter((nodeType: INodeTypeDescription) => {
if (!nodeType.credentials) {
return false;
}

View File

@@ -6,12 +6,7 @@ import {
getResourceLocatorResults,
getResourceMapperFields,
} from '@/api/nodeTypes';
import {
DEFAULT_NODETYPE_VERSION,
HTTP_REQUEST_NODE_TYPE,
STORES,
CREDENTIAL_ONLY_HTTP_NODE_VERSION,
} from '@/constants';
import { HTTP_REQUEST_NODE_TYPE, STORES, CREDENTIAL_ONLY_HTTP_NODE_VERSION } from '@/constants';
import type { INodeTypesState, DynamicNodeParameters } from '@/Interface';
import { addHeaders, addNodeTranslation } from '@/plugins/i18n';
import { omit } from '@/utils/typesUtils';
@@ -35,10 +30,9 @@ import {
getCredentialTypeName,
isCredentialOnlyNodeType,
} from '@/utils/credentialOnlyNodes';
import { groupNodeTypesByNameAndType } from '@/utils/nodeTypes/nodeTypeTransforms';
function getNodeVersions(nodeType: INodeTypeDescription) {
return Array.isArray(nodeType.version) ? nodeType.version : [nodeType.version];
}
export type NodeTypesStore = ReturnType<typeof useNodeTypesStore>;
export const useNodeTypesStore = defineStore(STORES.NODE_TYPES, {
state: (): INodeTypesState => ({
@@ -196,36 +190,11 @@ export const useNodeTypesStore = defineStore(STORES.NODE_TYPES, {
},
actions: {
setNodeTypes(newNodeTypes: INodeTypeDescription[] = []): void {
const nodeTypes = newNodeTypes.reduce<Record<string, Record<string, INodeTypeDescription>>>(
(acc, newNodeType) => {
const newNodeVersions = getNodeVersions(newNodeType);
if (newNodeVersions.length === 0) {
const singleVersion = { [DEFAULT_NODETYPE_VERSION]: newNodeType };
acc[newNodeType.name] = singleVersion;
return acc;
}
for (const version of newNodeVersions) {
// Node exists with the same name
if (acc[newNodeType.name]) {
acc[newNodeType.name][version] = Object.assign(
acc[newNodeType.name][version] ?? {},
newNodeType,
);
} else {
acc[newNodeType.name] = Object.assign(acc[newNodeType.name] ?? {}, {
[version]: newNodeType,
});
}
}
return acc;
},
{ ...this.nodeTypes },
);
this.nodeTypes = nodeTypes;
const nodeTypes = groupNodeTypesByNameAndType(newNodeTypes);
this.nodeTypes = {
...this.nodeTypes,
...nodeTypes,
};
},
removeNodeTypes(nodeTypesToRemove: INodeTypeDescription[]): void {
this.nodeTypes = nodeTypesToRemove.reduce(