terrier-engine 4.37.0 → 4.37.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data-dive/queries/columns.ts +31 -23
- package/package.json +1 -1
- package/terrier/api.ts +10 -9
|
@@ -124,18 +124,15 @@ export class ColumnsEditorModal extends ModalPart<ColumnsEditorState> {
|
|
|
124
124
|
|
|
125
125
|
modelDef!: ModelDef
|
|
126
126
|
table!: TableRef
|
|
127
|
-
|
|
127
|
+
columnEditors: Record<string, ColumnEditor> = {}
|
|
128
128
|
columnCount = 0
|
|
129
129
|
|
|
130
130
|
tableFields!: FormFields<TableRef>
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
this.assignCollection('columns', ColumnEditor, this.columnStates)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
addState(col: ColumnRef) {
|
|
132
|
+
addEditor(col: ColumnRef) {
|
|
137
133
|
this.columnCount += 1
|
|
138
|
-
|
|
134
|
+
const state = {schema: this.state.schema, columnsEditor: this, id: `column-${this.columnCount}`, column: col}
|
|
135
|
+
this.columnEditors[state.id] = this.makePart(ColumnEditor, state)
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
|
|
@@ -148,9 +145,8 @@ export class ColumnsEditorModal extends ModalPart<ColumnsEditorState> {
|
|
|
148
145
|
// initialize the columns states
|
|
149
146
|
const columns: ColumnRef[] = this.table.columns || []
|
|
150
147
|
for (const col of columns) {
|
|
151
|
-
this.
|
|
148
|
+
this.addEditor(col)
|
|
152
149
|
}
|
|
153
|
-
this.updateColumnEditors()
|
|
154
150
|
|
|
155
151
|
this.setTitle(`Columns for ${this.state.tableView.displayName}`)
|
|
156
152
|
this.setIcon('glyp-columns')
|
|
@@ -172,7 +168,7 @@ export class ColumnsEditorModal extends ModalPart<ColumnsEditorState> {
|
|
|
172
168
|
})
|
|
173
169
|
|
|
174
170
|
this.onClick(removeKey, m => {
|
|
175
|
-
this.
|
|
171
|
+
this.removeEditor(m.data.id)
|
|
176
172
|
})
|
|
177
173
|
|
|
178
174
|
this.onClick(addSingleKey, m => {
|
|
@@ -193,16 +189,20 @@ export class ColumnsEditorModal extends ModalPart<ColumnsEditorState> {
|
|
|
193
189
|
const colDef = this.modelDef.columns[col]
|
|
194
190
|
log.info(`Add column ${col}`, colDef)
|
|
195
191
|
if (colDef) {
|
|
196
|
-
this.
|
|
197
|
-
this.updateColumnEditors()
|
|
192
|
+
this.addEditor({name: colDef.name})
|
|
198
193
|
this.dirty()
|
|
199
194
|
} else {
|
|
200
195
|
alert(`Unknown column name '${col}'`)
|
|
201
196
|
}
|
|
202
197
|
}
|
|
203
198
|
|
|
199
|
+
get currentEditorStates(): ColumnState[] {
|
|
200
|
+
return Object.values(this.columnEditors).map(e => e.state)
|
|
201
|
+
}
|
|
202
|
+
|
|
204
203
|
get currentColumnNames(): Set<string> {
|
|
205
|
-
|
|
204
|
+
const states = this.currentEditorStates
|
|
205
|
+
return new Set(states.map(s => s.column.name))
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
renderContent(parent: PartTag): void {
|
|
@@ -223,8 +223,11 @@ export class ColumnsEditorModal extends ModalPart<ColumnsEditorState> {
|
|
|
223
223
|
header.div('.function').label({text: "Function"})
|
|
224
224
|
header.div('.group-by').label({text: "Group By?"})
|
|
225
225
|
})
|
|
226
|
-
|
|
227
|
-
.
|
|
226
|
+
table.div('dd-editor-row-container', container => {
|
|
227
|
+
for (const id of Object.keys(this.columnEditors)) {
|
|
228
|
+
container.part(this.columnEditors[id])
|
|
229
|
+
}
|
|
230
|
+
})
|
|
228
231
|
})
|
|
229
232
|
|
|
230
233
|
// common column quick links
|
|
@@ -258,17 +261,21 @@ export class ColumnsEditorModal extends ModalPart<ColumnsEditorState> {
|
|
|
258
261
|
|
|
259
262
|
}
|
|
260
263
|
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
this.
|
|
264
|
+
removeEditor(id: string) {
|
|
265
|
+
const editor = this.columnEditors[id]
|
|
266
|
+
if (editor) {
|
|
267
|
+
log.info(`Removing column ${id}`)
|
|
268
|
+
this.removeChild(editor)
|
|
269
|
+
delete this.columnEditors[id]
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
log.warn(`No editor for column ${id}`)
|
|
266
273
|
}
|
|
267
274
|
}
|
|
268
275
|
|
|
269
276
|
async serialize(): Promise<ColumnRef[]> {
|
|
270
|
-
const
|
|
271
|
-
return await Promise.all(
|
|
277
|
+
const editors = Object.values(this.columnEditors)
|
|
278
|
+
return await Promise.all(editors.map(async part => {
|
|
272
279
|
return await (part as ColumnEditor).serialize()
|
|
273
280
|
}))
|
|
274
281
|
}
|
|
@@ -296,8 +303,9 @@ export class ColumnsEditorModal extends ModalPart<ColumnsEditorState> {
|
|
|
296
303
|
Validation.validateQuery(query)
|
|
297
304
|
|
|
298
305
|
// copy the column errors over
|
|
306
|
+
const editors = Object.values(this.columnEditors)
|
|
299
307
|
for (let i = 0; i < columns.length; i++) {
|
|
300
|
-
|
|
308
|
+
editors[i].state.column.errors = columns[i].errors
|
|
301
309
|
}
|
|
302
310
|
|
|
303
311
|
this.dirty()
|
package/package.json
CHANGED
package/terrier/api.ts
CHANGED
|
@@ -115,15 +115,16 @@ async function get<ResponseType>(url: string, params: QueryParams | Record<strin
|
|
|
115
115
|
* @param url the URL of the API endpoint
|
|
116
116
|
* @param body the body of the request (will be transmitted as JSON)
|
|
117
117
|
*/
|
|
118
|
-
async function safePost<ResponseType>(url: string, body: Record<string, unknown>): Promise<ResponseType> {
|
|
118
|
+
async function safePost<ResponseType>(url: string, body: Record<string, unknown> | FormData): Promise<ResponseType> {
|
|
119
119
|
log.debug(`Safe posting to ${url} with body`, body)
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
120
|
+
const config: RequestInit = { method: 'POST' }
|
|
121
|
+
if (body instanceof FormData) {
|
|
122
|
+
config.body = body
|
|
123
|
+
} else {
|
|
124
|
+
config.body = JSON.stringify(body)
|
|
125
|
+
config.headers = { 'Content-Type': 'application/json' }
|
|
126
|
+
}
|
|
127
|
+
const response = await apiRequest<ResponseType>(url, config)
|
|
127
128
|
if (response.status == 'error') {
|
|
128
129
|
throw new ApiException(response.message)
|
|
129
130
|
}
|
|
@@ -139,7 +140,7 @@ async function safePost<ResponseType>(url: string, body: Record<string, unknown>
|
|
|
139
140
|
*/
|
|
140
141
|
async function post<ResponseType>(url: string, body: Record<string, unknown> | FormData): Promise<ResponseType & ApiResponse> {
|
|
141
142
|
log.debug(`Posting to ${url} with body`, body)
|
|
142
|
-
const config = { method: 'POST' }
|
|
143
|
+
const config: RequestInit = { method: 'POST' }
|
|
143
144
|
if (body instanceof FormData) {
|
|
144
145
|
config.body = body
|
|
145
146
|
} else {
|