columns.tsx
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { ColumnsType } from 'antd/es/table';
import type { StoreListingRow } from '@/api';
import type { StoreDictionaries } from '@/features/store/dictionaries';
import { dictionaryLabel, formatDateTime } from '@/features/store/formatters';
import { COLUMN_LABELS, type ListingColumn } from '../tools/listing';
export function buildColumns({
visible,
spec,
}: {
visible: ListingColumn[];
spec?: StoreDictionaries;
}): ColumnsType<StoreListingRow> {
const definitions: Record<ListingColumn, ColumnsType<StoreListingRow>[number]> = {
storeName: {
title: COLUMN_LABELS.storeName,
dataIndex: 'storeName',
key: 'storeName',
width: 230,
render: (value: string) => <span className="store-listing-name">{value || '—'}</span>,
},
merchantNo: {
title: COLUMN_LABELS.merchantNo,
dataIndex: 'merchantNo',
key: 'merchantNo',
width: 120,
render: (value: string) => <span className="store-code">{value || '—'}</span>,
},
businessScene: {
title: COLUMN_LABELS.businessScene,
dataIndex: 'businessScene',
key: 'businessScene',
width: 230,
render: (value: string) => (
<span className="store-listing-scene">{dictionaryLabel(spec?.businessScenes, value)}</span>
),
},
effectiveTime: {
title: COLUMN_LABELS.effectiveTime,
dataIndex: 'effectiveTime',
key: 'effectiveTime',
width: 130,
render: (value: string | null) => formatDateTime(value).split(' ')[0],
},
changeCount: {
title: COLUMN_LABELS.changeCount,
dataIndex: 'changeCount',
key: 'changeCount',
width: 90,
align: 'right',
render: (value: number | null | undefined) => value ?? '—',
},
};
return visible.map((column) => definitions[column]);
}