Select full record in variable dropdown (#8851)
Output schema is now separated in two sections: - object, that gather all informations on the selectable object - fields, that display object fields in a record context, or simply the available fields from the previous steps The dropdown variable has now a new mode: - if objectNameSingularToSelect is defined, it goes into an object mode. Only objects of the right type will be shown - if not set, it will use the already existing mode, to select a field When an object is selected, it actually set the id of the object https://github.com/user-attachments/assets/1c95f8fd-10f0-4c1c-aeb7-c7d847e89536
This commit is contained in:
+22
-11
@@ -2,13 +2,13 @@ import { v4 } from 'uuid';
|
||||
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { BaseOutputSchema } from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import { generateFakeObjectRecord } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record';
|
||||
import { OutputSchema } from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
|
||||
export const generateFakeObjectRecordEvent = (
|
||||
objectMetadataEntity: ObjectMetadataEntity,
|
||||
action: DatabaseEventAction,
|
||||
): OutputSchema => {
|
||||
): BaseOutputSchema => {
|
||||
const recordId = v4();
|
||||
const userId = v4();
|
||||
const workspaceMemberId = v4();
|
||||
@@ -16,23 +16,30 @@ export const generateFakeObjectRecordEvent = (
|
||||
const after = generateFakeObjectRecord(objectMetadataEntity);
|
||||
const formattedObjectMetadataEntity = Object.entries(
|
||||
objectMetadataEntity,
|
||||
).reduce((acc: OutputSchema, [key, value]) => {
|
||||
).reduce((acc: BaseOutputSchema, [key, value]) => {
|
||||
acc[key] = { isLeaf: true, value };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const baseResult: OutputSchema = {
|
||||
recordId: { isLeaf: true, type: 'string', value: recordId },
|
||||
userId: { isLeaf: true, type: 'string', value: userId },
|
||||
const baseResult: BaseOutputSchema = {
|
||||
recordId: {
|
||||
isLeaf: true,
|
||||
type: 'string',
|
||||
value: recordId,
|
||||
label: 'Record ID',
|
||||
},
|
||||
userId: { isLeaf: true, type: 'string', value: userId, label: 'User ID' },
|
||||
workspaceMemberId: {
|
||||
isLeaf: true,
|
||||
type: 'string',
|
||||
value: workspaceMemberId,
|
||||
label: 'Workspace Member ID',
|
||||
},
|
||||
objectMetadata: {
|
||||
isLeaf: false,
|
||||
value: formattedObjectMetadataEntity,
|
||||
label: 'Object Metadata',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -41,7 +48,8 @@ export const generateFakeObjectRecordEvent = (
|
||||
...baseResult,
|
||||
properties: {
|
||||
isLeaf: false,
|
||||
value: { after: { isLeaf: false, value: after } },
|
||||
value: { after: { isLeaf: false, value: after, label: 'After' } },
|
||||
label: 'Properties',
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -54,9 +62,10 @@ export const generateFakeObjectRecordEvent = (
|
||||
properties: {
|
||||
isLeaf: false,
|
||||
value: {
|
||||
before: { isLeaf: false, value: before },
|
||||
after: { isLeaf: false, value: after },
|
||||
before: { isLeaf: false, value: before, label: 'Before' },
|
||||
after: { isLeaf: false, value: after, label: 'After' },
|
||||
},
|
||||
label: 'Properties',
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -67,8 +76,9 @@ export const generateFakeObjectRecordEvent = (
|
||||
properties: {
|
||||
isLeaf: false,
|
||||
value: {
|
||||
before: { isLeaf: false, value: before },
|
||||
before: { isLeaf: false, value: before, label: 'Before' },
|
||||
},
|
||||
label: 'Properties',
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -79,8 +89,9 @@ export const generateFakeObjectRecordEvent = (
|
||||
properties: {
|
||||
isLeaf: false,
|
||||
value: {
|
||||
before: { isLeaf: false, value: before },
|
||||
before: { isLeaf: false, value: before, label: 'Before' },
|
||||
},
|
||||
label: 'Properties',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+60
-34
@@ -1,40 +1,66 @@
|
||||
import { compositeTypeDefinitions } from 'src/engine/metadata-modules/field-metadata/composite-types';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { generateFakeValue } from 'src/engine/utils/generate-fake-value';
|
||||
import {
|
||||
Leaf,
|
||||
Node,
|
||||
RecordOutputSchema,
|
||||
} from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import { shouldGenerateFieldFakeValue } from 'src/modules/workflow/workflow-builder/utils/should-generate-field-fake-value';
|
||||
import { OutputSchema } from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import { compositeTypeDefinitions } from 'src/engine/metadata-modules/field-metadata/composite-types';
|
||||
import { camelToTitleCase } from 'src/utils/camel-to-title-case';
|
||||
|
||||
const generateObjectRecordFields = (
|
||||
objectMetadataEntity: ObjectMetadataEntity,
|
||||
) =>
|
||||
objectMetadataEntity.fields.reduce(
|
||||
(acc: Record<string, Leaf | Node>, field) => {
|
||||
if (!shouldGenerateFieldFakeValue(field)) {
|
||||
return acc;
|
||||
}
|
||||
const compositeType = compositeTypeDefinitions.get(field.type);
|
||||
|
||||
if (!compositeType) {
|
||||
acc[field.name] = {
|
||||
isLeaf: true,
|
||||
type: field.type,
|
||||
icon: field.icon,
|
||||
label: field.label,
|
||||
value: generateFakeValue(field.type),
|
||||
};
|
||||
} else {
|
||||
acc[field.name] = {
|
||||
isLeaf: false,
|
||||
icon: field.icon,
|
||||
label: field.label,
|
||||
value: compositeType.properties.reduce((acc, property) => {
|
||||
acc[property.name] = {
|
||||
isLeaf: true,
|
||||
type: property.type,
|
||||
label: camelToTitleCase(property.name),
|
||||
value: generateFakeValue(property.type),
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
export const generateFakeObjectRecord = (
|
||||
objectMetadataEntity: ObjectMetadataEntity,
|
||||
): OutputSchema =>
|
||||
objectMetadataEntity.fields.reduce((acc: OutputSchema, field) => {
|
||||
if (!shouldGenerateFieldFakeValue(field)) {
|
||||
return acc;
|
||||
}
|
||||
const compositeType = compositeTypeDefinitions.get(field.type);
|
||||
|
||||
if (!compositeType) {
|
||||
acc[field.name] = {
|
||||
isLeaf: true,
|
||||
type: field.type,
|
||||
icon: field.icon,
|
||||
value: generateFakeValue(field.type),
|
||||
};
|
||||
} else {
|
||||
acc[field.name] = {
|
||||
isLeaf: false,
|
||||
icon: field.icon,
|
||||
value: compositeType.properties.reduce((acc, property) => {
|
||||
acc[property.name] = {
|
||||
isLeaf: true,
|
||||
type: property.type,
|
||||
value: generateFakeValue(property.type),
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
): RecordOutputSchema => ({
|
||||
object: {
|
||||
isLeaf: true,
|
||||
icon: objectMetadataEntity.icon,
|
||||
label: objectMetadataEntity.labelSingular,
|
||||
value: objectMetadataEntity.description,
|
||||
nameSingular: objectMetadataEntity.nameSingular,
|
||||
fieldIdName: 'id',
|
||||
},
|
||||
fields: generateObjectRecordFields(objectMetadataEntity),
|
||||
_outputSchemaType: 'RECORD',
|
||||
});
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
||||
|
||||
export const shouldGenerateFieldFakeValue = (field: FieldMetadataEntity) => {
|
||||
return (
|
||||
!field.isSystem &&
|
||||
(!field.isSystem || field.name === 'id') &&
|
||||
field.isActive &&
|
||||
field.type !== FieldMetadataType.RELATION
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user