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