From 6dc33be4550be0ad010690beb0156ab3cac02eb8 Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Wed, 1 Apr 2026 19:24:09 +0530 Subject: [PATCH] overrides for customisation --- src_generic/components/GenericForm.tsx | 1 + src_generic/configuration.ts | 20 +++++----------- src_generic/utils/openapi_loader.ts | 32 ++++++++++++++------------ src_generic/utils/overrides.ts | 14 +++++++++++ 4 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 src_generic/utils/overrides.ts diff --git a/src_generic/components/GenericForm.tsx b/src_generic/components/GenericForm.tsx index 280446c..f860010 100644 --- a/src_generic/components/GenericForm.tsx +++ b/src_generic/components/GenericForm.tsx @@ -33,6 +33,7 @@ export default function GenericForm({ onCancel, loading: saving, }: GenericFormProps) { + initialData = initialData || {}; const [formData, setFormData] = React.useState(initialData); const { uploadFile, uploading } = useUpload(); const appConfig = React.useContext(ConfigContext); diff --git a/src_generic/configuration.ts b/src_generic/configuration.ts index da4dfa9..9e90e84 100644 --- a/src_generic/configuration.ts +++ b/src_generic/configuration.ts @@ -1,16 +1,4 @@ -/** - * This file contains application-specific overrides and configuration - * for the generic Admin Panel. - */ - -export interface FieldOverride { - displayField?: string; - formatter?: (value: any) => string; -} - -export interface ResourceOverride { - fields?: Record; -} +import { ResourceOverride } from "./utils/overrides"; export const configuration: Record = { expenses: { @@ -19,13 +7,14 @@ export const configuration: Record = { displayField: "name", }, payor: { + display: false, displayField: "username", }, account: { displayField: "nickname", }, tags: { - displayField: "name", + displayField: "icon", }, occurred_at: { formatter: (val: string) => { @@ -44,6 +33,9 @@ export const configuration: Record = { }; return `${day}${suffix(day)} ${month} ${year}`; } + }, + created_at: { + display: false } }, }, diff --git a/src_generic/utils/openapi_loader.ts b/src_generic/utils/openapi_loader.ts index 1dce7c5..6a64606 100644 --- a/src_generic/utils/openapi_loader.ts +++ b/src_generic/utils/openapi_loader.ts @@ -51,20 +51,22 @@ function parseSchemaFields( const type = mapOpenApiType(prop); const override = overrides[key]; - fields[key] = { - type, - label: - prop.title || - key.charAt(0).toUpperCase() + key.slice(1).replace(/_/g, " "), - required: required.includes(key), - options: prop.enum, - readOnly: - prop.readOnly || - key === "id" || - key === "created_at" || - key === "updated_at", - ...override, - }; + console.log("key", key, "type", type, "prop", prop, "override", override); + if (key !== "id" && override?.display !== false) { + fields[key] = { + type, + label: + prop.title || + key.charAt(0).toUpperCase() + key.slice(1).replace(/_/g, " "), + required: required.includes(key), + options: prop.enum, + readOnly: + prop.readOnly || + key === "created_at" || + key === "updated_at", + ...override, + }; + } else continue; // Schema-based Relation Detection // If it's an object/string and matches a resource name, it might be a relation @@ -148,7 +150,7 @@ export async function loadConfigFromOpenApi(baseUrl: string): Promise label: schema.title || label, pluralLabel: pluralLabel, endpoint: listPath, - primaryKey: "_id", // assume 'id' as default or look for 'required' + 'unique' + primaryKey: "id", // assume 'id' as default or look for 'required' + 'unique' fields: parseSchemaFields(schema, name, allResourceNames), }); } diff --git a/src_generic/utils/overrides.ts b/src_generic/utils/overrides.ts new file mode 100644 index 0000000..00cb060 --- /dev/null +++ b/src_generic/utils/overrides.ts @@ -0,0 +1,14 @@ +/** + * This file contains application-specific overrides and configuration + * for the generic Admin Panel. + */ + +export interface FieldOverride { + displayField?: string; + display?: boolean; + formatter?: (value: any) => string; +} + +export interface ResourceOverride { + fields?: Record; +}