fix(editor): Fix 0 items labels on new canvas (no-changelog) (#11344)

This commit is contained in:
Alex Grozav 2024-10-22 15:16:43 +03:00 committed by GitHub
parent 5fae187a0a
commit f98f0ead25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 12 deletions

View file

@ -31,6 +31,7 @@ onEdgeMouseEnter(({ edge }) => {
if (edge.id !== props.id) return;
isHovered.value = true;
});
onEdgeMouseLeave(({ edge }) => {
if (edge.id !== props.id) return;
isHovered.value = false;

View file

@ -64,7 +64,7 @@ describe('CanvasHandleMainOutput', () => {
expect(getByText('1 item')).toBeInTheDocument();
});
it('should not render run data label if output label is available', async () => {
it('should render run data label even if output label is available', async () => {
const runData = {
total: 1,
iterations: 1,
@ -77,7 +77,22 @@ describe('CanvasHandleMainOutput', () => {
},
});
expect(() => getByText('1 item')).toThrow();
expect(getByText('1 item')).toBeInTheDocument();
expect(getByText('Output')).toBeInTheDocument();
});
it('should not render run data label if handle is connected', async () => {
const runData = {
total: 1,
iterations: 1,
};
const { queryByText } = renderComponent({
global: {
provide: {
...createCanvasHandleProvide({ label: '', runData, isConnected: true }),
},
},
});
expect(queryByText('1 item')).not.toBeInTheDocument();
});
});

View file

@ -31,7 +31,7 @@ const renderOptions = computed(() => render.value.options as CanvasNodeDefaultRe
const runDataTotal = computed(() => runData.value?.total ?? 0);
const runDataLabel = computed(() =>
runData.value
!isConnected.value && runData.value && runData.value.total > 0
? i18n.baseText('ndv.output.items', {
adjustToNumber: runData.value.total,
interpolate: { count: String(runData.value.total) },
@ -77,7 +77,7 @@ function onClickAdd() {
<template>
<div :class="classes">
<div v-if="label" :class="outputLabelClasses">{{ label }}</div>
<div v-else-if="runData" :class="runDataLabelClasses">{{ runDataLabel }}</div>
<div v-if="runData" :class="runDataLabelClasses">{{ runDataLabel }}</div>
<CanvasHandleDot :handle-classes="handleClasses" />
<Transition name="canvas-node-handle-main-output">
<CanvasHandlePlus

View file

@ -555,19 +555,23 @@ export function useCanvasMapping({
if (nodePinnedDataById.value[fromNode.id]) {
const pinnedDataCount = nodePinnedDataById.value[fromNode.id]?.length ?? 0;
return i18n.baseText('ndv.output.items', {
adjustToNumber: pinnedDataCount,
interpolate: { count: String(pinnedDataCount) },
});
return pinnedDataCount > 0
? i18n.baseText('ndv.output.items', {
adjustToNumber: pinnedDataCount,
interpolate: { count: String(pinnedDataCount) },
})
: '';
} else if (nodeExecutionRunDataById.value[fromNode.id]) {
const { type, index } = parseCanvasConnectionHandleString(connection.sourceHandle);
const runDataTotal =
nodeExecutionRunDataOutputMapById.value[fromNode.id]?.[type]?.[index]?.total ?? 0;
return i18n.baseText('ndv.output.items', {
adjustToNumber: runDataTotal,
interpolate: { count: String(runDataTotal) },
});
return runDataTotal > 0
? i18n.baseText('ndv.output.items', {
adjustToNumber: runDataTotal,
interpolate: { count: String(runDataTotal) },
})
: '';
}
return '';