mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
public commit
This commit is contained in:
51
app/src/ui/modules/data/components/EntityTable2.tsx
Normal file
51
app/src/ui/modules/data/components/EntityTable2.tsx
Normal 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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user