|
27 | 27 | </div> |
28 | 28 | <template v-if="numValsAllowed"> |
29 | 29 | <VDropdown |
30 | | - v-for="(item, i) in new Array(numValsAllowed).fill()" |
| 30 | + v-for="(_, i) in Array.from({ length: numValsAllowed })" |
31 | 31 | :key="i" |
32 | 32 | :options="valsOptions" |
33 | 33 | :value="vals[i]" |
|
38 | 38 | </td> |
39 | 39 | </template> |
40 | 40 |
|
41 | | -<script setup> |
| 41 | +<script setup lang="ts"> |
42 | 42 | import { computed } from 'vue' |
43 | 43 | import VDropdown from './VDropdown.vue' |
| 44 | +import type { AggregatorTemplate } from '@/helper/utilities' |
44 | 45 |
|
45 | | -const emit = defineEmits([ |
46 | | - 'update:aggregatorName', |
47 | | - 'update:rowOrder', |
48 | | - 'update:colOrder', |
49 | | - 'update:vals' |
50 | | -]) |
51 | | -const props = defineProps({ |
52 | | - aggregatorItems: { |
53 | | - type: Object, |
54 | | - default: () => ({}) |
55 | | - }, |
56 | | - aggregatorName: { |
57 | | - type: String, |
58 | | - default: 'Count' |
59 | | - }, |
60 | | - rowOrder: { |
61 | | - type: String, |
62 | | - default: 'key_a_to_z', |
63 | | - validator: function (value) { |
64 | | - return ( |
65 | | - ['key_a_to_z', 'value_a_to_z', 'value_z_to_a'].indexOf(value) !== -1 |
66 | | - ) |
67 | | - } |
68 | | - }, |
69 | | - colOrder: { |
70 | | - type: String, |
71 | | - default: 'key_a_to_z', |
72 | | - validator: function (value) { |
73 | | - return ( |
74 | | - ['key_a_to_z', 'value_a_to_z', 'value_z_to_a'].indexOf(value) !== -1 |
75 | | - ) |
76 | | - } |
77 | | - }, |
78 | | - vals: { |
79 | | - type: Array, |
80 | | - default: function () { |
81 | | - return [] |
82 | | - } |
83 | | - }, |
84 | | - attributeNames: { |
85 | | - type: Array, |
86 | | - default: () => [] |
87 | | - }, |
88 | | - hiddenFromAggregators: { |
89 | | - type: Array, |
90 | | - default: () => [] |
91 | | - } |
| 46 | +const emit = defineEmits<{ |
| 47 | + (event: 'update:aggregatorName', value: string): void |
| 48 | + (event: 'update:rowOrder', value: string): void |
| 49 | + (event: 'update:colOrder', value: string): void |
| 50 | + (event: 'update:vals', value: string[]): void |
| 51 | +}>() |
| 52 | +
|
| 53 | +type OrderType = 'key_a_to_z' | 'value_a_to_z' | 'value_z_to_a' |
| 54 | +
|
| 55 | +interface AggregatorCellProps { |
| 56 | + aggregatorItems: Record<string, AggregatorTemplate> |
| 57 | + aggregatorName: string |
| 58 | + rowOrder: OrderType |
| 59 | + colOrder: OrderType |
| 60 | + vals: string[] |
| 61 | + attributeNames: string[] |
| 62 | + hiddenFromAggregators: string[] |
| 63 | +} |
| 64 | +
|
| 65 | +const props = withDefaults(defineProps<AggregatorCellProps>(), { |
| 66 | + aggregatorItems: () => ({}), |
| 67 | + aggregatorName: 'Count', |
| 68 | + rowOrder: 'key_a_to_z', |
| 69 | + colOrder: 'key_a_to_z', |
| 70 | + vals: () => [], |
| 71 | + attributeNames: () => [], |
| 72 | + hiddenFromAggregators: () => [] |
92 | 73 | }) |
93 | | -const sortIcons = { |
| 74 | +
|
| 75 | +const sortIcons: Record< |
| 76 | + OrderType, |
| 77 | + { rowSymbol: string; colSymbol: string; next: OrderType } |
| 78 | +> = { |
94 | 79 | key_a_to_z: { rowSymbol: '↕', colSymbol: '↔', next: 'value_a_to_z' }, |
95 | 80 | value_a_to_z: { rowSymbol: '↓', colSymbol: '→', next: 'value_z_to_a' }, |
96 | 81 | value_z_to_a: { rowSymbol: '↑', colSymbol: '←', next: 'key_a_to_z' } |
97 | | -} |
| 82 | +} as const |
| 83 | +
|
98 | 84 | const aggregatorOptions = computed(() => Object.keys(props.aggregatorItems)) |
99 | 85 | const valsOptions = computed(() => |
100 | 86 | props.attributeNames.filter( |
101 | 87 | (item) => !props.hiddenFromAggregators.includes(item) |
102 | 88 | ) |
103 | 89 | ) |
104 | | -const numValsAllowed = computed( |
105 | | - () => props.aggregatorItems[props.aggregatorName]([])().numInputs || 0 |
106 | | -) |
| 90 | +const numValsAllowed = computed(() => { |
| 91 | + const aggregator = props.aggregatorItems[props.aggregatorName] |
| 92 | + if (!aggregator) return 0 |
| 93 | + const aggregatorInstance = aggregator([])?.() |
| 94 | + return aggregatorInstance?.numInputs || 0 |
| 95 | +}) |
| 96 | +
|
107 | 97 | const currentRowSortIcon = computed(() => sortIcons[props.rowOrder].rowSymbol) |
108 | 98 | const currentColSortIcon = computed(() => sortIcons[props.colOrder].colSymbol) |
109 | | -const updateAggregatorName = (value) => emit('update:aggregatorName', value) |
| 99 | +
|
| 100 | +const updateAggregatorName = (value: string) => |
| 101 | + emit('update:aggregatorName', value) |
110 | 102 | const updateRowOrder = () => |
111 | 103 | emit('update:rowOrder', sortIcons[props.rowOrder].next) |
112 | 104 | const updateColOrder = () => |
113 | 105 | emit('update:colOrder', sortIcons[props.colOrder].next) |
114 | | -const updateVals = (val, i) => { |
| 106 | +const updateVals = (val: string, i: number) => { |
115 | 107 | const newVals = [...props.vals] |
116 | 108 | newVals[i] = val |
117 | 109 | emit('update:vals', newVals) |
|
0 commit comments