public commit

This commit is contained in:
dswbx
2024-11-16 12:01:47 +01:00
commit 90f80c4280
582 changed files with 49291 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
import type { Entity, EntityData } from "data";
import { CellValue, DataTable, type DataTableProps } from "ui/components/table/DataTable";
type EntityTableProps<Data extends EntityData = EntityData> = Omit<
DataTableProps<Data>,
"columns"
> & {
entity: Entity;
select?: string[];
};
export function EntityTable2({ entity, select, ...props }: EntityTableProps) {
const columns = select ?? entity.getSelect();
const fields = entity.getFields();
function getField(name: string) {
return fields.find((field) => field.name === name);
}
function renderHeader(column: string) {
try {
const field = getField(column)!;
return field.getLabel();
} catch (e) {
console.warn("Couldn't render header", { entity, select, ...props }, e);
return column;
}
}
function renderValue({ value, property }) {
let _value: any = value;
try {
const field = getField(property)!;
_value = field.getValue(value, "table");
} catch (e) {
console.warn("Couldn't render value", { value, property, entity, select, ...props }, e);
}
return <CellValue value={_value} property={property} />;
}
return (
<DataTable
{...props}
columns={columns}
renderHeader={renderHeader}
renderValue={renderValue}
/>
);
}