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

refactor(editor): Fix types issues in src/components/Node/* (no-changelog) #9444

Merged
merged 2 commits into from
May 17, 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
11 changes: 9 additions & 2 deletions packages/editor-ui/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const retry = async (
try {
resolve(assertion());
} catch (err) {
Date.now() - startTime > timeout ? reject(err) : tryAgain();
if (Date.now() - startTime > timeout) {
reject(err);
} else {
tryAgain();
}
}
}, interval);
};
Expand Down Expand Up @@ -62,7 +66,10 @@ export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
saveDataErrorExecution: 'all',
saveDataSuccessExecution: 'all',
saveManualExecutions: false,
binaryDataMode: 'default',
initialized: false,
mfa: {
enabled: false,
},
};

export const getDropdownItems = async (dropdownTriggerParent: HTMLElement) => {
Expand Down
73 changes: 40 additions & 33 deletions packages/editor-ui/src/components/Node.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div
v-if="data"
:id="nodeId"
:ref="data.name"
:class="nodeWrapperClass"
Expand Down Expand Up @@ -262,6 +263,16 @@ export default defineComponent({
callDebounced,
};
},
data() {
return {
isTouchActive: false,
nodeSubtitle: '',
showTriggerNodeTooltip: false,
pinDataDiscoveryTooltipVisible: false,
dragging: false,
unwatchWorkflowDataItems: () => {},
};
},
computed: {
...mapStores(useNodeTypesStore, useNDVStore, useUIStore, useWorkflowsStore),
showPinnedDataInfo(): boolean {
Expand Down Expand Up @@ -325,6 +336,7 @@ export default defineComponent({
return !!this.nodeType?.polling;
},
isExecuting(): boolean {
if (!this.data) return false;
return this.workflowsStore.isNodeExecuting(this.data.name);
},
isSingleActiveTriggerNode(): boolean {
Expand All @@ -336,12 +348,15 @@ export default defineComponent({
return nodes.length === 1;
},
isManualTypeNode(): boolean {
return this.data.type === MANUAL_TRIGGER_NODE_TYPE;
return this.data?.type === MANUAL_TRIGGER_NODE_TYPE;
},
isConfigNode(): boolean {
return this.nodeTypesStore.isConfigNode(this.workflow, this.data, this.data?.type ?? '');
if (!this.data) return false;
return this.nodeTypesStore.isConfigNode(this.workflow, this.data, this.data.type ?? '');
},
isConfigurableNode(): boolean {
if (!this.data) return false;

return this.nodeTypesStore.isConfigurableNode(
this.workflow,
this.data,
Expand All @@ -365,10 +380,10 @@ export default defineComponent({
return this.workflowsStore.nodesByName[this.name] as INodeUi | undefined;
},
sameTypeNodes(): INodeUi[] {
return this.workflowsStore.allNodes.filter((node: INodeUi) => node.type === this.data.type);
return this.workflowsStore.allNodes.filter((node: INodeUi) => node.type === this.data?.type);
},
nodeWrapperClass(): object {
const classes = {
nodeWrapperClass() {
const classes: Record<string, boolean> = {
'node-wrapper': true,
'node-wrapper--trigger': this.isTriggerNode,
'node-wrapper--configurable': this.isConfigurableNode,
Expand All @@ -389,7 +404,7 @@ export default defineComponent({

return classes;
},
nodeWrapperStyles(): object {
nodeWrapperStyles() {
const styles: {
[key: string]: string | number;
} = {
Expand Down Expand Up @@ -435,7 +450,7 @@ export default defineComponent({
nodeClass(): object {
return {
'node-box': true,
disabled: this.data.disabled,
disabled: this.data?.disabled,
executing: this.isExecuting,
};
},
Expand Down Expand Up @@ -466,7 +481,7 @@ export default defineComponent({
return issues;
},
nodeDisabledTitle(): string {
return this.data.disabled
return this.data?.disabled
? this.$locale.baseText('node.enable')
: this.$locale.baseText('node.disable');
},
Expand All @@ -476,21 +491,21 @@ export default defineComponent({
showDisabledLinethrough(): boolean {
return (
!this.isConfigurableNode &&
!!(this.data.disabled && this.inputs.length === 1 && this.outputs.length === 1)
!!(this.data?.disabled && this.inputs.length === 1 && this.outputs.length === 1)
);
},
shortNodeType(): string {
return this.$locale.shortNodeType(this.data.type);
return this.$locale.shortNodeType(this.data?.type ?? '');
},
nodeTitle(): string {
if (this.data.name === 'Start') {
if (this.data?.name === 'Start') {
return this.$locale.headerText({
key: 'headers.start.displayName',
fallback: 'Start',
});
}

return this.data.name;
return this.data?.name ?? '';
},
waiting(): string | undefined {
const workflowExecution = this.workflowsStore.getWorkflowExecution as ExecutionSummary;
Expand Down Expand Up @@ -518,7 +533,7 @@ export default defineComponent({
workflowRunning(): boolean {
return this.uiStore.isActionActive('workflowRunning');
},
nodeStyle(): object {
nodeStyle() {
const returnStyles: {
[key: string]: string;
} = {};
Expand All @@ -529,7 +544,7 @@ export default defineComponent({
borderColor = '--color-foreground-dark';
}

if (this.data.disabled) {
if (this.data?.disabled) {
borderColor = '--color-foreground-base';
} else if (!this.isExecuting) {
if (this.hasIssues && !this.hideNodeIssues) {
Expand Down Expand Up @@ -559,7 +574,7 @@ export default defineComponent({
},
isSelected(): boolean {
return (
this.uiStore.getSelectedNodes.find((node: INodeUi) => node.name === this.data.name) !==
this.uiStore.getSelectedNodes.find((node: INodeUi) => node.name === this.data?.name) !==
undefined
);
},
Expand Down Expand Up @@ -668,23 +683,13 @@ export default defineComponent({
}, 0);
}
},
data() {
return {
isTouchActive: false,
nodeSubtitle: '',
showTriggerNodeTooltip: false,
pinDataDiscoveryTooltipVisible: false,
dragging: false,
unwatchWorkflowDataItems: () => {},
};
},
methods: {
showPinDataDiscoveryTooltip(dataItemsCount: number): void {
if (
!this.isTriggerNode ||
this.isManualTypeNode ||
this.isScheduledGroup ||
this.uiStore.isModalActive ||
this.uiStore.isAnyModalOpen ||
OlegIvaniv marked this conversation as resolved.
Show resolved Hide resolved
dataItemsCount === 0
)
return;
Expand All @@ -695,13 +700,14 @@ export default defineComponent({
this.unwatchWorkflowDataItems();
},
setSubtitle() {
if (!this.data || !this.nodeType) return;
// why is this not a computed property? because it's a very expensive operation
// it requires expressions to resolve each subtitle...
// and ends up bogging down the UI with big workflows, for example when pasting a workflow or even opening a node...
// so we only update it when necessary (when node is mounted and when it's opened and closed (isActive))
try {
const nodeSubtitle =
this.nodeHelpers.getNodeSubtitle(this.data, this.nodeType, this.workflow) || '';
this.nodeHelpers.getNodeSubtitle(this.data, this.nodeType, this.workflow) ?? '';

this.nodeSubtitle = nodeSubtitle.includes(CUSTOM_API_CALL_KEY) ? '' : nodeSubtitle;
} catch (e) {
Expand All @@ -727,28 +733,28 @@ export default defineComponent({
},

executeNode() {
this.$emit('runWorkflow', this.data.name, 'Node.executeNode');
this.$emit('runWorkflow', this.data?.name, 'Node.executeNode');
this.$telemetry.track('User clicked node hover button', {
node_type: this.data.type,
node_type: this.data?.type,
button_name: 'execute',
workflow_id: this.workflowsStore.workflowId,
});
},

deleteNode() {
this.$telemetry.track('User clicked node hover button', {
node_type: this.data.type,
node_type: this.data?.type,
button_name: 'delete',
workflow_id: this.workflowsStore.workflowId,
});

this.$emit('removeNode', this.data.name);
this.$emit('removeNode', this.data?.name);
},

toggleDisableNode(event: MouseEvent) {
(event.currentTarget as HTMLButtonElement).blur();
this.$telemetry.track('User clicked node hover button', {
node_type: this.data.type,
node_type: this.data?.type,
button_name: 'disable',
workflow_id: this.workflowsStore.workflowId,
});
Expand All @@ -759,7 +765,8 @@ export default defineComponent({
void this.callDebounced(this.onClickDebounced, { debounceTime: 50, trailing: true }, event);
},

onClickDebounced(event: MouseEvent) {
onClickDebounced(...args: unknown[]) {
const event = args[0] as MouseEvent;
const isDoubleClick = event.detail >= 2;
if (isDoubleClick) {
this.setNodeActive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>

<script setup lang="ts">
import { reactive, computed, toRefs, getCurrentInstance } from 'vue';
import { reactive, computed, toRefs } from 'vue';
import type { ActionTypeDescription, SimplifiedNodeType } from '@/Interface';
import { WEBHOOK_NODE_TYPE, DRAG_EVENT_DATA_KEY } from '@/constants';

Expand All @@ -30,16 +30,15 @@ import NodeIcon from '@/components/NodeIcon.vue';

import { useViewStacks } from '../composables/useViewStacks';
import { useActions } from '../composables/useActions';
import { useTelemetry } from '@/composables/useTelemetry';

export interface Props {
nodeType: SimplifiedNodeType;
action: ActionTypeDescription;
}

const props = defineProps<Props>();

const instance = getCurrentInstance();
const telemetry = instance?.proxy.$telemetry;
const telemetry = useTelemetry();

const { getActionData, getAddedNodesAndConnections, setAddedNodeActionParameters } = useActions();
const { activeViewStack } = useViewStacks();
Expand Down Expand Up @@ -104,7 +103,7 @@ function onDragOver(event: DragEvent): void {
state.draggablePosition = { x, y };
}

function onDragEnd(event: DragEvent): void {
function onDragEnd(): void {
if (state.storeWatcher) state.storeWatcher();
document.body.removeEventListener('dragend', onDragEnd);
document.body.removeEventListener('dragover', onDragOver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface Props {

const props = withDefaults(defineProps<Props>(), {
active: false,
subcategory: undefined,
});

const i18n = useI18n();
Expand Down Expand Up @@ -105,8 +106,7 @@ const hasActions = computed(() => {
});

const nodeActions = computed(() => {
const nodeActions = actions[props.nodeType.name] || [];
return nodeActions;
return actions[props.nodeType.name] || [];
});

const shortNodeType = computed<string>(() => i18n.shortNodeType(props.nodeType.name) || '');
Expand All @@ -119,11 +119,11 @@ const draggableStyle = computed<{ top: string; left: string }>(() => ({
const isCommunityNode = computed<boolean>(() => isCommunityPackageName(props.nodeType.name));

const displayName = computed<string>(() => {
const displayName = props.nodeType.displayName.trimEnd();
const trimmedDisplayName = props.nodeType.displayName.trimEnd();

return i18n.headerText({
key: `headers.${shortNodeType.value}.displayName`,
fallback: hasActions.value ? displayName.replace('Trigger', '') : displayName,
fallback: hasActions.value ? trimmedDisplayName.replace('Trigger', '') : trimmedDisplayName,
});
});

Expand Down Expand Up @@ -165,7 +165,7 @@ function onDragOver(event: DragEvent): void {
draggablePosition.value = { x, y };
}

function onDragEnd(event: DragEvent): void {
function onDragEnd(): void {
document.body.removeEventListener('dragover', onDragOver);

dragging.value = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<template>
<n8n-node-creator-node
:class="$style.subCategory"
:title="i18n.baseText(`nodeCreator.subcategoryNames.${subcategoryName}`)"
:title="i18n.baseText(`nodeCreator.subcategoryNames.${subcategoryName}` as BaseTextKey)"
:is-trigger="false"
:description="i18n.baseText(`nodeCreator.subcategoryDescriptions.${subcategoryName}`)"
:description="
i18n.baseText(`nodeCreator.subcategoryDescriptions.${subcategoryName}` as BaseTextKey)
"
:show-action-arrow="true"
>
<template #icon>
Expand All @@ -23,6 +25,7 @@ import type { SubcategoryItemProps } from '@/Interface';
import { camelCase } from 'lodash-es';
import { computed } from 'vue';
import { useI18n } from '@/composables/useI18n';
import type { BaseTextKey } from '@/plugins/i18n';

export interface Props {
item: SubcategoryItemProps;
Expand Down
Loading
Loading