import { defineComponent, withApiName, type ComponentDefinition } from './component'; import { fieldReferences, manifestObject, manifestField, type ObjectReference, type DefinitionFieldReference, } from './custom-object'; import { ListViewDef, type ListViewDefProps } from '../list-view'; export type DefineListViewProps = Omit< ListViewDefProps, 'viewId' | 'apiName' | 'fields' | 'orderBy' > & { apiName: string; fields: readonly NoInfer>[]; orderBy?: NoInfer>; }; export function defineListView( object: TObject, props: DefineListViewProps, ): ListViewDef { const { fields, orderBy, ...rest } = props; return listViewComponent.register( withApiName( new ListViewDef(manifestObject(object), { ...rest, viewId: rest.apiName, fields: fields.map((field) => manifestField(object, field)), ...(orderBy != null ? { orderBy: manifestField(object, orderBy) } : {}), }), rest.apiName, ), object, props, ); } const listViewComponent: ComponentDefinition = defineComponent({ type: 'CUSTOM_OBJECT_LIST_VIEW', define: defineListView, references: (_definition, object, props) => [ object, ...props.fields.flatMap((field) => fieldReferences(object, field)), ...(props.orderBy == null ? [] : fieldReferences(object, props.orderBy)), ], });