5dfcc413cf
- Fix Tablist style - Fix dropdown style (wrong grey background) - Update dropdown variable when no outputSchema is available https://github.com/user-attachments/assets/56698fe8-8dd3-404a-b2b2-f1eca6f5fa28
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { BaseOutputSchema } from '@/workflow/search-variables/types/StepOutputSchema';
|
|
import { isObject } from '@sniptt/guards';
|
|
import { InputSchemaPropertyType } from '@/workflow/types/InputSchema';
|
|
import { isDefined } from 'twenty-ui';
|
|
|
|
const getValueType = (value: any): InputSchemaPropertyType => {
|
|
if (!isDefined(value) || value === null) {
|
|
return 'unknown';
|
|
}
|
|
if (typeof value === 'string') {
|
|
return 'string';
|
|
}
|
|
if (typeof value === 'number') {
|
|
return 'number';
|
|
}
|
|
if (typeof value === 'boolean') {
|
|
return 'boolean';
|
|
}
|
|
if (Array.isArray(value)) {
|
|
return 'array';
|
|
}
|
|
if (isObject(value)) {
|
|
return 'object';
|
|
}
|
|
return 'unknown';
|
|
};
|
|
|
|
export const getFunctionOutputSchema = (testResult: object) => {
|
|
return testResult
|
|
? Object.entries(testResult).reduce(
|
|
(acc: BaseOutputSchema, [key, value]) => {
|
|
if (isObject(value) && !Array.isArray(value)) {
|
|
acc[key] = {
|
|
isLeaf: false,
|
|
icon: 'IconVariable',
|
|
value: getFunctionOutputSchema(value),
|
|
};
|
|
} else {
|
|
acc[key] = {
|
|
isLeaf: true,
|
|
value,
|
|
type: getValueType(value),
|
|
icon: 'IconVariable',
|
|
};
|
|
}
|
|
return acc;
|
|
},
|
|
{},
|
|
)
|
|
: {};
|
|
};
|