overrides for customisation
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -51,20 +51,22 @@ function parseSchemaFields(
|
|||||||
const type = mapOpenApiType(prop);
|
const type = mapOpenApiType(prop);
|
||||||
const override = overrides[key];
|
const override = overrides[key];
|
||||||
|
|
||||||
fields[key] = {
|
console.log("key", key, "type", type, "prop", prop, "override", override);
|
||||||
type,
|
if (key !== "id" && override?.display !== false) {
|
||||||
label:
|
fields[key] = {
|
||||||
prop.title ||
|
type,
|
||||||
key.charAt(0).toUpperCase() + key.slice(1).replace(/_/g, " "),
|
label:
|
||||||
required: required.includes(key),
|
prop.title ||
|
||||||
options: prop.enum,
|
key.charAt(0).toUpperCase() + key.slice(1).replace(/_/g, " "),
|
||||||
readOnly:
|
required: required.includes(key),
|
||||||
prop.readOnly ||
|
options: prop.enum,
|
||||||
key === "id" ||
|
readOnly:
|
||||||
key === "created_at" ||
|
prop.readOnly ||
|
||||||
key === "updated_at",
|
key === "created_at" ||
|
||||||
...override,
|
key === "updated_at",
|
||||||
};
|
...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),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
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