Skip to content

Commit

Permalink
fix(editor): Show correct schema for output with falsy keys (#9556)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored May 31, 2024
1 parent 93fb9b5 commit 020bd36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/editor-ui/src/components/RunDataSchema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Draggable from '@/components/Draggable.vue';
import { useNDVStore } from '@/stores/ndv.store';
import { telemetry } from '@/plugins/telemetry';
import type { IDataObject } from 'n8n-workflow';
import { isEmpty } from '@/utils/typesUtils';
import { useExternalHooks } from '@/composables/useExternalHooks';
import { i18n } from '@/plugins/i18n';
import MappingPill from './MappingPill.vue';
Expand All @@ -33,7 +32,14 @@ const { getSchemaForExecutionData } = useDataSchema();
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);
Expand All @@ -51,11 +57,11 @@ const onDragEnd = (el: HTMLElement) => {
const mappingTelemetry = ndvStore.mappingTelemetry;
const telemetryPayload = {
src_node_type: props.node?.type,
src_field_name: el.dataset.name || '',
src_field_name: el.dataset.name ?? '',
src_nodes_back: props.distanceFromActive,
src_run_index: props.runIndex,
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_element: el,
success: false,
Expand Down
23 changes: 23 additions & 0 deletions packages/editor-ui/src/components/__tests__/RunDataSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,27 @@ describe('RunDataJsonSchema.vue', () => {
});
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();
},
);
});

0 comments on commit 020bd36

Please sign in to comment.