1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-19 17:07:18 +03:00

fix(editor): Show correct schema for output with falsy keys (#9556)

This commit is contained in:
Tomi Turtiainen 2024-05-31 11:33:52 +03:00 committed by GitHub
parent 93fb9b5393
commit 020bd36354
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 4 deletions

View File

@ -6,7 +6,6 @@ import Draggable from '@/components/Draggable.vue';
import { useNDVStore } from '@/stores/ndv.store'; import { useNDVStore } from '@/stores/ndv.store';
import { telemetry } from '@/plugins/telemetry'; import { telemetry } from '@/plugins/telemetry';
import type { IDataObject } from 'n8n-workflow'; import type { IDataObject } from 'n8n-workflow';
import { isEmpty } from '@/utils/typesUtils';
import { useExternalHooks } from '@/composables/useExternalHooks'; import { useExternalHooks } from '@/composables/useExternalHooks';
import { i18n } from '@/plugins/i18n'; import { i18n } from '@/plugins/i18n';
import MappingPill from './MappingPill.vue'; import MappingPill from './MappingPill.vue';
@ -33,7 +32,14 @@ const { getSchemaForExecutionData } = useDataSchema();
const schema = computed(() => getSchemaForExecutionData(props.data)); const schema = computed(() => getSchemaForExecutionData(props.data));
const isDataEmpty = computed(() => isEmpty(props.data)); const isDataEmpty = computed(() => {
// Utilize the generated schema instead of looping over the entire data again
// The schema for empty data is { type: 'object' | 'array', value: [] }
const isObjectOrArray = schema.value.type === 'object' || schema.value.type === 'array';
const isEmpty = Array.isArray(schema.value.value) && schema.value.value.length === 0;
return isObjectOrArray && isEmpty;
});
const highlight = computed(() => ndvStore.highlightDraggables); const highlight = computed(() => ndvStore.highlightDraggables);
@ -51,11 +57,11 @@ const onDragEnd = (el: HTMLElement) => {
const mappingTelemetry = ndvStore.mappingTelemetry; const mappingTelemetry = ndvStore.mappingTelemetry;
const telemetryPayload = { const telemetryPayload = {
src_node_type: props.node?.type, src_node_type: props.node?.type,
src_field_name: el.dataset.name || '', src_field_name: el.dataset.name ?? '',
src_nodes_back: props.distanceFromActive, src_nodes_back: props.distanceFromActive,
src_run_index: props.runIndex, src_run_index: props.runIndex,
src_runs_total: props.totalRuns, src_runs_total: props.totalRuns,
src_field_nest_level: el.dataset.depth || 0, src_field_nest_level: el.dataset.depth ?? 0,
src_view: 'schema', src_view: 'schema',
src_element: el, src_element: el,
success: false, success: false,

View File

@ -84,4 +84,27 @@ describe('RunDataJsonSchema.vue', () => {
}); });
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
}); });
it('renders no data to show for data empty objects', () => {
const renderResult = renderComponent({
props: {
data: [{}, {}],
},
});
expect(renderResult.getByText(/No data to show/)).toBeInTheDocument();
});
test.each([[[{ tx: false }, { tx: false }]], [[{ tx: '' }, { tx: '' }]], [[{ tx: [] }]]])(
'renders schema instead of showing no data for %o',
(data) => {
const renderResult = renderComponent({
props: {
data,
},
});
expect(renderResult.queryByText(/No data to show/)).not.toBeInTheDocument();
},
);
}); });