overrides for customisation
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<string, FieldOverride>;
|
||||
}
|
||||
import { ResourceOverride } from "./utils/overrides";
|
||||
|
||||
export const configuration: Record<string, ResourceOverride> = {
|
||||
expenses: {
|
||||
@@ -19,13 +7,14 @@ export const configuration: Record<string, ResourceOverride> = {
|
||||
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<string, ResourceOverride> = {
|
||||
};
|
||||
return `${day}${suffix(day)} ${month} ${year}`;
|
||||
}
|
||||
},
|
||||
created_at: {
|
||||
display: false
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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<AppConfig>
|
||||
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),
|
||||
});
|
||||
}
|
||||
|
||||
14
src_generic/utils/overrides.ts
Normal file
14
src_generic/utils/overrides.ts
Normal 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>;
|
||||
}
|
||||
Reference in New Issue
Block a user