Adding types au List Schemas
This commit is contained in:
@@ -2,6 +2,7 @@ import { RJSFSchema } from '@rjsf/utils';
|
||||
import i18n from '../../../i18n'
|
||||
import { JSONSchema7Definition } from "json-schema";
|
||||
import { GridColDef } from "@mui/x-data-grid";
|
||||
import { GridColType } from "@mui/x-data-grid/models/colDef/gridColType";
|
||||
|
||||
const API_URL = "/api/v1";
|
||||
|
||||
@@ -120,20 +121,34 @@ function buildColumns (rawSchemas: RJSFSchema, resourceName: string, prefix: str
|
||||
const subresourceName = get_reference_name(prop.items);
|
||||
result = result.concat(buildColumns(rawSchemas, subresourceName, prefix ? `${prefix}.${prop_name}` : prop_name))
|
||||
} else {
|
||||
let column: GridColDef = {
|
||||
field: prefix ? `${prefix}.${prop_name}` : prop_name,
|
||||
headerName: i18n.t(`schemas.${shortResourceName}.${convertCamelToSnake(prop_name)}`, prop.title) as string,
|
||||
valueGetter: (value: any, row: any ) => {
|
||||
if (prefix === undefined) {
|
||||
return value;
|
||||
let valueGetter: undefined|((value: any, row: any) => any) = undefined;
|
||||
let type: GridColType = "string";
|
||||
if (is_array(prop)) {
|
||||
valueGetter = (value: any[], row: any ) => {
|
||||
return value.concat(".");
|
||||
}
|
||||
|
||||
} else if (prefix !== undefined) {
|
||||
valueGetter = (value: any, row: any ) => {
|
||||
let parent = row;
|
||||
for (const column of prefix.split(".")) {
|
||||
parent = parent[column];
|
||||
for (const col of prefix.split(".")) {
|
||||
parent = parent[col];
|
||||
}
|
||||
return parent ? parent[prop_name] : "";
|
||||
}
|
||||
} else {
|
||||
if (prop.type == "string" && prop.format == "date-time") {
|
||||
type = "dateTime"
|
||||
valueGetter = (value: string) => new Date(value)
|
||||
}
|
||||
}
|
||||
if (prop.type == "string" && prop.format == "date-time") {
|
||||
|
||||
}
|
||||
const column: GridColDef = {
|
||||
field: prefix ? `${prefix}.${prop_name}` : prop_name,
|
||||
headerName: i18n.t(`schemas.${shortResourceName}.${convertCamelToSnake(prop_name)}`, prop.title) as string,
|
||||
type: type,
|
||||
valueGetter: valueGetter
|
||||
}
|
||||
result.push(column);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user