overrides for customisation

This commit is contained in:
2026-04-01 19:24:09 +05:30
parent 44567496a1
commit 6dc33be455
4 changed files with 38 additions and 29 deletions

View File

@@ -33,6 +33,7 @@ export default function GenericForm({
onCancel, onCancel,
loading: saving, loading: saving,
}: GenericFormProps) { }: GenericFormProps) {
initialData = initialData || {};
const [formData, setFormData] = React.useState(initialData); const [formData, setFormData] = React.useState(initialData);
const { uploadFile, uploading } = useUpload(); const { uploadFile, uploading } = useUpload();
const appConfig = React.useContext(ConfigContext); const appConfig = React.useContext(ConfigContext);

View File

@@ -1,16 +1,4 @@
/** import { ResourceOverride } from "./utils/overrides";
* 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<string, FieldOverride>;
}
export const configuration: Record<string, ResourceOverride> = { export const configuration: Record<string, ResourceOverride> = {
expenses: { expenses: {
@@ -19,13 +7,14 @@ export const configuration: Record<string, ResourceOverride> = {
displayField: "name", displayField: "name",
}, },
payor: { payor: {
display: false,
displayField: "username", displayField: "username",
}, },
account: { account: {
displayField: "nickname", displayField: "nickname",
}, },
tags: { tags: {
displayField: "name", displayField: "icon",
}, },
occurred_at: { occurred_at: {
formatter: (val: string) => { formatter: (val: string) => {
@@ -44,6 +33,9 @@ export const configuration: Record<string, ResourceOverride> = {
}; };
return `${day}${suffix(day)} ${month} ${year}`; return `${day}${suffix(day)} ${month} ${year}`;
} }
},
created_at: {
display: false
} }
}, },
}, },

View File

@@ -51,6 +51,8 @@ function parseSchemaFields(
const type = mapOpenApiType(prop); const type = mapOpenApiType(prop);
const override = overrides[key]; const override = overrides[key];
console.log("key", key, "type", type, "prop", prop, "override", override);
if (key !== "id" && override?.display !== false) {
fields[key] = { fields[key] = {
type, type,
label: label:
@@ -60,11 +62,11 @@ function parseSchemaFields(
options: prop.enum, options: prop.enum,
readOnly: readOnly:
prop.readOnly || prop.readOnly ||
key === "id" ||
key === "created_at" || key === "created_at" ||
key === "updated_at", key === "updated_at",
...override, ...override,
}; };
} else continue;
// Schema-based Relation Detection // Schema-based Relation Detection
// If it's an object/string and matches a resource name, it might be a relation // 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<AppConfig>
label: schema.title || label, label: schema.title || label,
pluralLabel: pluralLabel, pluralLabel: pluralLabel,
endpoint: listPath, 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), fields: parseSchemaFields(schema, name, allResourceNames),
}); });
} }

View File

@@ -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<string, FieldOverride>;
}