This commit is contained in:
r00gm 2024-11-12 15:32:10 +01:00
parent bd4df6dbb5
commit 878220d7b6
No known key found for this signature in database
2 changed files with 41 additions and 15 deletions

View file

@ -1,5 +1,5 @@
import jp from 'jsonpath'; import jp from 'jsonpath';
import { useDataSchema } from '@/composables/useDataSchema'; import { useDataSchema, useFlattenSchema } from '@/composables/useDataSchema';
import type { Schema } from '@/Interface'; import type { Schema } from '@/Interface';
describe('useDataSchema', () => { describe('useDataSchema', () => {
@ -525,3 +525,39 @@ describe('useDataSchema', () => {
}); });
}); });
}); });
describe('useFlattenSchema', () => {
it('flattens a schema', () => {
const schema: Schema = {
path: '',
type: 'object',
value: [
{
key: 'obj',
path: '.obj',
type: 'object',
value: [
{
key: 'foo',
path: '.obj.foo',
type: 'object',
value: [
{
key: 'nested',
path: '.obj.foo.nested',
type: 'string',
value: 'bar',
},
],
},
],
},
],
};
expect(
useFlattenSchema().flattSchema({
schema,
}).length,
).toBe(3);
});
});

View file

@ -12,7 +12,7 @@ import { generatePath, getMappedExpression } from '@/utils/mappingUtils';
import { isObj } from '@/utils/typeGuards'; import { isObj } from '@/utils/typeGuards';
import { useWorkflowsStore } from '@/stores/workflows.store'; import { useWorkflowsStore } from '@/stores/workflows.store';
import { isPresent, shorten } from '@/utils/typesUtils'; import { isPresent, shorten } from '@/utils/typesUtils';
import { i18n } from '@/plugins/i18n'; import { useI18n } from '@/composables/useI18n';
import { checkExhaustive } from '@/utils/typeGuards'; import { checkExhaustive } from '@/utils/typeGuards';
export function useDataSchema() { export function useDataSchema() {
@ -175,7 +175,7 @@ export type SchemaNode = {
depth: number; depth: number;
connectedOutputIndexes: number[]; connectedOutputIndexes: number[];
itemsCount: number; itemsCount: number;
schema: Schema | null; schema: Schema;
}; };
export type RenderItem = { export type RenderItem = {
@ -321,16 +321,6 @@ export const useFlattenSchema = () => {
} }
}; };
const flattSchemaNode = (schemaNode: SchemaNode) => {
const { schema, node, depth } = schemaNode;
if (!schema) {
return [];
}
return flattSchema({ schema, node, depth });
};
const flattMultipleSchema = (nodes: SchemaNode[], additionalInfo: (node: INodeUi) => string) => const flattMultipleSchema = (nodes: SchemaNode[], additionalInfo: (node: INodeUi) => string) =>
nodes.reduce<Renders[]>((acc, item, index) => { nodes.reduce<Renders[]>((acc, item, index) => {
acc.push({ acc.push({
@ -350,13 +340,13 @@ export const useFlattenSchema = () => {
if (isDataEmpty(item.schema)) { if (isDataEmpty(item.schema)) {
acc.push({ acc.push({
id: `empty-${index}`, id: `empty-${index}`,
value: i18n.baseText('dataMapping.schemaView.emptyData'), value: useI18n().baseText('dataMapping.schemaView.emptyData'),
type: 'item', type: 'item',
}); });
return acc; return acc;
} }
acc.push(...flattSchemaNode(item)); acc.push(...flattSchema(item));
return acc; return acc;
}, []); }, []);