Use rv-screen column.display for table header labels
This commit is contained in:
parent
78987a6066
commit
d05fa0cb2c
@ -85,9 +85,30 @@ interface Props {
|
||||
toolbarAction?: React.ReactNode;
|
||||
}
|
||||
|
||||
// Walks the rv-screen layout to find the rv_table element and returns a
|
||||
// key_name → display map for column header labels (the recordview response's
|
||||
// output_label is empty for v2 envelope screens).
|
||||
function extractColumnLabels(layout: any): Record<string, string> {
|
||||
const out: Record<string, string> = {};
|
||||
const walk = (nodes: any[]): void => {
|
||||
for (const n of nodes ?? []) {
|
||||
const cfg = n?.config;
|
||||
if (cfg?.type === "rv_table" && Array.isArray(cfg.columns)) {
|
||||
for (const c of cfg.columns) {
|
||||
if (c?.key_name && c?.display) out[c.key_name] = c.display;
|
||||
}
|
||||
}
|
||||
if (Array.isArray(n?.children)) walk(n.children);
|
||||
}
|
||||
};
|
||||
walk(Array.isArray(layout) ? layout : []);
|
||||
return out;
|
||||
}
|
||||
|
||||
export default function RecordViewTable({ viewId, onRowClick, toolbarAction }: Props) {
|
||||
const navigate = useNavigate();
|
||||
const [rvTemplateUid, setRvTemplateUid] = useState<string | null>(null);
|
||||
const [columnLabels, setColumnLabels] = useState<Record<string, string>>({});
|
||||
const [fields, setFields] = useState<RecordViewField[]>([]);
|
||||
const [rows, setRows] = useState<Record<string, unknown>[]>([]);
|
||||
const [pagination, setPagination] = useState({ page: 1, limit: 10, total_count: 0, total_pages: 0 });
|
||||
@ -102,8 +123,12 @@ export default function RecordViewTable({ viewId, onRowClick, toolbarAction }: P
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
setRvTemplateUid(null);
|
||||
setColumnLabels({});
|
||||
getRVScreen(viewId)
|
||||
.then((rv) => setRvTemplateUid(rv.rv_template_uid))
|
||||
.then((rv) => {
|
||||
setColumnLabels(extractColumnLabels(rv.layout));
|
||||
setRvTemplateUid(rv.rv_template_uid);
|
||||
})
|
||||
.catch((err) => { setError(err.message); setLoading(false); });
|
||||
}, [viewId]);
|
||||
|
||||
@ -262,7 +287,7 @@ export default function RecordViewTable({ viewId, onRowClick, toolbarAction }: P
|
||||
`}
|
||||
>
|
||||
<span className="inline-flex items-center gap-1">
|
||||
{f.output_label}
|
||||
{columnLabels[f.field_key] || f.output_label || f.field_key}
|
||||
{isSorted
|
||||
? (query.sort_dir === "asc"
|
||||
? <ArrowUp size={11} className="text-rose-500" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user