code improvements

This commit is contained in:
r00gm 2024-11-13 08:45:13 +01:00
parent 85fb7584d0
commit c4bd0f0b0b
No known key found for this signature in database

View file

@ -13,7 +13,6 @@ 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 { useI18n } from '@/composables/useI18n'; import { useI18n } from '@/composables/useI18n';
import { checkExhaustive } from '@/utils/typeGuards';
export function useDataSchema() { export function useDataSchema() {
function getSchema( function getSchema(
@ -204,35 +203,22 @@ export type RenderHeader = {
type Renders = RenderHeader | RenderItem; type Renders = RenderHeader | RenderItem;
const getIconBySchemaType = (type: Schema['type']): string => { const icons = {
switch (type) { object: 'cube',
case 'object': array: 'list',
return 'cube'; ['string']: 'font',
case 'array': null: 'font',
return 'list'; ['number']: 'hashtag',
case 'string': ['boolean']: 'check-square',
case 'null': function: 'code',
return 'font'; bigint: 'calculator',
case 'number': symbol: 'sun',
return 'hashtag'; ['undefined']: 'ban',
case 'boolean': } as const;
return 'check-square';
case 'function':
return 'code';
case 'bigint':
return 'calculator';
case 'symbol':
return 'sun';
case 'undefined':
return 'ban';
default:
checkExhaustive(type);
return '';
}
};
const isDataEmpty = (schema: Schema | null) => { const getIconBySchemaType = (type: Schema['type']): string => icons[type];
if (!schema) return true;
const isDataEmpty = (schema: Schema) => {
// Utilize the generated schema instead of looping over the entire data again // Utilize the generated schema instead of looping over the entire data again
// The schema for empty data is { type: 'object' | 'array', value: [] } // The schema for empty data is { type: 'object' | 'array', value: [] }
const isObjectOrArray = schema.type === 'object' || schema.type === 'array'; const isObjectOrArray = schema.type === 'object' || schema.type === 'array';
@ -324,9 +310,9 @@ export const useFlattenSchema = () => {
type: 'item', type: 'item',
}, },
]; ];
} else {
return [];
} }
return [];
}; };
const flattenMultipleSchemas = (nodes: SchemaNode[], additionalInfo: (node: INodeUi) => string) => const flattenMultipleSchemas = (nodes: SchemaNode[], additionalInfo: (node: INodeUi) => string) =>