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

fix(editor): Fix node icon in node creator header #9782

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import CategorizedItemsRenderer from '../Renderers/CategorizedItemsRenderer.vue'
import NoResults from '../Panel/NoResults.vue';
import { useI18n } from '@/composables/useI18n';
import { useTelemetry } from '@/composables/useTelemetry';
import { getNodeIcon, getNodeIconColor, getNodeIconUrl } from '@/utils/nodeTypesUtils';
import { useUIStore } from '@/stores/ui.store';

export interface Props {
rootView: 'trigger' | 'action';
Expand All @@ -35,6 +37,8 @@ const emit = defineEmits({

const i18n = useI18n();
const telemetry = useTelemetry();
const uiStore = useUIStore();
const rootStore = useRootStore();

const { mergedNodes, actions } = useNodeCreatorStore();
const { baseUrl } = useRootStore();
Expand Down Expand Up @@ -86,11 +90,10 @@ function onSelected(item: INodeCreateElement) {
return;
}

const icon = item.properties.iconUrl
? `${baseUrl}${item.properties.iconUrl}`
: typeof item.properties.icon === 'string'
? item.properties.icon?.split(':')[1]
: undefined;
const iconUrl = getNodeIconUrl(item.properties, uiStore.appliedTheme);
const icon = iconUrl
? rootStore.baseUrl + iconUrl
: getNodeIcon(item.properties, uiStore.appliedTheme)?.split(':')[1];

const transformedActions = nodeActions?.map((a) =>
transformNodeType(a, item.properties.displayName, 'action'),
Expand All @@ -100,9 +103,9 @@ function onSelected(item: INodeCreateElement) {
subcategory: item.properties.displayName,
title: item.properties.displayName,
nodeIcon: {
color: item.properties.defaults?.color?.toString(),
color: getNodeIconColor(item.properties),
icon,
iconType: item.properties.iconUrl ? 'file' : 'icon',
iconType: iconUrl ? 'file' : 'icon',
},

rootView: activeViewStack.value.rootView,
Expand Down
16 changes: 7 additions & 9 deletions packages/editor-ui/src/components/NodeIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
import type { IVersionNode, SimplifiedNodeType } from '@/Interface';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useUIStore } from '@/stores/ui.store';
import { getBadgeIconUrl, getNodeIcon, getNodeIconUrl } from '@/utils/nodeTypesUtils';
import {
getBadgeIconUrl,
getNodeIcon,
getNodeIconColor,
getNodeIconUrl,
} from '@/utils/nodeTypesUtils';
import type { INodeTypeDescription } from 'n8n-workflow';
import { computed } from 'vue';

Expand Down Expand Up @@ -75,14 +80,7 @@ const iconType = computed(() => {
return 'unknown';
});

const color = computed(() => {
const nodeType = props.nodeType;

if (nodeType && 'iconColor' in nodeType && nodeType.iconColor) {
return `var(--color-node-icon-${nodeType.iconColor})`;
}
return nodeType?.defaults?.color?.toString() ?? props.colorDefault ?? '';
});
const color = computed(() => getNodeIconColor(props.nodeType) ?? props.colorDefault ?? '');

const iconSource = computed<NodeIconSource>(() => {
const nodeType = props.nodeType;
Expand Down
9 changes: 9 additions & 0 deletions packages/editor-ui/src/utils/nodeTypesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,12 @@ export const getBadgeIconUrl = (
): string | null => {
return getThemedValue(nodeType.badgeIconUrl, theme);
};

export const getNodeIconColor = (
nodeType?: INodeTypeDescription | SimplifiedNodeType | IVersionNode | null,
) => {
if (nodeType && 'iconColor' in nodeType && nodeType.iconColor) {
return `var(--color-node-icon-${nodeType.iconColor})`;
}
return nodeType?.defaults?.color?.toString();
};
Loading