@vuu-ui/vuu-data-react 0.8.24-debug → 0.8.24
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/LICENSE +201 -0
- package/cjs/index.js +1 -575
- package/cjs/index.js.map +2 -2
- package/esm/index.js +1 -560
- package/esm/index.js.map +2 -2
- package/package.json +11 -11
package/cjs/index.js
CHANGED
|
@@ -1,576 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
MovingWindow: () => MovingWindow,
|
|
24
|
-
addRowsFromInstruments: () => addRowsFromInstruments,
|
|
25
|
-
getSelectedOption: () => getSelectedOption,
|
|
26
|
-
getTypeaheadParams: () => getTypeaheadParams,
|
|
27
|
-
getVuuTableSchema: () => getVuuTableSchema,
|
|
28
|
-
useDataSource: () => useDataSource,
|
|
29
|
-
useLookupValues: () => useLookupValues,
|
|
30
|
-
useServerConnectionQuality: () => useServerConnectionQuality,
|
|
31
|
-
useServerConnectionStatus: () => useServerConnectionStatus,
|
|
32
|
-
useTypeaheadSuggestions: () => useTypeaheadSuggestions,
|
|
33
|
-
useVuuMenuActions: () => useVuuMenuActions,
|
|
34
|
-
useVuuTables: () => useVuuTables
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(src_exports);
|
|
37
|
-
|
|
38
|
-
// src/hooks/useDataSource.ts
|
|
39
|
-
var import_vuu_utils = require("@vuu-ui/vuu-utils");
|
|
40
|
-
var import_react = require("react");
|
|
41
|
-
var { SELECTED } = import_vuu_utils.metadataKeys;
|
|
42
|
-
function useDataSource({
|
|
43
|
-
dataSource,
|
|
44
|
-
renderBufferSize = 10
|
|
45
|
-
}) {
|
|
46
|
-
const [, forceUpdate] = (0, import_react.useState)(null);
|
|
47
|
-
const isMounted = (0, import_react.useRef)(true);
|
|
48
|
-
const hasUpdated = (0, import_react.useRef)(false);
|
|
49
|
-
const rafHandle = (0, import_react.useRef)(null);
|
|
50
|
-
const data = (0, import_react.useRef)([]);
|
|
51
|
-
const rangeRef = (0, import_react.useRef)({ from: 0, to: 10 });
|
|
52
|
-
const dataWindow = (0, import_react.useMemo)(
|
|
53
|
-
() => new MovingWindow((0, import_vuu_utils.getFullRange)(rangeRef.current, renderBufferSize)),
|
|
54
|
-
[renderBufferSize]
|
|
55
|
-
);
|
|
56
|
-
const setData = (0, import_react.useCallback)(
|
|
57
|
-
(updates) => {
|
|
58
|
-
for (const row of updates) {
|
|
59
|
-
dataWindow.add(row);
|
|
60
|
-
}
|
|
61
|
-
data.current = dataWindow.data.slice();
|
|
62
|
-
hasUpdated.current = true;
|
|
63
|
-
},
|
|
64
|
-
[dataWindow]
|
|
65
|
-
);
|
|
66
|
-
const datasourceMessageHandler = (0, import_react.useCallback)(
|
|
67
|
-
(message) => {
|
|
68
|
-
if (message.type === "viewport-update") {
|
|
69
|
-
if (message.size !== void 0) {
|
|
70
|
-
dataWindow.setRowCount(message.size);
|
|
71
|
-
}
|
|
72
|
-
if (message.rows) {
|
|
73
|
-
setData(message.rows);
|
|
74
|
-
forceUpdate({});
|
|
75
|
-
} else if (message.size !== void 0) {
|
|
76
|
-
data.current = dataWindow.data.slice();
|
|
77
|
-
hasUpdated.current = true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
[dataWindow, setData]
|
|
82
|
-
);
|
|
83
|
-
(0, import_react.useEffect)(
|
|
84
|
-
() => () => {
|
|
85
|
-
if (rafHandle.current) {
|
|
86
|
-
cancelAnimationFrame(rafHandle.current);
|
|
87
|
-
rafHandle.current = null;
|
|
88
|
-
}
|
|
89
|
-
isMounted.current = false;
|
|
90
|
-
},
|
|
91
|
-
[]
|
|
92
|
-
);
|
|
93
|
-
const setRange = (0, import_react.useCallback)(
|
|
94
|
-
(range) => {
|
|
95
|
-
rangeRef.current = range;
|
|
96
|
-
const fullRange = (0, import_vuu_utils.getFullRange)(rangeRef.current, renderBufferSize);
|
|
97
|
-
dataSource.range = fullRange;
|
|
98
|
-
dataWindow.setRange(fullRange.from, fullRange.to);
|
|
99
|
-
},
|
|
100
|
-
[dataSource, dataWindow, renderBufferSize]
|
|
101
|
-
);
|
|
102
|
-
(0, import_react.useMemo)(() => {
|
|
103
|
-
const { from, to } = rangeRef.current;
|
|
104
|
-
const fullRange = (0, import_vuu_utils.getFullRange)({ from, to }, renderBufferSize);
|
|
105
|
-
dataSource.range = fullRange;
|
|
106
|
-
dataWindow.setRange(fullRange.from, fullRange.to);
|
|
107
|
-
}, [dataSource, dataWindow, renderBufferSize]);
|
|
108
|
-
(0, import_react.useEffect)(() => {
|
|
109
|
-
const { from, to } = (0, import_vuu_utils.getFullRange)(rangeRef.current, renderBufferSize);
|
|
110
|
-
dataSource.subscribe(
|
|
111
|
-
{
|
|
112
|
-
range: { from, to }
|
|
113
|
-
},
|
|
114
|
-
datasourceMessageHandler
|
|
115
|
-
);
|
|
116
|
-
}, [dataSource, datasourceMessageHandler, renderBufferSize]);
|
|
117
|
-
(0, import_react.useEffect)(
|
|
118
|
-
() => () => {
|
|
119
|
-
dataSource.unsubscribe();
|
|
120
|
-
},
|
|
121
|
-
[dataSource]
|
|
122
|
-
);
|
|
123
|
-
return [
|
|
124
|
-
data.current,
|
|
125
|
-
dataWindow.rowCount,
|
|
126
|
-
(0, import_vuu_utils.getFullRange)(rangeRef.current, renderBufferSize),
|
|
127
|
-
setRange
|
|
128
|
-
];
|
|
129
|
-
}
|
|
130
|
-
var MovingWindow = class {
|
|
131
|
-
constructor({ from, to }) {
|
|
132
|
-
this.rowCount = 0;
|
|
133
|
-
this.setRowCount = (rowCount) => {
|
|
134
|
-
if (rowCount < this.data.length) {
|
|
135
|
-
this.data.length = rowCount;
|
|
136
|
-
}
|
|
137
|
-
this.rowCount = rowCount;
|
|
138
|
-
};
|
|
139
|
-
this.range = new import_vuu_utils.WindowRange(from, to);
|
|
140
|
-
this.data = new Array(to - from);
|
|
141
|
-
}
|
|
142
|
-
add(data) {
|
|
143
|
-
const [index] = data;
|
|
144
|
-
if (this.isWithinRange(index)) {
|
|
145
|
-
const internalIndex = index - this.range.from;
|
|
146
|
-
this.data[internalIndex] = data;
|
|
147
|
-
if (this.data[internalIndex - 1]) {
|
|
148
|
-
if (this.data[internalIndex - 1][SELECTED] === 1 && data[SELECTED] === 0) {
|
|
149
|
-
data[SELECTED] = 2;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (index === this.rowCount - 1) {
|
|
153
|
-
this.data.length = internalIndex + 1;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
getAtIndex(index) {
|
|
158
|
-
return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
|
|
159
|
-
}
|
|
160
|
-
isWithinRange(index) {
|
|
161
|
-
return this.range.isWithin(index);
|
|
162
|
-
}
|
|
163
|
-
setRange(from, to) {
|
|
164
|
-
if (from !== this.range.from || to !== this.range.to) {
|
|
165
|
-
const [overlapFrom, overlapTo] = this.range.overlap(from, to);
|
|
166
|
-
const newData = new Array(to - from);
|
|
167
|
-
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
168
|
-
const data = this.getAtIndex(i);
|
|
169
|
-
if (data) {
|
|
170
|
-
const index = i - from;
|
|
171
|
-
newData[index] = data;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
this.data = newData;
|
|
175
|
-
this.range.from = from;
|
|
176
|
-
this.range.to = to;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// src/hooks/useLookupValues.ts
|
|
182
|
-
var import_vuu_data_remote = require("@vuu-ui/vuu-data-remote");
|
|
183
|
-
var import_vuu_shell = require("@vuu-ui/vuu-shell");
|
|
184
|
-
var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
|
|
185
|
-
var import_react2 = require("react");
|
|
186
|
-
var NO_VALUES = [];
|
|
187
|
-
var lookupValueMap = /* @__PURE__ */ new Map();
|
|
188
|
-
var loadLookupValues = ({
|
|
189
|
-
labelColumn,
|
|
190
|
-
table,
|
|
191
|
-
valueColumn
|
|
192
|
-
}) => {
|
|
193
|
-
const tableKey = `${table.module}:${table.table}`;
|
|
194
|
-
const lookupValues = lookupValueMap.get(tableKey);
|
|
195
|
-
if (lookupValues) {
|
|
196
|
-
return lookupValues;
|
|
197
|
-
} else {
|
|
198
|
-
const promise = new Promise((resolve) => {
|
|
199
|
-
const columns = [valueColumn, labelColumn];
|
|
200
|
-
const columnMap = (0, import_vuu_utils2.buildColumnMap)(columns);
|
|
201
|
-
const dataSource = new import_vuu_data_remote.VuuDataSource({
|
|
202
|
-
bufferSize: 0,
|
|
203
|
-
table
|
|
204
|
-
});
|
|
205
|
-
dataSource.subscribe(
|
|
206
|
-
{
|
|
207
|
-
columns,
|
|
208
|
-
range: { from: 0, to: 100 }
|
|
209
|
-
},
|
|
210
|
-
(message) => {
|
|
211
|
-
if (message.type === "viewport-update") {
|
|
212
|
-
if (message.rows) {
|
|
213
|
-
const listOptions = message.rows.map((row) => ({
|
|
214
|
-
value: row[columnMap[valueColumn]],
|
|
215
|
-
label: row[columnMap[labelColumn]]
|
|
216
|
-
}));
|
|
217
|
-
resolve(listOptions);
|
|
218
|
-
dataSource.unsubscribe();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
);
|
|
223
|
-
});
|
|
224
|
-
lookupValueMap.set(tableKey, promise);
|
|
225
|
-
return promise;
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
var getSelectedOption = (values, selectedValue) => {
|
|
229
|
-
var _a;
|
|
230
|
-
if (selectedValue === void 0) {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
return (_a = values.find((option) => option.value === selectedValue)) != null ? _a : null;
|
|
234
|
-
};
|
|
235
|
-
var getLookupDetails = ({ name, type }) => {
|
|
236
|
-
if ((0, import_vuu_utils2.isTypeDescriptor)(type) && (0, import_vuu_utils2.isLookupRenderer)(type.renderer)) {
|
|
237
|
-
return type.renderer.lookup;
|
|
238
|
-
} else {
|
|
239
|
-
throw Error(
|
|
240
|
-
`useLookupValues column ${name} is not configured to use lookup values`
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
var useLookupValues = (column, initialValueProp) => {
|
|
245
|
-
const lookupDetails = getLookupDetails(column);
|
|
246
|
-
const { getLookupValues } = (0, import_vuu_shell.useShellContext)();
|
|
247
|
-
const initialState = (0, import_react2.useMemo)(() => {
|
|
248
|
-
var _a;
|
|
249
|
-
const values2 = (_a = getLookupValues == null ? void 0 : getLookupValues(lookupDetails.table)) != null ? _a : NO_VALUES;
|
|
250
|
-
return {
|
|
251
|
-
initialValue: getSelectedOption(values2, initialValueProp),
|
|
252
|
-
values: values2
|
|
253
|
-
};
|
|
254
|
-
}, [getLookupValues, initialValueProp, lookupDetails.table]);
|
|
255
|
-
const [{ initialValue, values }, setLookupState] = (0, import_react2.useState)(initialState);
|
|
256
|
-
(0, import_react2.useMemo)(() => {
|
|
257
|
-
if (values === NO_VALUES) {
|
|
258
|
-
loadLookupValues(lookupDetails).then(
|
|
259
|
-
(values2) => setLookupState({
|
|
260
|
-
initialValue: getSelectedOption(values2, initialValueProp),
|
|
261
|
-
values: values2
|
|
262
|
-
})
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
}, [values, lookupDetails, initialValueProp]);
|
|
266
|
-
return {
|
|
267
|
-
initialValue,
|
|
268
|
-
values
|
|
269
|
-
};
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
// src/hooks/useServerConnectionStatus.ts
|
|
273
|
-
var import_react3 = require("react");
|
|
274
|
-
var import_vuu_data_remote2 = require("@vuu-ui/vuu-data-remote");
|
|
275
|
-
var useServerConnectionStatus = () => {
|
|
276
|
-
const [connectionStatus, setConnectionStatus] = (0, import_react3.useState)("disconnected");
|
|
277
|
-
const handleStatusChange = (0, import_react3.useCallback)(
|
|
278
|
-
({ status }) => {
|
|
279
|
-
setConnectionStatus(status);
|
|
280
|
-
},
|
|
281
|
-
[]
|
|
282
|
-
);
|
|
283
|
-
(0, import_react3.useEffect)(() => {
|
|
284
|
-
import_vuu_data_remote2.ConnectionManager.on("connection-status", handleStatusChange);
|
|
285
|
-
return () => {
|
|
286
|
-
import_vuu_data_remote2.ConnectionManager.removeListener("connection-status", handleStatusChange);
|
|
287
|
-
};
|
|
288
|
-
}, [handleStatusChange]);
|
|
289
|
-
return connectionStatus;
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// src/hooks/useServerConnectionQuality.ts
|
|
293
|
-
var import_react4 = require("react");
|
|
294
|
-
var import_vuu_data_remote3 = require("@vuu-ui/vuu-data-remote");
|
|
295
|
-
var useServerConnectionQuality = () => {
|
|
296
|
-
const [messagesPerSecond, setMessagesPerSecond] = (0, import_react4.useState)(0);
|
|
297
|
-
const handleConnectivityMessage = (0, import_react4.useCallback)(({ messages }) => {
|
|
298
|
-
setMessagesPerSecond(messages.messagesLength);
|
|
299
|
-
}, []);
|
|
300
|
-
(0, import_react4.useEffect)(() => {
|
|
301
|
-
import_vuu_data_remote3.ConnectionManager.on("connection-metrics", handleConnectivityMessage);
|
|
302
|
-
return () => {
|
|
303
|
-
import_vuu_data_remote3.ConnectionManager.removeListener(
|
|
304
|
-
"connection-metrics",
|
|
305
|
-
handleConnectivityMessage
|
|
306
|
-
);
|
|
307
|
-
};
|
|
308
|
-
}, [handleConnectivityMessage]);
|
|
309
|
-
return messagesPerSecond;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
// src/hooks/useTypeaheadSuggestions.ts
|
|
313
|
-
var import_vuu_data_remote4 = require("@vuu-ui/vuu-data-remote");
|
|
314
|
-
var import_react5 = require("react");
|
|
315
|
-
var TYPEAHEAD_MESSAGE_CONSTANTS = {
|
|
316
|
-
type: "RPC_CALL",
|
|
317
|
-
service: "TypeAheadRpcHandler"
|
|
318
|
-
};
|
|
319
|
-
var getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
|
|
320
|
-
if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
|
|
321
|
-
return [table, column, text];
|
|
322
|
-
}
|
|
323
|
-
return [table, column];
|
|
324
|
-
};
|
|
325
|
-
var useTypeaheadSuggestions = () => (0, import_react5.useCallback)(async (params) => {
|
|
326
|
-
const rpcMessage = params.length === 2 ? {
|
|
327
|
-
method: "getUniqueFieldValues",
|
|
328
|
-
params,
|
|
329
|
-
...TYPEAHEAD_MESSAGE_CONSTANTS
|
|
330
|
-
} : {
|
|
331
|
-
method: "getUniqueFieldValuesStartingWith",
|
|
332
|
-
params,
|
|
333
|
-
...TYPEAHEAD_MESSAGE_CONSTANTS
|
|
334
|
-
};
|
|
335
|
-
return (0, import_vuu_data_remote4.makeRpcCall)(rpcMessage);
|
|
336
|
-
}, []);
|
|
337
|
-
|
|
338
|
-
// src/hooks/useVuuMenuActions.ts
|
|
339
|
-
var import_vuu_filter_parser = require("@vuu-ui/vuu-filter-parser");
|
|
340
|
-
var import_vuu_utils3 = require("@vuu-ui/vuu-utils");
|
|
341
|
-
var import_react6 = require("react");
|
|
342
|
-
var addRowsFromInstruments = "addRowsFromInstruments";
|
|
343
|
-
var { KEY } = import_vuu_utils3.metadataKeys;
|
|
344
|
-
var NO_CONFIG = {};
|
|
345
|
-
var isMenuItem = (menu) => "rpcName" in menu;
|
|
346
|
-
var isGroupMenuItem = (menu) => "menus" in menu;
|
|
347
|
-
var isRoot = (menu) => menu.name === "ROOT";
|
|
348
|
-
var isCellMenu = (options) => options.context === "cell";
|
|
349
|
-
var isRowMenu = (options) => options.context === "row";
|
|
350
|
-
var isSelectionMenu = (options) => options.context === "selected-rows";
|
|
351
|
-
var vuuContextCompatibleWithTableLocation = (uiLocation, vuuContext, selectedRowCount = 0) => {
|
|
352
|
-
switch (uiLocation) {
|
|
353
|
-
case "grid":
|
|
354
|
-
if (vuuContext === "selected-rows") {
|
|
355
|
-
return selectedRowCount > 0;
|
|
356
|
-
} else {
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
case "header":
|
|
360
|
-
return vuuContext === "grid";
|
|
361
|
-
default:
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
var gridRowMeetsFilterCriteria = (context, row, selectedRows, filter, columnMap) => {
|
|
366
|
-
if (context === "cell" || context === "row") {
|
|
367
|
-
const filterPredicate = (0, import_vuu_filter_parser.getFilterPredicate)(columnMap, filter);
|
|
368
|
-
return filterPredicate(row);
|
|
369
|
-
} else if (context === "selected-rows") {
|
|
370
|
-
if (selectedRows.length === 0) {
|
|
371
|
-
return false;
|
|
372
|
-
} else {
|
|
373
|
-
const filterPredicate = (0, import_vuu_filter_parser.getFilterPredicate)(columnMap, filter);
|
|
374
|
-
return selectedRows.every(filterPredicate);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return true;
|
|
378
|
-
};
|
|
379
|
-
var getMenuRpcRequest = (options) => {
|
|
380
|
-
const { rpcName } = options;
|
|
381
|
-
if (isCellMenu(options)) {
|
|
382
|
-
return {
|
|
383
|
-
field: options.field,
|
|
384
|
-
rowKey: options.rowKey,
|
|
385
|
-
rpcName,
|
|
386
|
-
value: options.value,
|
|
387
|
-
type: "VIEW_PORT_MENU_CELL_RPC"
|
|
388
|
-
};
|
|
389
|
-
} else if (isRowMenu(options)) {
|
|
390
|
-
return {
|
|
391
|
-
rowKey: options.rowKey,
|
|
392
|
-
row: options.row,
|
|
393
|
-
rpcName,
|
|
394
|
-
type: "VIEW_PORT_MENU_ROW_RPC"
|
|
395
|
-
};
|
|
396
|
-
} else if (isSelectionMenu(options)) {
|
|
397
|
-
return {
|
|
398
|
-
rpcName,
|
|
399
|
-
type: "VIEW_PORT_MENUS_SELECT_RPC"
|
|
400
|
-
};
|
|
401
|
-
} else {
|
|
402
|
-
return {
|
|
403
|
-
rpcName,
|
|
404
|
-
type: "VIEW_PORT_MENU_TABLE_RPC"
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
var isTableLocation = (location) => ["grid", "header", "filter"].includes(location);
|
|
409
|
-
var hasFilter = ({ filter }) => typeof filter === "string" && filter.length > 0;
|
|
410
|
-
var getMenuItemOptions = (menu, options) => {
|
|
411
|
-
switch (menu.context) {
|
|
412
|
-
case "cell":
|
|
413
|
-
return {
|
|
414
|
-
...menu,
|
|
415
|
-
field: options.columnName,
|
|
416
|
-
rowKey: options.row[KEY],
|
|
417
|
-
value: options.row[options.columnMap[options.columnName]]
|
|
418
|
-
};
|
|
419
|
-
case "row":
|
|
420
|
-
return {
|
|
421
|
-
...menu,
|
|
422
|
-
row: (0, import_vuu_utils3.getRowRecord)(options.row, options.columnMap),
|
|
423
|
-
rowKey: options.row[KEY]
|
|
424
|
-
};
|
|
425
|
-
default:
|
|
426
|
-
return menu;
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
var menuShouldBeRenderedInThisContext = (menuItem, tableLocation, options) => {
|
|
430
|
-
var _a;
|
|
431
|
-
if (isGroupMenuItem(menuItem)) {
|
|
432
|
-
return menuItem.menus.some(
|
|
433
|
-
(childMenu) => menuShouldBeRenderedInThisContext(childMenu, tableLocation, options)
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
if (!vuuContextCompatibleWithTableLocation(
|
|
437
|
-
tableLocation,
|
|
438
|
-
menuItem.context,
|
|
439
|
-
(_a = options.selectedRows) == null ? void 0 : _a.length
|
|
440
|
-
)) {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
if (tableLocation === "grid" && hasFilter(menuItem)) {
|
|
444
|
-
return gridRowMeetsFilterCriteria(
|
|
445
|
-
menuItem.context,
|
|
446
|
-
options.row,
|
|
447
|
-
options.selectedRows,
|
|
448
|
-
menuItem.filter,
|
|
449
|
-
options.columnMap
|
|
450
|
-
);
|
|
451
|
-
}
|
|
452
|
-
if (isCellMenu(menuItem) && menuItem.field !== "*") {
|
|
453
|
-
return menuItem.field === options.columnName;
|
|
454
|
-
}
|
|
455
|
-
return true;
|
|
456
|
-
};
|
|
457
|
-
var buildMenuDescriptor = (menu, tableLocation, options) => {
|
|
458
|
-
if (menuShouldBeRenderedInThisContext(menu, tableLocation, options)) {
|
|
459
|
-
if (isMenuItem(menu)) {
|
|
460
|
-
return {
|
|
461
|
-
label: menu.name,
|
|
462
|
-
action: "MENU_RPC_CALL",
|
|
463
|
-
options: getMenuItemOptions(menu, options)
|
|
464
|
-
};
|
|
465
|
-
} else {
|
|
466
|
-
const children = menu.menus.map(
|
|
467
|
-
(childMenu) => buildMenuDescriptor(childMenu, tableLocation, options)
|
|
468
|
-
).filter(
|
|
469
|
-
(childMenu) => childMenu !== void 0
|
|
470
|
-
);
|
|
471
|
-
if (children.length > 0) {
|
|
472
|
-
return {
|
|
473
|
-
label: menu.name,
|
|
474
|
-
children
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
var useVuuMenuActions = ({
|
|
481
|
-
clientSideMenuActionHandler,
|
|
482
|
-
dataSource,
|
|
483
|
-
menuActionConfig = NO_CONFIG,
|
|
484
|
-
onRpcResponse
|
|
485
|
-
}) => {
|
|
486
|
-
const buildViewserverMenuOptions = (0, import_react6.useCallback)(
|
|
487
|
-
(location, options) => {
|
|
488
|
-
const { links, menu } = dataSource;
|
|
489
|
-
const { visualLink } = menuActionConfig;
|
|
490
|
-
const descriptors = [];
|
|
491
|
-
if (location === "grid" && links && !visualLink) {
|
|
492
|
-
links.forEach((linkDescriptor) => {
|
|
493
|
-
const { link, label: linkLabel } = linkDescriptor;
|
|
494
|
-
const label = linkLabel ? linkLabel : link.toTable;
|
|
495
|
-
descriptors.push({
|
|
496
|
-
label: `Link to ${label}`,
|
|
497
|
-
action: "link-table",
|
|
498
|
-
options: linkDescriptor
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
if (menu && isTableLocation(location)) {
|
|
503
|
-
const menuDescriptor = buildMenuDescriptor(
|
|
504
|
-
menu,
|
|
505
|
-
location,
|
|
506
|
-
options
|
|
507
|
-
);
|
|
508
|
-
if (isRoot(menu) && (0, import_vuu_utils3.isGroupMenuItemDescriptor)(menuDescriptor)) {
|
|
509
|
-
descriptors.push(...menuDescriptor.children);
|
|
510
|
-
} else if (menuDescriptor) {
|
|
511
|
-
descriptors.push(menuDescriptor);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return descriptors;
|
|
515
|
-
},
|
|
516
|
-
[dataSource, menuActionConfig]
|
|
517
|
-
);
|
|
518
|
-
const handleMenuAction = (0, import_react6.useCallback)(
|
|
519
|
-
({ menuId, options }) => {
|
|
520
|
-
if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(menuId, options)) {
|
|
521
|
-
return true;
|
|
522
|
-
} else if (menuId === "MENU_RPC_CALL") {
|
|
523
|
-
const rpcRequest = getMenuRpcRequest(options);
|
|
524
|
-
dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {
|
|
525
|
-
if (onRpcResponse && rpcResponse) {
|
|
526
|
-
onRpcResponse && onRpcResponse(rpcResponse);
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
return true;
|
|
530
|
-
} else if (menuId === "link-table") {
|
|
531
|
-
return dataSource.visualLink = options, true;
|
|
532
|
-
} else {
|
|
533
|
-
console.log(
|
|
534
|
-
`useViewServer handleMenuAction, can't handle action type ${menuId}`
|
|
535
|
-
);
|
|
536
|
-
}
|
|
537
|
-
return false;
|
|
538
|
-
},
|
|
539
|
-
[clientSideMenuActionHandler, dataSource, onRpcResponse]
|
|
540
|
-
);
|
|
541
|
-
return {
|
|
542
|
-
buildViewserverMenuOptions,
|
|
543
|
-
handleMenuAction
|
|
544
|
-
};
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
// src/hooks/useVuuTables.ts
|
|
548
|
-
var import_vuu_data_remote5 = require("@vuu-ui/vuu-data-remote");
|
|
549
|
-
var import_react7 = require("react");
|
|
550
|
-
var useVuuTables = () => {
|
|
551
|
-
const [tables, setTables] = (0, import_react7.useState)();
|
|
552
|
-
const buildTables = (0, import_react7.useCallback)((schemas) => {
|
|
553
|
-
const vuuTables = /* @__PURE__ */ new Map();
|
|
554
|
-
schemas.forEach((schema) => {
|
|
555
|
-
vuuTables.set(schema.table.table, schema);
|
|
556
|
-
});
|
|
557
|
-
return vuuTables;
|
|
558
|
-
}, []);
|
|
559
|
-
(0, import_react7.useEffect)(() => {
|
|
560
|
-
async function fetchTableMetadata() {
|
|
561
|
-
console.log("GET TABLE LIST");
|
|
562
|
-
const server = await (0, import_vuu_data_remote5.getServerAPI)();
|
|
563
|
-
const { tables: tables2 } = await server.getTableList();
|
|
564
|
-
const tableSchemas = buildTables(
|
|
565
|
-
await Promise.all(
|
|
566
|
-
tables2.map((vuuTable) => server.getTableSchema(vuuTable))
|
|
567
|
-
)
|
|
568
|
-
);
|
|
569
|
-
setTables(tableSchemas);
|
|
570
|
-
}
|
|
571
|
-
fetchTableMetadata();
|
|
572
|
-
}, [buildTables]);
|
|
573
|
-
return tables;
|
|
574
|
-
};
|
|
575
|
-
var getVuuTableSchema = (table) => (0, import_vuu_data_remote5.getServerAPI)().then((server) => server.getTableSchema(table));
|
|
1
|
+
"use strict";var T=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var Y=(t,e)=>{for(var n in e)T(t,n,{get:e[n],enumerable:!0})},Q=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!j.call(t,o)&&o!==n&&T(t,o,{get:()=>e[o],enumerable:!(r=q(e,o))||r.enumerable});return t};var J=t=>Q(T({},"__esModule",{value:!0}),t);var we={};Y(we,{MovingWindow:()=>S,addRowsFromInstruments:()=>oe,getSelectedOption:()=>L,getTypeaheadParams:()=>ne,getVuuTableSchema:()=>Ce,useDataSource:()=>X,useLookupValues:()=>z,useServerConnectionQuality:()=>te,useServerConnectionStatus:()=>ee,useTypeaheadSuggestions:()=>re,useVuuMenuActions:()=>he,useVuuTables:()=>Re});module.exports=J(we);var f=require("@vuu-ui/vuu-utils"),l=require("react"),{SELECTED:v}=f.metadataKeys;function X({dataSource:t,renderBufferSize:e=10}){let[,n]=(0,l.useState)(null),r=(0,l.useRef)(!0),o=(0,l.useRef)(!1),c=(0,l.useRef)(null),s=(0,l.useRef)([]),i=(0,l.useRef)({from:0,to:10}),u=(0,l.useMemo)(()=>new S((0,f.getFullRange)(i.current,e)),[e]),p=(0,l.useCallback)(a=>{for(let m of a)u.add(m);s.current=u.data.slice(),o.current=!0},[u]),d=(0,l.useCallback)(a=>{a.type==="viewport-update"&&(a.size!==void 0&&u.setRowCount(a.size),a.rows?(p(a.rows),n({})):a.size!==void 0&&(s.current=u.data.slice(),o.current=!0))},[u,p]);(0,l.useEffect)(()=>()=>{c.current&&(cancelAnimationFrame(c.current),c.current=null),r.current=!1},[]);let M=(0,l.useCallback)(a=>{i.current=a;let m=(0,f.getFullRange)(i.current,e);t.range=m,u.setRange(m.from,m.to)},[t,u,e]);return(0,l.useMemo)(()=>{let{from:a,to:m}=i.current,g=(0,f.getFullRange)({from:a,to:m},e);t.range=g,u.setRange(g.from,g.to)},[t,u,e]),(0,l.useEffect)(()=>{let{from:a,to:m}=(0,f.getFullRange)(i.current,e);t.subscribe({range:{from:a,to:m}},d)},[t,d,e]),(0,l.useEffect)(()=>()=>{t.unsubscribe()},[t]),[s.current,u.rowCount,(0,f.getFullRange)(i.current,e),M]}var S=class{constructor({from:e,to:n}){this.rowCount=0;this.setRowCount=e=>{e<this.data.length&&(this.data.length=e),this.rowCount=e};this.range=new f.WindowRange(e,n),this.data=new Array(n-e)}add(e){let[n]=e;if(this.isWithinRange(n)){let r=n-this.range.from;this.data[r]=e,this.data[r-1]&&this.data[r-1][v]===1&&e[v]===0&&(e[v]=2),n===this.rowCount-1&&(this.data.length=r+1)}}getAtIndex(e){return this.range.isWithin(e)&&this.data[e-this.range.from]!=null?this.data[e-this.range.from]:void 0}isWithinRange(e){return this.range.isWithin(e)}setRange(e,n){if(e!==this.range.from||n!==this.range.to){let[r,o]=this.range.overlap(e,n),c=new Array(n-e);for(let s=r;s<o;s++){let i=this.getAtIndex(s);if(i){let u=s-e;c[u]=i}}this.data=c,this.range.from=e,this.range.to=n}}};var O=require("@vuu-ui/vuu-data-remote"),A=require("@vuu-ui/vuu-shell"),h=require("@vuu-ui/vuu-utils"),V=require("react"),P=[],E=new Map,Z=({labelColumn:t,table:e,valueColumn:n})=>{let r=`${e.module}:${e.table}`,o=E.get(r);if(o)return o;{let c=new Promise(s=>{let i=[n,t],u=(0,h.buildColumnMap)(i),p=new O.VuuDataSource({bufferSize:0,table:e});p.subscribe({columns:i,range:{from:0,to:100}},d=>{if(d.type==="viewport-update"&&d.rows){let M=d.rows.map(a=>({value:a[u[n]],label:a[u[t]]}));s(M),p.unsubscribe()}})});return E.set(r,c),c}},L=(t,e)=>{var n;return e===void 0?null:(n=t.find(r=>r.value===e))!=null?n:null},B=({name:t,type:e})=>{if((0,h.isTypeDescriptor)(e)&&(0,h.isLookupRenderer)(e.renderer))return e.renderer.lookup;throw Error(`useLookupValues column ${t} is not configured to use lookup values`)},z=(t,e)=>{let n=B(t),{getLookupValues:r}=(0,A.useShellContext)(),o=(0,V.useMemo)(()=>{var p;let u=(p=r==null?void 0:r(n.table))!=null?p:P;return{initialValue:L(u,e),values:u}},[r,e,n.table]),[{initialValue:c,values:s},i]=(0,V.useState)(o);return(0,V.useMemo)(()=>{s===P&&Z(n).then(u=>i({initialValue:L(u,e),values:u}))},[s,n,e]),{initialValue:c,values:s}};var R=require("react"),I=require("@vuu-ui/vuu-data-remote"),ee=()=>{let[t,e]=(0,R.useState)("disconnected"),n=(0,R.useCallback)(({status:r})=>{e(r)},[]);return(0,R.useEffect)(()=>(I.ConnectionManager.on("connection-status",n),()=>{I.ConnectionManager.removeListener("connection-status",n)}),[n]),t};var C=require("react"),k=require("@vuu-ui/vuu-data-remote"),te=()=>{let[t,e]=(0,C.useState)(0),n=(0,C.useCallback)(({messages:r})=>{e(r.messagesLength)},[]);return(0,C.useEffect)(()=>(k.ConnectionManager.on("connection-metrics",n),()=>{k.ConnectionManager.removeListener("connection-metrics",n)}),[n]),t};var U=require("@vuu-ui/vuu-data-remote"),W=require("react"),_={type:"RPC_CALL",service:"TypeAheadRpcHandler"},ne=(t,e,n="",r=[])=>n!==""&&!r.includes(n.toLowerCase())?[t,e,n]:[t,e],re=()=>(0,W.useCallback)(async t=>{let e=t.length===2?{method:"getUniqueFieldValues",params:t,..._}:{method:"getUniqueFieldValuesStartingWith",params:t,..._};return(0,U.makeRpcCall)(e)},[]);var y=require("@vuu-ui/vuu-filter-parser"),w=require("@vuu-ui/vuu-utils"),D=require("react"),oe="addRowsFromInstruments",{KEY:N}=w.metadataKeys,ue={},se=t=>"rpcName"in t,ae=t=>"menus"in t,ie=t=>t.name==="ROOT",F=t=>t.context==="cell",ce=t=>t.context==="row",le=t=>t.context==="selected-rows",pe=(t,e,n=0)=>{switch(t){case"grid":return e==="selected-rows"?n>0:!0;case"header":return e==="grid";default:return!1}},me=(t,e,n,r,o)=>{if(t==="cell"||t==="row")return(0,y.getFilterPredicate)(o,r)(e);if(t==="selected-rows"){if(n.length===0)return!1;{let c=(0,y.getFilterPredicate)(o,r);return n.every(c)}}return!0},fe=t=>{let{rpcName:e}=t;return F(t)?{field:t.field,rowKey:t.rowKey,rpcName:e,value:t.value,type:"VIEW_PORT_MENU_CELL_RPC"}:ce(t)?{rowKey:t.rowKey,row:t.row,rpcName:e,type:"VIEW_PORT_MENU_ROW_RPC"}:le(t)?{rpcName:e,type:"VIEW_PORT_MENUS_SELECT_RPC"}:{rpcName:e,type:"VIEW_PORT_MENU_TABLE_RPC"}},de=t=>["grid","header","filter"].includes(t),Me=({filter:t})=>typeof t=="string"&&t.length>0,ge=(t,e)=>{switch(t.context){case"cell":return{...t,field:e.columnName,rowKey:e.row[N],value:e.row[e.columnMap[e.columnName]]};case"row":return{...t,row:(0,w.getRowRecord)(e.row,e.columnMap),rowKey:e.row[N]};default:return t}},H=(t,e,n)=>{var r;return ae(t)?t.menus.some(o=>H(o,e,n)):pe(e,t.context,(r=n.selectedRows)==null?void 0:r.length)?e==="grid"&&Me(t)?me(t.context,n.row,n.selectedRows,t.filter,n.columnMap):F(t)&&t.field!=="*"?t.field===n.columnName:!0:!1},K=(t,e,n)=>{if(H(t,e,n)){if(se(t))return{label:t.name,action:"MENU_RPC_CALL",options:ge(t,n)};{let r=t.menus.map(o=>K(o,e,n)).filter(o=>o!==void 0);if(r.length>0)return{label:t.name,children:r}}}},he=({clientSideMenuActionHandler:t,dataSource:e,menuActionConfig:n=ue,onRpcResponse:r})=>{let o=(0,D.useCallback)((s,i)=>{let{links:u,menu:p}=e,{visualLink:d}=n,M=[];if(s==="grid"&&u&&!d&&u.forEach(a=>{let{link:m,label:g}=a,G=g||m.toTable;M.push({label:`Link to ${G}`,action:"link-table",options:a})}),p&&de(s)){let a=K(p,s,i);ie(p)&&(0,w.isGroupMenuItemDescriptor)(a)?M.push(...a.children):a&&M.push(a)}return M},[e,n]),c=(0,D.useCallback)(({menuId:s,options:i})=>{if(t!=null&&t(s,i))return!0;if(s==="MENU_RPC_CALL"){let u=fe(i);return e.menuRpcCall(u).then(p=>{r&&p&&r&&r(p)}),!0}else{if(s==="link-table")return e.visualLink=i,!0;console.log(`useViewServer handleMenuAction, can't handle action type ${s}`)}return!1},[t,e,r]);return{buildViewserverMenuOptions:o,handleMenuAction:c}};var x=require("@vuu-ui/vuu-data-remote"),b=require("react"),Re=()=>{let[t,e]=(0,b.useState)(),n=(0,b.useCallback)(r=>{let o=new Map;return r.forEach(c=>{o.set(c.table.table,c)}),o},[]);return(0,b.useEffect)(()=>{async function r(){console.log("GET TABLE LIST");let o=await(0,x.getServerAPI)(),{tables:c}=await o.getTableList(),s=n(await Promise.all(c.map(i=>o.getTableSchema(i))));e(s)}r()},[n]),t},Ce=t=>(0,x.getServerAPI)().then(e=>e.getTableSchema(t));
|
|
576
2
|
//# sourceMappingURL=index.js.map
|