-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathBaseSimpleTable.vue
More file actions
253 lines (220 loc) · 6.25 KB
/
BaseSimpleTable.vue
File metadata and controls
253 lines (220 loc) · 6.25 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<template>
<div :class="['tabulator-container', 'tabulator-container--simple', { 'tabulator-container--editable': editable }]">
<RenderTable
ref="renderTable"
:tableJSON="computedTableJSON"
:editable="editable"
:hasValidValues="hasValidValues"
:questions="questions"
:validation="validation || validators"
@table-built="$emit('table-built')"
@row-click="(e, row) => $emit('row-click', e, row)"
@cell-edited="(cell) => $emit('cell-edited', cell)"
@updateValidValues="(value) => $emit('updateValidValues', value)"
/>
</div>
</template>
<script lang="ts">
import RenderTable from "~/components/base/base-render-table/RenderTable.vue";
import "tabulator-tables/dist/css/tabulator.min.css";
import { TableData } from "@/v1/domain/entities/table/TableData";
import { DataFrameSchema } from "@/v1/domain/entities/table/Schema";
import { Question } from "@/v1/domain/entities/question/Question";
import { Validators } from "@/v1/domain/entities/table/Validation";
export default {
name: "BaseSimpleTable",
components: {
RenderTable,
},
props: {
data: {
type: Array,
default: () => [],
},
columns: {
type: Array,
required: true,
},
options: {
type: Object,
default: () => ({}),
},
loading: {
type: Boolean,
default: false,
},
editable: {
type: Boolean,
default: false,
},
validation: {
type: Object,
default: null,
},
validators: {
type: Object as () => Validators,
default: null,
},
hasValidValues: {
type: Boolean,
default: false,
},
questions: {
type: Array as () => Question[],
default: () => [],
},
},
computed: {
// Convert simple data/columns to TableData format for RenderTable
computedTableJSON(): TableData {
// FIX 1: Use "...col" to preserve editor config (dropdowns), validators, and freezing
const fields = this.columns.map((col: any) => ({
name: col.field,
type: col.type || "string",
...col // <--- THIS IS THE MAGIC FIX
}));
const schema = new DataFrameSchema(
fields,
[],
null,
"simple-table"
);
const tableData = new TableData(
[...this.data] as any[],
schema,
null
);
// FIX 2: Handle both 'validation' and 'validators' props
// ImportFileUpload passes :validators, so we must prioritize that.
if (this.validators) {
// We wrap it in a structure RenderTable understands
tableData.validation = { columns: {}, ...this.validation };
// We might need to pass this directly to the RenderTable prop instead,
// but attaching it to tableData is the safest way for the Schema to know about it.
} else if (this.validation) {
tableData.validation = this.validation;
}
return tableData;
},
},
methods: {
// Public API methods - delegate to internal RenderTable's tabulator
getInternalTabulator() {
return this.$refs.renderTable?.tabulator;
},
getData() {
const tabulator = this.getInternalTabulator();
return tabulator ? tabulator.getData() : [];
},
setData(data: any[]) {
const tabulator = this.getInternalTabulator();
if (tabulator) {
return tabulator.setData(data);
}
return Promise.resolve();
},
getRowCount() {
const tabulator = this.getInternalTabulator();
return tabulator ? tabulator.getDataCount() : 0;
},
getColumns() {
const tabulator = this.getInternalTabulator();
return tabulator ? tabulator.getColumns() : [];
},
validateTable(options?: { scrollToError?: boolean; saveData?: boolean }) {
if (this.$refs.renderTable?.validateTable) {
return this.$refs.renderTable.validateTable(options);
}
return true;
},
redraw(force?: boolean) {
const tabulator = this.getInternalTabulator();
if (tabulator) {
tabulator.redraw(force);
}
},
},
};
</script>
<style lang="scss">
// Styles for BaseSimpleTable wrapping RenderTable
.tabulator-container--simple {
display: flex;
flex-flow: column;
position: relative;
max-height: 80vh;
border: 1px solid var(--border-field);
border-radius: $border-radius;
background: var(--bg-accent-grey-1);
overflow: auto;
// Hide RenderTable's edit buttons when not editable
:deep(.table-container) {
.__table-buttons {
display: none;
}
max-height: inherit;
margin-bottom: 0;
}
// Apply design system styling to RenderTable's tabulator
:deep(.tabulator) {
background: var(--bg-accent-grey-1);
border: none;
font-family: $primary-font-family;
font-size: $base-font-size;
.tabulator-header {
background: var(--bg-solid-grey-2);
border-bottom: 1px solid var(--border-field);
.tabulator-col {
background: var(--bg-solid-grey-2);
border-right: 1px solid var(--border-field);
.tabulator-col-content {
color: var(--fg-primary);
font-weight: 600;
padding: $base-space;
}
&:hover {
background: var(--bg-solid-grey-3);
}
}
}
.tabulator-tableHolder {
background: var(--bg-accent-grey-1);
.tabulator-table {
background: var(--bg-accent-grey-1);
.tabulator-row {
background: var(--bg-accent-grey-1);
border-bottom: 1px solid var(--bg-solid-grey-2);
&:hover {
background: var(--bg-solid-grey-2);
}
.tabulator-cell {
color: var(--fg-primary);
border-right: 1px solid var(--bg-solid-grey-2);
padding: $base-space;
}
}
.tabulator-row-odd {
background: var(--bg-accent-grey-1);
&:hover {
background: var(--bg-solid-grey-2);
}
}
.tabulator-row-even {
background: var(--bg-accent-grey-2);
&:hover {
background: var(--bg-solid-grey-3);
}
}
}
}
}
// When editable, show the buttons
&.tabulator-container--editable {
:deep(.table-container) {
.__table-buttons {
display: flex;
}
}
}
}
</style>