mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): Show correct schema for output with falsy keys (#9556)
This commit is contained in:
parent
93fb9b5393
commit
020bd36354
|
@ -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,
|
||||||
|
|
|
@ -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();
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue