11<script setup lang="ts">
22import type { TableColumn } from ' @nuxt/ui'
3- import type { RowSelectionState , VisibilityState } from ' @tanstack/vue-table'
3+ import type { RowSelectionState } from ' @tanstack/vue-table'
44
5- import { ItemParam , ItemTableMedia } from ' #components'
5+ import { AppCoin , ItemParam , ItemTableMedia } from ' #components'
66
77import type { CompareItemsResult , ItemFlat } from ' ~/models/item'
8- import type { AggregationConfig , AggregationOptions } from ' ~/services/item-search-service/aggregations'
8+ import type { AggregationConfig } from ' ~/services/item-search-service/aggregations'
99
1010import { ITEM_COMPARE_MODE } from ' ~/models/item'
11+ import { getColumnVisibility } from ' ~/services/item-search-service'
1112
1213const {
1314 items,
1415 aggregationConfig,
15- withHeader = false ,
1616 compareItemsResult,
1717 loading = false ,
1818 currentRank,
19- withFiller = true ,
2019} = defineProps <{
2120 items: ItemFlat []
2221 aggregationConfig: AggregationConfig
2322 compareItemsResult: CompareItemsResult
2423 loading? : boolean
25- withHeader? : boolean
26- withFiller? : boolean // offset
2724 currentRank? : number
2825}>()
2926
30- const { t } = useI18n ()
27+ const { t, n } = useI18n ()
3128
32- function createTableColumn(key : keyof ItemFlat , options : AggregationOptions ): TableColumn <ItemFlat > {
33- const widthPx = options .width || 160
29+ function createTableColumn(key : keyof ItemFlat ): TableColumn <ItemFlat > {
3430 return {
3531 accessorKey: key ,
36- meta: {
37- style: {
38- th: {
39- width: ` ${widthPx }px ` ,
40- },
41- td: {
42- width: ` ${widthPx }px ` ,
43- },
44- },
45- },
4632 header : ({ header }) => t (` item.aggregations.${header .id }.title ` ),
4733 cell : ({ row }) => h (ItemParam , {
4834 field: key ,
4935 item: row .original ,
5036 isCompare: true ,
5137 compareMode: ITEM_COMPARE_MODE .Relative ,
5238 relativeValue: compareItemsResult [key ]! ,
39+ }, {
40+ ... (key === ' upkeep' && { default : ({ rawBuckets }: { rawBuckets: number }) => h (AppCoin , { value: t (' item.format.upkeep' , { upkeep: n (rawBuckets ) }) }) }),
41+ ... (key === ' price' && { default : ({ rawBuckets }: { rawBuckets: number }) => h (AppCoin , { value: rawBuckets }) }),
5342 }),
5443 }
5544}
5645
5746const columns = computed <TableColumn <ItemFlat >[]>(() => [
58- ... (withFiller
59- ? [
60- {
61- id: ' fill' ,
62- meta: {
63- class: {
64- td: ' px-0 w-[32px]' ,
65- th: ' px-0 w-[32px]' ,
66- },
67- },
68- },
69- {
70- id: ' fill2' ,
71- meta: {
72- class: {
73- td: ' px-0 w-[32px]' ,
74- th: ' px-0 w-[32px]' ,
75- },
76- },
77- },
78- ]
79- : []),
8047 {
8148 accessorKey: ' name' ,
8249 header: ' ' ,
@@ -85,19 +52,10 @@ const columns = computed<TableColumn<ItemFlat>[]>(() => [
8552 showTier: true ,
8653 }),
8754 },
88- ... Object . entries (aggregationConfig ).map (([ key , config ]) => createTableColumn ( key as keyof ItemFlat , config ) ),
55+ ... objectKeys (aggregationConfig ).map (createTableColumn ),
8956])
9057
91- const columnVisibility = computed <VisibilityState >(() => {
92- return {
93- ... Object .entries (aggregationConfig )
94- .filter (([_ , value ]) => value .hidden )
95- .reduce ((out , [key ]) => {
96- out [key ] = false
97- return out
98- }, {} as VisibilityState ),
99- }
100- })
58+ const columnVisibility = computed (() => getColumnVisibility (aggregationConfig ))
10159
10260const rowSelection = ref <RowSelectionState >({
10361 ... (currentRank !== undefined && {
@@ -115,9 +73,6 @@ const rowSelection = ref<RowSelectionState>({
11573 :columns
11674 :ui =" {
11775 root: ' overflow-visible' ,
118- ... (! withHeader && {
119- thead: ' hidden' ,
120- }),
12176 } "
12277 >
12378 <template #empty >
0 commit comments