Use AI assistant to create records in the system, added configurable list views

This commit is contained in:
Francisco Gaona
2026-01-31 03:24:46 +01:00
parent 20fc90a3fb
commit f68321c802
18 changed files with 3310 additions and 142 deletions

View File

@@ -20,6 +20,9 @@ export const useFields = () => {
// Hide system fields and auto-generated fields on edit
const shouldHideOnEdit = isSystemField || isAutoGeneratedField
// Hide 'id' field from list view by default (check both apiName and id field)
const shouldHideOnList = fieldDef.apiName === 'id' || fieldDef.label === 'Id' || fieldDef.label === 'ID'
return {
id: fieldDef.id,
apiName: fieldDef.apiName,
@@ -37,7 +40,7 @@ export const useFields = () => {
validationRules: fieldDef.validationRules || [],
// View options - only hide system and auto-generated fields by default
showOnList: fieldDef.showOnList ?? true,
showOnList: fieldDef.showOnList ?? !shouldHideOnList,
showOnDetail: fieldDef.showOnDetail ?? true,
showOnEdit: fieldDef.showOnEdit ?? !shouldHideOnEdit,
sortable: fieldDef.sortable ?? true,
@@ -67,12 +70,36 @@ export const useFields = () => {
/**
* Build a ListView configuration from object definition
* @param objectDef - The object definition containing fields
* @param customConfig - Optional custom configuration
* @param listLayoutConfig - Optional list view layout configuration from page_layouts
*/
const buildListViewConfig = (
objectDef: any,
customConfig?: Partial<ListViewConfig>
customConfig?: Partial<ListViewConfig>,
listLayoutConfig?: { fields: Array<{ fieldId: string; order?: number }> } | null
): ListViewConfig => {
const fields = objectDef.fields?.map(mapFieldDefinitionToConfig) || []
let fields = objectDef.fields?.map(mapFieldDefinitionToConfig) || []
// If a list layout is provided, filter and order fields according to it
if (listLayoutConfig && listLayoutConfig.fields && listLayoutConfig.fields.length > 0) {
// Sort layout fields by order
const sortedLayoutFields = [...listLayoutConfig.fields].sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
// Map layout fields to actual field configs, preserving order
const orderedFields: FieldConfig[] = []
for (const layoutField of sortedLayoutFields) {
const fieldConfig = fields.find((f: FieldConfig) => f.id === layoutField.fieldId)
if (fieldConfig) {
orderedFields.push(fieldConfig)
}
}
// Use ordered fields if we found any, otherwise fall back to all fields
if (orderedFields.length > 0) {
fields = orderedFields
}
}
return {
objectApiName: objectDef.apiName,

View File

@@ -1,11 +1,13 @@
import type { PageLayout, CreatePageLayoutRequest, UpdatePageLayoutRequest } from '~/types/page-layout'
import type { PageLayout, CreatePageLayoutRequest, UpdatePageLayoutRequest, PageLayoutType } from '~/types/page-layout'
export const usePageLayouts = () => {
const { api } = useApi()
const getPageLayouts = async (objectId?: string) => {
const getPageLayouts = async (objectId?: string, layoutType?: PageLayoutType) => {
try {
const params = objectId ? { objectId } : {}
const params: Record<string, string> = {}
if (objectId) params.objectId = objectId
if (layoutType) params.layoutType = layoutType
const response = await api.get('/page-layouts', { params })
return response
} catch (error) {
@@ -24,9 +26,11 @@ export const usePageLayouts = () => {
}
}
const getDefaultPageLayout = async (objectId: string) => {
const getDefaultPageLayout = async (objectId: string, layoutType: PageLayoutType = 'detail') => {
try {
const response = await api.get(`/page-layouts/default/${objectId}`)
const response = await api.get(`/page-layouts/default/${objectId}`, {
params: { layoutType }
})
return response
} catch (error) {
console.error('Error fetching default page layout:', error)