Closed johnrake-betablox closed 1 month ago
Handled with discriminate union types
export type AdminAttributeType =
// Basic types with no additional properties
| {
name: string;
type:
| AdminFieldType.STRING
| AdminFieldType.TEXT
| AdminFieldType.PASSWORD
| AdminFieldType.BOOLEAN
| AdminFieldType.INTEGER
| AdminFieldType.JSON
| AdminFieldType.DATETIME;
}
// Select type with options
| {
name: string;
type: AdminFieldType.SELECT;
options: SelectOption[]; // Required for the SELECT type
}
// Has One relationship
| {
name: string;
type: AdminFieldType.RELATIONSHIP_HAS_ONE;
modelName: string; // The related model's name
sourceKey: string; // The field in the related model
relatedAttributes?: RelatedAttribute[];
}
// Has Many relationship
| {
name: string;
type: AdminFieldType.RELATIONSHIP_HAS_MANY;
modelName: string; // The related model's name
relationField: string; // The field in the related model
relatedAttributes?: RelatedAttribute[];
};