feat(editor): Show multiple nodes in input pane schema view (#9816)

This commit is contained in:
Elias Meire
2024-06-24 18:09:28 +02:00
committed by GitHub
parent e33a47311f
commit e51de9d391
23 changed files with 2561 additions and 742 deletions

View File

@@ -352,4 +352,176 @@ describe('useDataSchema', () => {
expect(pathData).toEqual([new Date('2022-11-22T00:00:00.000Z')]);
});
});
describe('filterSchema', () => {
const filterSchema = useDataSchema().filterSchema;
it('should correctly filter a flat schema', () => {
const flatSchema: Schema = {
type: 'object',
value: [
{
key: 'name',
type: 'string',
value: 'First item',
path: '.name',
},
{
key: 'code',
type: 'number',
value: '1',
path: '.code',
},
{
key: 'email',
type: 'string',
value: 'first item@gmail.com',
path: '.email',
},
],
path: '',
};
expect(filterSchema(flatSchema, 'mail')).toEqual({
path: '',
type: 'object',
value: [
{
key: 'email',
path: '.email',
type: 'string',
value: 'first item@gmail.com',
},
],
});
expect(filterSchema(flatSchema, '1')).toEqual({
path: '',
type: 'object',
value: [
{
key: 'code',
path: '.code',
type: 'number',
value: '1',
},
],
});
expect(filterSchema(flatSchema, 'no match')).toEqual(null);
});
it('should correctly filter a nested schema', () => {
const nestedSchema: Schema = {
type: 'object',
value: [
{
key: 'name',
type: 'string',
value: 'First item',
path: '.name',
},
{
key: 'code',
type: 'number',
value: '1',
path: '.code',
},
{
key: 'email',
type: 'string',
value: 'first item@gmail.com',
path: '.email',
},
{
key: 'obj',
type: 'object',
value: [
{
key: 'foo',
type: 'object',
value: [
{
key: 'nested',
type: 'string',
value: 'bar',
path: '.obj.foo.nested',
},
],
path: '.obj.foo',
},
],
path: '.obj',
},
],
path: '',
};
expect(filterSchema(nestedSchema, 'bar')).toEqual({
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(filterSchema(nestedSchema, '1')).toEqual({
path: '',
type: 'object',
value: [
{
key: 'code',
path: '.code',
type: 'number',
value: '1',
},
],
});
expect(filterSchema(nestedSchema, 'no match')).toEqual(null);
});
it('should not filter schema with empty search', () => {
const flatSchema: Schema = {
type: 'object',
value: [
{
key: 'name',
type: 'string',
value: 'First item',
path: '.name',
},
{
key: 'code',
type: 'number',
value: '1',
path: '.code',
},
{
key: 'email',
type: 'string',
value: 'first item@gmail.com',
path: '.email',
},
],
path: '',
};
expect(filterSchema(flatSchema, '')).toEqual(flatSchema);
});
});
});

View File

@@ -9,6 +9,7 @@ import { merge } from 'lodash-es';
import { generatePath } from '@/utils/mappingUtils';
import { isObj } from '@/utils/typeGuards';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { isPresent } from '@/utils/typesUtils';
export function useDataSchema() {
function getSchema(
@@ -126,10 +127,40 @@ export function useDataSchema() {
return inputData;
}
function schemaMatches(schema: Schema, search: string): boolean {
const searchLower = search.toLocaleLowerCase();
return (
!!schema.key?.toLocaleLowerCase().includes(searchLower) ||
(typeof schema.value === 'string' && schema.value.toLocaleLowerCase().includes(searchLower))
);
}
function filterSchema(schema: Schema, search: string): Schema | null {
if (!search.trim()) return schema;
if (Array.isArray(schema.value)) {
const filteredValue = schema.value
.map((value) => filterSchema(value, search))
.filter(isPresent);
if (filteredValue.length === 0) {
return schemaMatches(schema, search) ? schema : null;
}
return {
...schema,
value: filteredValue,
};
}
return schemaMatches(schema, search) ? schema : null;
}
return {
getSchema,
getSchemaForExecutionData,
getNodeInputData,
getInputDataWithPinned,
filterSchema,
};
}