Files
n8n-enterprise-unlocked/packages/editor-ui/src/components/NodeIcon.vue
T
Milorad FIlipović 3de062202d refactor(editor): Implemented NodeIcon design system component (#3727)
*  Implemented `NodeIcon` design system component

*  Updated editor to use N8nNodeIcon component, removed HoverableNodeIcon

*  Adding design system types import to editor-ui

* ✔️ Fixing linting errors

* 👌 Updating `NodeIcon` component based on review feedback

* 👌 Minor changes to `NodeIcon` component

* 👌 Removing unnecessary `Vue.use statement

* 🐛 Fixing unknown node icon bug and adding click listener to node icon component

* 💄 Removing unnecessary pointer cursor from the `NodeIcon` component

* 💄 Adding pointer cursor to node icons in the template details

* 💄 Updating node icon size in collections page
2022-08-01 22:35:45 +02:00

101 lines
2.3 KiB
Vue

<template>
<n8n-node-icon
:type="type"
:src="iconSource.path || iconSource.fileBuffer"
:name="iconSource.icon"
:color="color"
:disabled="disabled"
:size="size"
:circle="circle"
:nodeTypeName="nodeType ? nodeType.displayName : ''"
:showTooltip="showTooltip"
@click="(e) => $emit('click')"
></n8n-node-icon>
</template>
<script lang="ts">
import { IVersionNode } from '@/Interface';
import { INodeTypeDescription } from 'n8n-workflow';
import Vue from 'vue';
interface NodeIconSource {
path?: string;
fileBuffer?: string;
icon?: string;
}
export default Vue.extend({
name: 'NodeIcon',
props: {
nodeType: {
},
size: {
type: Number,
required: false,
},
disabled: {
type: Boolean,
default: false,
},
circle: {
type: Boolean,
default: false,
},
showTooltip: {
type: Boolean,
default: false,
},
},
computed: {
type (): string {
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
let iconType = 'unknown';
if (nodeType) {
if ((nodeType as IVersionNode).iconData) {
iconType = (nodeType as IVersionNode).iconData.type;
} else if (nodeType.icon) {
iconType = nodeType.icon.split(':')[0] === 'file' ? 'file' : 'icon';
}
}
return iconType;
},
color () : string {
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
if (nodeType && nodeType.defaults && nodeType.defaults.color) {
return nodeType.defaults.color.toString();
}
return '';
},
iconSource () : NodeIconSource {
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
const restUrl = this.$store.getters.getRestUrl;
const iconSource = {} as NodeIconSource;
if (nodeType) {
// If node type has icon data, use it
if ((nodeType as IVersionNode).iconData) {
return {
icon: (nodeType as IVersionNode).iconData.icon,
fileBuffer: (nodeType as IVersionNode).iconData.fileBuffer,
};
}
// Otherwise, extract it from icon prop
if (nodeType.icon) {
let type, path;
[type, path] = nodeType.icon.split(':');
if (type === 'file') {
iconSource.path = `${restUrl}/node-icon/${nodeType.name}`;
} else {
iconSource.icon = path;
}
}
}
return iconSource;
},
},
});
</script>
<style lang="scss">
</style>