@vuu-ui/vuu-data-react 0.8.7 → 0.8.8-debug
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/cjs/index.js +499 -1
- package/cjs/index.js.map +3 -3
- package/esm/index.js +480 -1
- package/esm/index.js.map +3 -3
- package/package.json +9 -8
- package/LICENSE +0 -201
- package/types/vuu-popups/src/dialog/Dialog.d.ts +0 -7
- package/types/vuu-popups/src/dialog/index.d.ts +0 -1
- package/types/vuu-popups/src/index.d.ts +0 -5
- package/types/vuu-popups/src/menu/ContextMenu.d.ts +0 -15
- package/types/vuu-popups/src/menu/MenuList.d.ts +0 -43
- package/types/vuu-popups/src/menu/context-menu-provider.d.ts +0 -10
- package/types/vuu-popups/src/menu/index.d.ts +0 -4
- package/types/vuu-popups/src/menu/key-code.d.ts +0 -12
- package/types/vuu-popups/src/menu/list-dom-utils.d.ts +0 -4
- package/types/vuu-popups/src/menu/use-cascade.d.ts +0 -25
- package/types/vuu-popups/src/menu/use-items-with-ids-next.d.ts +0 -13
- package/types/vuu-popups/src/menu/use-keyboard-navigation.d.ts +0 -26
- package/types/vuu-popups/src/menu/useContextMenu.d.ts +0 -13
- package/types/vuu-popups/src/menu/utils.d.ts +0 -2
- package/types/vuu-popups/src/popup/index.d.ts +0 -1
- package/types/vuu-popups/src/popup/popup-service.d.ts +0 -55
- package/types/vuu-popups/src/popup-menu/PopupMenu.d.ts +0 -14
- package/types/vuu-popups/src/popup-menu/index.d.ts +0 -1
- package/types/vuu-popups/src/portal/Portal.d.ts +0 -8
- package/types/vuu-popups/src/portal/index.d.ts +0 -3
- package/types/vuu-popups/src/portal/portal-utils.d.ts +0 -1
- package/types/vuu-popups/src/portal/render-portal.d.ts +0 -10
- /package/types/{vuu-data-react/src/hooks → hooks}/index.d.ts +0 -0
- /package/types/{vuu-data-react/src/hooks → hooks}/useDataSource.d.ts +0 -0
- /package/types/{vuu-data-react/src/hooks → hooks}/useServerConnectionQuality.d.ts +0 -0
- /package/types/{vuu-data-react/src/hooks → hooks}/useServerConnectionStatus.d.ts +0 -0
- /package/types/{vuu-data-react/src/hooks → hooks}/useTypeaheadSuggestions.d.ts +0 -0
- /package/types/{vuu-data-react/src/hooks → hooks}/useVuuMenuActions.d.ts +0 -0
- /package/types/{vuu-data-react/src/hooks → hooks}/useVuuTables.d.ts +0 -0
- /package/types/{vuu-data-react/src/index.d.ts → index.d.ts} +0 -0
package/esm/index.js
CHANGED
|
@@ -1,2 +1,481 @@
|
|
|
1
|
-
|
|
1
|
+
// src/hooks/useDataSource.ts
|
|
2
|
+
import { getFullRange, metadataKeys, WindowRange } from "@vuu-ui/vuu-utils";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
var { SELECTED } = metadataKeys;
|
|
5
|
+
function useDataSource({
|
|
6
|
+
dataSource,
|
|
7
|
+
renderBufferSize = 10
|
|
8
|
+
}) {
|
|
9
|
+
const [, forceUpdate] = useState(null);
|
|
10
|
+
const isMounted = useRef(true);
|
|
11
|
+
const hasUpdated = useRef(false);
|
|
12
|
+
const rafHandle = useRef(null);
|
|
13
|
+
const data = useRef([]);
|
|
14
|
+
const rangeRef = useRef({ from: 0, to: 10 });
|
|
15
|
+
const dataWindow = useMemo(
|
|
16
|
+
() => new MovingWindow(getFullRange(rangeRef.current, renderBufferSize)),
|
|
17
|
+
[renderBufferSize]
|
|
18
|
+
);
|
|
19
|
+
const setData = useCallback(
|
|
20
|
+
(updates) => {
|
|
21
|
+
for (const row of updates) {
|
|
22
|
+
dataWindow.add(row);
|
|
23
|
+
}
|
|
24
|
+
data.current = dataWindow.data.slice();
|
|
25
|
+
hasUpdated.current = true;
|
|
26
|
+
},
|
|
27
|
+
[dataWindow]
|
|
28
|
+
);
|
|
29
|
+
const datasourceMessageHandler = useCallback(
|
|
30
|
+
(message) => {
|
|
31
|
+
if (message.type === "viewport-update") {
|
|
32
|
+
if (message.size !== void 0) {
|
|
33
|
+
dataWindow.setRowCount(message.size);
|
|
34
|
+
}
|
|
35
|
+
if (message.rows) {
|
|
36
|
+
setData(message.rows);
|
|
37
|
+
forceUpdate({});
|
|
38
|
+
} else if (message.size !== void 0) {
|
|
39
|
+
data.current = dataWindow.data.slice();
|
|
40
|
+
hasUpdated.current = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[dataWindow, setData]
|
|
45
|
+
);
|
|
46
|
+
useEffect(
|
|
47
|
+
() => () => {
|
|
48
|
+
if (rafHandle.current) {
|
|
49
|
+
cancelAnimationFrame(rafHandle.current);
|
|
50
|
+
rafHandle.current = null;
|
|
51
|
+
}
|
|
52
|
+
isMounted.current = false;
|
|
53
|
+
},
|
|
54
|
+
[]
|
|
55
|
+
);
|
|
56
|
+
const setRange = useCallback(
|
|
57
|
+
(range) => {
|
|
58
|
+
rangeRef.current = range;
|
|
59
|
+
const fullRange = getFullRange(rangeRef.current, renderBufferSize);
|
|
60
|
+
dataSource.range = fullRange;
|
|
61
|
+
dataWindow.setRange(fullRange.from, fullRange.to);
|
|
62
|
+
},
|
|
63
|
+
[dataSource, dataWindow, renderBufferSize]
|
|
64
|
+
);
|
|
65
|
+
useMemo(() => {
|
|
66
|
+
const { from, to } = rangeRef.current;
|
|
67
|
+
const fullRange = getFullRange({ from, to }, renderBufferSize);
|
|
68
|
+
dataSource.range = fullRange;
|
|
69
|
+
dataWindow.setRange(fullRange.from, fullRange.to);
|
|
70
|
+
}, [dataSource, dataWindow, renderBufferSize]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const { from, to } = getFullRange(rangeRef.current, renderBufferSize);
|
|
73
|
+
dataSource.subscribe(
|
|
74
|
+
{
|
|
75
|
+
range: { from, to }
|
|
76
|
+
},
|
|
77
|
+
datasourceMessageHandler
|
|
78
|
+
);
|
|
79
|
+
}, [dataSource, datasourceMessageHandler, renderBufferSize]);
|
|
80
|
+
useEffect(
|
|
81
|
+
() => () => {
|
|
82
|
+
dataSource.unsubscribe();
|
|
83
|
+
},
|
|
84
|
+
[dataSource]
|
|
85
|
+
);
|
|
86
|
+
return [
|
|
87
|
+
data.current,
|
|
88
|
+
dataWindow.rowCount,
|
|
89
|
+
getFullRange(rangeRef.current, renderBufferSize),
|
|
90
|
+
setRange
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
var MovingWindow = class {
|
|
94
|
+
constructor({ from, to }) {
|
|
95
|
+
this.rowCount = 0;
|
|
96
|
+
this.setRowCount = (rowCount) => {
|
|
97
|
+
if (rowCount < this.data.length) {
|
|
98
|
+
this.data.length = rowCount;
|
|
99
|
+
}
|
|
100
|
+
this.rowCount = rowCount;
|
|
101
|
+
};
|
|
102
|
+
this.range = new WindowRange(from, to);
|
|
103
|
+
this.data = new Array(to - from);
|
|
104
|
+
}
|
|
105
|
+
add(data) {
|
|
106
|
+
const [index] = data;
|
|
107
|
+
if (this.isWithinRange(index)) {
|
|
108
|
+
const internalIndex = index - this.range.from;
|
|
109
|
+
this.data[internalIndex] = data;
|
|
110
|
+
if (this.data[internalIndex - 1]) {
|
|
111
|
+
if (this.data[internalIndex - 1][SELECTED] === 1 && data[SELECTED] === 0) {
|
|
112
|
+
data[SELECTED] = 2;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (index === this.rowCount - 1) {
|
|
116
|
+
this.data.length = internalIndex + 1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
getAtIndex(index) {
|
|
121
|
+
return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
|
|
122
|
+
}
|
|
123
|
+
isWithinRange(index) {
|
|
124
|
+
return this.range.isWithin(index);
|
|
125
|
+
}
|
|
126
|
+
setRange(from, to) {
|
|
127
|
+
if (from !== this.range.from || to !== this.range.to) {
|
|
128
|
+
const [overlapFrom, overlapTo] = this.range.overlap(from, to);
|
|
129
|
+
const newData = new Array(to - from);
|
|
130
|
+
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
131
|
+
const data = this.getAtIndex(i);
|
|
132
|
+
if (data) {
|
|
133
|
+
const index = i - from;
|
|
134
|
+
newData[index] = data;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
this.data = newData;
|
|
138
|
+
this.range.from = from;
|
|
139
|
+
this.range.to = to;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/hooks/useServerConnectionStatus.ts
|
|
145
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
146
|
+
import { ConnectionManager } from "@vuu-ui/vuu-data";
|
|
147
|
+
var useServerConnectionStatus = () => {
|
|
148
|
+
const [connectionStatus, setConnectionStatus] = useState2("disconnected");
|
|
149
|
+
const handleStatusChange = useCallback2(
|
|
150
|
+
({ status }) => {
|
|
151
|
+
setConnectionStatus(status);
|
|
152
|
+
},
|
|
153
|
+
[]
|
|
154
|
+
);
|
|
155
|
+
useEffect2(() => {
|
|
156
|
+
ConnectionManager.on("connection-status", handleStatusChange);
|
|
157
|
+
return () => {
|
|
158
|
+
ConnectionManager.removeListener("connection-status", handleStatusChange);
|
|
159
|
+
};
|
|
160
|
+
}, [handleStatusChange]);
|
|
161
|
+
return connectionStatus;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/hooks/useServerConnectionQuality.ts
|
|
165
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useState as useState3 } from "react";
|
|
166
|
+
import { ConnectionManager as ConnectionManager2 } from "@vuu-ui/vuu-data";
|
|
167
|
+
var useServerConnectionQuality = () => {
|
|
168
|
+
const [messagesPerSecond, setMessagesPerSecond] = useState3(0);
|
|
169
|
+
const handleConnectivityMessage = useCallback3(({ messages }) => {
|
|
170
|
+
setMessagesPerSecond(messages.messagesLength);
|
|
171
|
+
}, []);
|
|
172
|
+
useEffect3(() => {
|
|
173
|
+
ConnectionManager2.on("connection-metrics", handleConnectivityMessage);
|
|
174
|
+
return () => {
|
|
175
|
+
ConnectionManager2.removeListener(
|
|
176
|
+
"connection-metrics",
|
|
177
|
+
handleConnectivityMessage
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
}, [handleConnectivityMessage]);
|
|
181
|
+
return messagesPerSecond;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/hooks/useTypeaheadSuggestions.ts
|
|
185
|
+
import { useCallback as useCallback4 } from "react";
|
|
186
|
+
import { makeRpcCall } from "@vuu-ui/vuu-data";
|
|
187
|
+
var TYPEAHEAD_MESSAGE_CONSTANTS = {
|
|
188
|
+
type: "RPC_CALL",
|
|
189
|
+
service: "TypeAheadRpcHandler"
|
|
190
|
+
};
|
|
191
|
+
var getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
|
|
192
|
+
if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
|
|
193
|
+
return [table, column, text];
|
|
194
|
+
}
|
|
195
|
+
return [table, column];
|
|
196
|
+
};
|
|
197
|
+
var useTypeaheadSuggestions = () => {
|
|
198
|
+
const getTypeaheadSuggestions = useCallback4(
|
|
199
|
+
async (params) => {
|
|
200
|
+
const rpcMessage = params.length === 2 ? {
|
|
201
|
+
method: "getUniqueFieldValues",
|
|
202
|
+
params,
|
|
203
|
+
...TYPEAHEAD_MESSAGE_CONSTANTS
|
|
204
|
+
} : {
|
|
205
|
+
method: "getUniqueFieldValuesStartingWith",
|
|
206
|
+
params,
|
|
207
|
+
...TYPEAHEAD_MESSAGE_CONSTANTS
|
|
208
|
+
};
|
|
209
|
+
const suggestions = await makeRpcCall(rpcMessage);
|
|
210
|
+
return suggestions;
|
|
211
|
+
},
|
|
212
|
+
[]
|
|
213
|
+
);
|
|
214
|
+
return getTypeaheadSuggestions;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/hooks/useVuuMenuActions.ts
|
|
218
|
+
import { getFilterPredicate } from "@vuu-ui/vuu-filter-parser";
|
|
219
|
+
import {
|
|
220
|
+
getRowRecord,
|
|
221
|
+
isGroupMenuItemDescriptor,
|
|
222
|
+
metadataKeys as metadataKeys2
|
|
223
|
+
} from "@vuu-ui/vuu-utils";
|
|
224
|
+
import { useCallback as useCallback5 } from "react";
|
|
225
|
+
var addRowsFromInstruments = "addRowsFromInstruments";
|
|
226
|
+
var { KEY } = metadataKeys2;
|
|
227
|
+
var NO_CONFIG = {};
|
|
228
|
+
var isVisualLinksAction = (action) => action.type === "vuu-links";
|
|
229
|
+
var isVisualLinkCreatedAction = (action) => action.type === "vuu-link-created";
|
|
230
|
+
var isVisualLinkRemovedAction = (action) => action.type === "vuu-link-removed";
|
|
231
|
+
var isViewportMenusAction = (action) => action.type === "vuu-menu";
|
|
232
|
+
var isVuuFeatureAction = (action) => isViewportMenusAction(action) || isVisualLinksAction(action);
|
|
233
|
+
var isVuuFeatureInvocation = (action) => action.type === "vuu-link-created" || action.type === "vuu-link-removed";
|
|
234
|
+
var isMenuItem = (menu) => "rpcName" in menu;
|
|
235
|
+
var isGroupMenuItem = (menu) => "menus" in menu;
|
|
236
|
+
var isRoot = (menu) => menu.name === "ROOT";
|
|
237
|
+
var isCellMenu = (options) => options.context === "cell";
|
|
238
|
+
var isRowMenu = (options) => options.context === "row";
|
|
239
|
+
var isSelectionMenu = (options) => options.context === "selected-rows";
|
|
240
|
+
var vuuContextCompatibleWithTableLocation = (uiLocation, vuuContext, selectedRowCount = 0) => {
|
|
241
|
+
switch (uiLocation) {
|
|
242
|
+
case "grid":
|
|
243
|
+
if (vuuContext === "selected-rows") {
|
|
244
|
+
return selectedRowCount > 0;
|
|
245
|
+
} else {
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
case "header":
|
|
249
|
+
return vuuContext === "grid";
|
|
250
|
+
default:
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var gridRowMeetsFilterCriteria = (context, row, selectedRows, filter, columnMap) => {
|
|
255
|
+
if (context === "cell" || context === "row") {
|
|
256
|
+
const filterPredicate = getFilterPredicate(columnMap, filter);
|
|
257
|
+
return filterPredicate(row);
|
|
258
|
+
} else if (context === "selected-rows") {
|
|
259
|
+
if (selectedRows.length === 0) {
|
|
260
|
+
return false;
|
|
261
|
+
} else {
|
|
262
|
+
const filterPredicate = getFilterPredicate(columnMap, filter);
|
|
263
|
+
return selectedRows.every(filterPredicate);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
};
|
|
268
|
+
var getMenuRpcRequest = (options) => {
|
|
269
|
+
const { rpcName } = options;
|
|
270
|
+
if (isCellMenu(options)) {
|
|
271
|
+
return {
|
|
272
|
+
field: options.field,
|
|
273
|
+
rowKey: options.rowKey,
|
|
274
|
+
rpcName,
|
|
275
|
+
value: options.value,
|
|
276
|
+
type: "VIEW_PORT_MENU_CELL_RPC"
|
|
277
|
+
};
|
|
278
|
+
} else if (isRowMenu(options)) {
|
|
279
|
+
return {
|
|
280
|
+
rowKey: options.rowKey,
|
|
281
|
+
row: options.row,
|
|
282
|
+
rpcName,
|
|
283
|
+
type: "VIEW_PORT_MENU_ROW_RPC"
|
|
284
|
+
};
|
|
285
|
+
} else if (isSelectionMenu(options)) {
|
|
286
|
+
return {
|
|
287
|
+
rpcName,
|
|
288
|
+
type: "VIEW_PORT_MENUS_SELECT_RPC"
|
|
289
|
+
};
|
|
290
|
+
} else {
|
|
291
|
+
return {
|
|
292
|
+
rpcName,
|
|
293
|
+
type: "VIEW_PORT_MENU_TABLE_RPC"
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
var isTableLocation = (location) => ["grid", "header", "filter"].includes(location);
|
|
298
|
+
var hasFilter = ({ filter }) => typeof filter === "string" && filter.length > 0;
|
|
299
|
+
var getMenuItemOptions = (menu, options) => {
|
|
300
|
+
switch (menu.context) {
|
|
301
|
+
case "cell":
|
|
302
|
+
return {
|
|
303
|
+
...menu,
|
|
304
|
+
field: options.columnName,
|
|
305
|
+
rowKey: options.row[KEY],
|
|
306
|
+
value: options.row[options.columnMap[options.columnName]]
|
|
307
|
+
};
|
|
308
|
+
case "row":
|
|
309
|
+
return {
|
|
310
|
+
...menu,
|
|
311
|
+
row: getRowRecord(options.row, options.columnMap),
|
|
312
|
+
rowKey: options.row[KEY]
|
|
313
|
+
};
|
|
314
|
+
default:
|
|
315
|
+
return menu;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var menuShouldBeRenderedInThisContext = (menuItem, tableLocation, options) => {
|
|
319
|
+
var _a;
|
|
320
|
+
if (isGroupMenuItem(menuItem)) {
|
|
321
|
+
return menuItem.menus.some(
|
|
322
|
+
(childMenu) => menuShouldBeRenderedInThisContext(childMenu, tableLocation, options)
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
if (!vuuContextCompatibleWithTableLocation(
|
|
326
|
+
tableLocation,
|
|
327
|
+
menuItem.context,
|
|
328
|
+
(_a = options.selectedRows) == null ? void 0 : _a.length
|
|
329
|
+
)) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
if (tableLocation === "grid" && hasFilter(menuItem)) {
|
|
333
|
+
return gridRowMeetsFilterCriteria(
|
|
334
|
+
menuItem.context,
|
|
335
|
+
options.row,
|
|
336
|
+
options.selectedRows,
|
|
337
|
+
menuItem.filter,
|
|
338
|
+
options.columnMap
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
if (isCellMenu(menuItem) && menuItem.field !== "*") {
|
|
342
|
+
return menuItem.field === options.columnName;
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
345
|
+
};
|
|
346
|
+
var buildMenuDescriptor = (menu, tableLocation, options) => {
|
|
347
|
+
if (menuShouldBeRenderedInThisContext(menu, tableLocation, options)) {
|
|
348
|
+
if (isMenuItem(menu)) {
|
|
349
|
+
return {
|
|
350
|
+
label: menu.name,
|
|
351
|
+
action: "MENU_RPC_CALL",
|
|
352
|
+
options: getMenuItemOptions(menu, options)
|
|
353
|
+
};
|
|
354
|
+
} else {
|
|
355
|
+
const children = menu.menus.map(
|
|
356
|
+
(childMenu) => buildMenuDescriptor(childMenu, tableLocation, options)
|
|
357
|
+
).filter(
|
|
358
|
+
(childMenu) => childMenu !== void 0
|
|
359
|
+
);
|
|
360
|
+
if (children.length > 0) {
|
|
361
|
+
return {
|
|
362
|
+
label: menu.name,
|
|
363
|
+
children
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
var useVuuMenuActions = ({
|
|
370
|
+
clientSideMenuActionHandler,
|
|
371
|
+
dataSource,
|
|
372
|
+
menuActionConfig = NO_CONFIG,
|
|
373
|
+
onRpcResponse
|
|
374
|
+
}) => {
|
|
375
|
+
const buildViewserverMenuOptions = useCallback5(
|
|
376
|
+
(location, options) => {
|
|
377
|
+
const { visualLink, visualLinks, vuuMenu } = menuActionConfig;
|
|
378
|
+
const descriptors = [];
|
|
379
|
+
if (location === "grid" && visualLinks && !visualLink) {
|
|
380
|
+
visualLinks.forEach((linkDescriptor) => {
|
|
381
|
+
const { link, label: linkLabel } = linkDescriptor;
|
|
382
|
+
const label = linkLabel ? linkLabel : link.toTable;
|
|
383
|
+
descriptors.push({
|
|
384
|
+
label: `Link to ${label}`,
|
|
385
|
+
action: "link-table",
|
|
386
|
+
options: linkDescriptor
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
if (vuuMenu && isTableLocation(location)) {
|
|
391
|
+
const menuDescriptor = buildMenuDescriptor(
|
|
392
|
+
vuuMenu,
|
|
393
|
+
location,
|
|
394
|
+
options
|
|
395
|
+
);
|
|
396
|
+
if (isRoot(vuuMenu) && isGroupMenuItemDescriptor(menuDescriptor)) {
|
|
397
|
+
descriptors.push(...menuDescriptor.children);
|
|
398
|
+
} else if (menuDescriptor) {
|
|
399
|
+
descriptors.push(menuDescriptor);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return descriptors;
|
|
403
|
+
},
|
|
404
|
+
[menuActionConfig]
|
|
405
|
+
);
|
|
406
|
+
const handleMenuAction = useCallback5(
|
|
407
|
+
({ menuId, options }) => {
|
|
408
|
+
if (clientSideMenuActionHandler == null ? void 0 : clientSideMenuActionHandler(menuId, options)) {
|
|
409
|
+
return true;
|
|
410
|
+
} else if (menuId === "MENU_RPC_CALL") {
|
|
411
|
+
const rpcRequest = getMenuRpcRequest(options);
|
|
412
|
+
dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {
|
|
413
|
+
if (onRpcResponse && rpcResponse) {
|
|
414
|
+
onRpcResponse && onRpcResponse(rpcResponse);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
return true;
|
|
418
|
+
} else if (menuId === "link-table") {
|
|
419
|
+
return dataSource.visualLink = options, true;
|
|
420
|
+
} else {
|
|
421
|
+
console.log(
|
|
422
|
+
`useViewServer handleMenuAction, can't handle action type ${menuId}`
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
426
|
+
},
|
|
427
|
+
[clientSideMenuActionHandler, dataSource, onRpcResponse]
|
|
428
|
+
);
|
|
429
|
+
return {
|
|
430
|
+
buildViewserverMenuOptions,
|
|
431
|
+
handleMenuAction
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// src/hooks/useVuuTables.ts
|
|
436
|
+
import { useCallback as useCallback6, useEffect as useEffect4, useState as useState4 } from "react";
|
|
437
|
+
import { getServerAPI } from "@vuu-ui/vuu-data";
|
|
438
|
+
var useVuuTables = () => {
|
|
439
|
+
const [tables, setTables] = useState4();
|
|
440
|
+
const buildTables = useCallback6((schemas) => {
|
|
441
|
+
const vuuTables = /* @__PURE__ */ new Map();
|
|
442
|
+
schemas.forEach((schema) => {
|
|
443
|
+
vuuTables.set(schema.table.table, schema);
|
|
444
|
+
});
|
|
445
|
+
return vuuTables;
|
|
446
|
+
}, []);
|
|
447
|
+
useEffect4(() => {
|
|
448
|
+
async function fetchTableMetadata() {
|
|
449
|
+
const server = await getServerAPI();
|
|
450
|
+
const { tables: tables2 } = await server.getTableList();
|
|
451
|
+
const tableSchemas = buildTables(
|
|
452
|
+
await Promise.all(
|
|
453
|
+
tables2.map(
|
|
454
|
+
(tableDescriptor) => server.getTableSchema(tableDescriptor)
|
|
455
|
+
)
|
|
456
|
+
)
|
|
457
|
+
);
|
|
458
|
+
setTables(tableSchemas);
|
|
459
|
+
}
|
|
460
|
+
fetchTableMetadata();
|
|
461
|
+
}, [buildTables]);
|
|
462
|
+
return tables;
|
|
463
|
+
};
|
|
464
|
+
export {
|
|
465
|
+
MovingWindow,
|
|
466
|
+
addRowsFromInstruments,
|
|
467
|
+
getTypeaheadParams,
|
|
468
|
+
isViewportMenusAction,
|
|
469
|
+
isVisualLinkCreatedAction,
|
|
470
|
+
isVisualLinkRemovedAction,
|
|
471
|
+
isVisualLinksAction,
|
|
472
|
+
isVuuFeatureAction,
|
|
473
|
+
isVuuFeatureInvocation,
|
|
474
|
+
useDataSource,
|
|
475
|
+
useServerConnectionQuality,
|
|
476
|
+
useServerConnectionStatus,
|
|
477
|
+
useTypeaheadSuggestions,
|
|
478
|
+
useVuuMenuActions,
|
|
479
|
+
useVuuTables
|
|
480
|
+
};
|
|
2
481
|
//# sourceMappingURL=index.js.map
|