Skip to content

Commit

Permalink
fix(editor): Fix credential icon for old node type version (#7843)
Browse files Browse the repository at this point in the history
If a credential was for a node's older version, its icon was not shown.
  • Loading branch information
tomi authored and netroy committed Nov 29, 2023
1 parent d21d7fd commit 9b0e2d1
Show file tree
Hide file tree
Showing 7 changed files with 1,115 additions and 47 deletions.
12 changes: 7 additions & 5 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,12 +1277,14 @@ export interface ISettingsState {
saveManualExecutions: boolean;
}

export interface INodeTypesState {
nodeTypes: {
[nodeType: string]: {
[version: number]: INodeTypeDescription;
};
export type NodeTypesByTypeNameAndVersion = {
[nodeType: string]: {
[version: number]: INodeTypeDescription;
};
};

export interface INodeTypesState {
nodeTypes: NodeTypesByTypeNameAndVersion;
}

export interface ITemplateState {
Expand Down
5 changes: 4 additions & 1 deletion packages/editor-ui/src/components/CredentialIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ export default defineComponent({
const nodeType = this.credentialWithIcon.icon.replace('node:', '');
return this.nodeTypesStore.getNodeType(nodeType);
}
const nodesWithAccess = this.credentialsStore.getNodesWithAccess(this.credentialTypeName);
if (!this.credentialTypeName) {
return null;
}
const nodesWithAccess = this.credentialsStore.getNodesWithAccess(this.credentialTypeName);
if (nodesWithAccess.length) {
return nodesWithAccess[0];
}
Expand Down
73 changes: 73 additions & 0 deletions packages/editor-ui/src/components/__tests__/CredentialIcon.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { createComponentRenderer } from '@/__tests__/render';
import CredentialIcon from '@/components/CredentialIcon.vue';
import { STORES } from '@/constants';
import { createTestingPinia } from '@pinia/testing';
import * as testNodeTypes from './testData/nodeTypesTestData';
import merge from 'lodash-es/merge';
import { groupNodeTypesByNameAndType } from '@/utils/nodeTypes/nodeTypeTransforms';

const defaultState = {
[STORES.CREDENTIALS]: {},
[STORES.NODE_TYPES]: {},
};

const renderComponent = createComponentRenderer(CredentialIcon, {
pinia: createTestingPinia({
initialState: defaultState,
}),
global: {
stubs: ['n8n-tooltip'],
},
});

describe('CredentialIcon', () => {
const findIcon = (baseElement: Element) => baseElement.querySelector('img');

it('shows correct icon for credential type that is for the latest node type version', () => {
const { baseElement } = renderComponent({
pinia: createTestingPinia({
initialState: merge(defaultState, {
[STORES.CREDENTIALS]: {},
[STORES.NODE_TYPES]: {
nodeTypes: groupNodeTypesByNameAndType([
testNodeTypes.twitterV1,
testNodeTypes.twitterV2,
]),
},
}),
}),
props: {
credentialTypeName: 'twitterOAuth2Api',
},
});

expect(findIcon(baseElement)).toHaveAttribute(
'src',
'/icons/n8n-nodes-base/dist/nodes/Twitter/x.svg',
);
});

it('shows correct icon for credential type that is for an older node type version', () => {
const { baseElement } = renderComponent({
pinia: createTestingPinia({
initialState: merge(defaultState, {
[STORES.CREDENTIALS]: {},
[STORES.NODE_TYPES]: {
nodeTypes: groupNodeTypesByNameAndType([
testNodeTypes.twitterV1,
testNodeTypes.twitterV2,
]),
},
}),
}),
props: {
credentialTypeName: 'twitterOAuth1Api',
},
});

expect(findIcon(baseElement)).toHaveAttribute(
'src',
'/icons/n8n-nodes-base/dist/nodes/Twitter/x.svg',
);
});
});
Loading

0 comments on commit 9b0e2d1

Please sign in to comment.