@vuu-ui/vuu-data-react 0.0.26

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.
Files changed (44) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +0 -0
  3. package/cjs/hooks/useDataSource.js +148 -0
  4. package/cjs/hooks/useDataSource.js.map +1 -0
  5. package/cjs/hooks/useLookupValues.js +108 -0
  6. package/cjs/hooks/useLookupValues.js.map +1 -0
  7. package/cjs/hooks/useServerConnectionQuality.js +24 -0
  8. package/cjs/hooks/useServerConnectionQuality.js.map +1 -0
  9. package/cjs/hooks/useServerConnectionStatus.js +24 -0
  10. package/cjs/hooks/useServerConnectionStatus.js.map +1 -0
  11. package/cjs/hooks/useTypeaheadSuggestions.js +31 -0
  12. package/cjs/hooks/useTypeaheadSuggestions.js.map +1 -0
  13. package/cjs/hooks/useVuuMenuActions.js +213 -0
  14. package/cjs/hooks/useVuuMenuActions.js.map +1 -0
  15. package/cjs/hooks/useVuuTables.js +40 -0
  16. package/cjs/hooks/useVuuTables.js.map +1 -0
  17. package/cjs/index.js +25 -0
  18. package/cjs/index.js.map +1 -0
  19. package/esm/hooks/useDataSource.js +145 -0
  20. package/esm/hooks/useDataSource.js.map +1 -0
  21. package/esm/hooks/useLookupValues.js +105 -0
  22. package/esm/hooks/useLookupValues.js.map +1 -0
  23. package/esm/hooks/useServerConnectionQuality.js +22 -0
  24. package/esm/hooks/useServerConnectionQuality.js.map +1 -0
  25. package/esm/hooks/useServerConnectionStatus.js +22 -0
  26. package/esm/hooks/useServerConnectionStatus.js.map +1 -0
  27. package/esm/hooks/useTypeaheadSuggestions.js +28 -0
  28. package/esm/hooks/useTypeaheadSuggestions.js.map +1 -0
  29. package/esm/hooks/useVuuMenuActions.js +210 -0
  30. package/esm/hooks/useVuuMenuActions.js.map +1 -0
  31. package/esm/hooks/useVuuTables.js +37 -0
  32. package/esm/hooks/useVuuTables.js.map +1 -0
  33. package/esm/index.js +8 -0
  34. package/esm/index.js.map +1 -0
  35. package/package.json +41 -0
  36. package/types/hooks/index.d.ts +7 -0
  37. package/types/hooks/useDataSource.d.ts +23 -0
  38. package/types/hooks/useLookupValues.d.ts +6 -0
  39. package/types/hooks/useServerConnectionQuality.d.ts +1 -0
  40. package/types/hooks/useServerConnectionStatus.d.ts +1 -0
  41. package/types/hooks/useTypeaheadSuggestions.d.ts +4 -0
  42. package/types/hooks/useVuuMenuActions.d.ts +48 -0
  43. package/types/hooks/useVuuTables.d.ts +4 -0
  44. package/types/index.d.ts +1 -0
@@ -0,0 +1,22 @@
1
+ import { useState, useCallback, useEffect } from 'react';
2
+ import { ConnectionManager } from '@vuu-ui/vuu-data-remote';
3
+
4
+ const useServerConnectionStatus = () => {
5
+ const [connectionStatus, setConnectionStatus] = useState("disconnected");
6
+ const handleStatusChange = useCallback(
7
+ ({ status }) => {
8
+ setConnectionStatus(status);
9
+ },
10
+ []
11
+ );
12
+ useEffect(() => {
13
+ ConnectionManager.on("connection-status", handleStatusChange);
14
+ return () => {
15
+ ConnectionManager.removeListener("connection-status", handleStatusChange);
16
+ };
17
+ }, [handleStatusChange]);
18
+ return connectionStatus;
19
+ };
20
+
21
+ export { useServerConnectionStatus };
22
+ //# sourceMappingURL=useServerConnectionStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useServerConnectionStatus.js","sources":["../../src/hooks/useServerConnectionStatus.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { ConnectionManager } from \"@vuu-ui/vuu-data-remote\";\nimport { ConnectionStatusMessage } from \"@vuu-ui/vuu-data-types\";\n\nexport const useServerConnectionStatus = () => {\n const [connectionStatus, setConnectionStatus] = useState(\"disconnected\");\n\n const handleStatusChange = useCallback(\n ({ status }: ConnectionStatusMessage) => {\n setConnectionStatus(status);\n },\n []\n );\n\n useEffect(() => {\n ConnectionManager.on(\"connection-status\", handleStatusChange);\n return () => {\n ConnectionManager.removeListener(\"connection-status\", handleStatusChange);\n };\n }, [handleStatusChange]);\n\n return connectionStatus;\n};\n"],"names":[],"mappings":";;;AAIO,MAAM,4BAA4B,MAAM;AAC7C,EAAA,MAAM,CAAC,gBAAA,EAAkB,mBAAmB,CAAA,GAAI,SAAS,cAAc,CAAA,CAAA;AAEvE,EAAA,MAAM,kBAAqB,GAAA,WAAA;AAAA,IACzB,CAAC,EAAE,MAAA,EAAsC,KAAA;AACvC,MAAA,mBAAA,CAAoB,MAAM,CAAA,CAAA;AAAA,KAC5B;AAAA,IACA,EAAC;AAAA,GACH,CAAA;AAEA,EAAA,SAAA,CAAU,MAAM;AACd,IAAkB,iBAAA,CAAA,EAAA,CAAG,qBAAqB,kBAAkB,CAAA,CAAA;AAC5D,IAAA,OAAO,MAAM;AACX,MAAkB,iBAAA,CAAA,cAAA,CAAe,qBAAqB,kBAAkB,CAAA,CAAA;AAAA,KAC1E,CAAA;AAAA,GACF,EAAG,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEvB,EAAO,OAAA,gBAAA,CAAA;AACT;;;;"}
@@ -0,0 +1,28 @@
1
+ import { makeRpcCall } from '@vuu-ui/vuu-data-remote';
2
+ import { useCallback } from 'react';
3
+
4
+ const TYPEAHEAD_MESSAGE_CONSTANTS = {
5
+ type: "RPC_CALL",
6
+ service: "TypeAheadRpcHandler"
7
+ };
8
+ const getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
9
+ if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
10
+ return [table, column, text];
11
+ }
12
+ return [table, column];
13
+ };
14
+ const useTypeaheadSuggestions = () => useCallback(async (params) => {
15
+ const rpcMessage = params.length === 2 ? {
16
+ method: "getUniqueFieldValues",
17
+ params,
18
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
19
+ } : {
20
+ method: "getUniqueFieldValuesStartingWith",
21
+ params,
22
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
23
+ };
24
+ return makeRpcCall(rpcMessage);
25
+ }, []);
26
+
27
+ export { getTypeaheadParams, useTypeaheadSuggestions };
28
+ //# sourceMappingURL=useTypeaheadSuggestions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTypeaheadSuggestions.js","sources":["../../src/hooks/useTypeaheadSuggestions.ts"],"sourcesContent":["import { makeRpcCall } from \"@vuu-ui/vuu-data-remote\";\nimport { SuggestionFetcher, TableSchemaTable } from \"@vuu-ui/vuu-data-types\";\nimport {\n ClientToServerGetUniqueValues,\n ClientToServerGetUniqueValuesStartingWith,\n TypeaheadParams,\n} from \"@vuu-ui/vuu-protocol-types\";\nimport { useCallback } from \"react\";\n\n// const SPECIAL_SPACE = \"_\";\nconst TYPEAHEAD_MESSAGE_CONSTANTS = {\n type: \"RPC_CALL\",\n service: \"TypeAheadRpcHandler\",\n};\n\nexport const getTypeaheadParams = (\n table: TableSchemaTable,\n column: string,\n text = \"\",\n selectedValues: string[] = []\n): TypeaheadParams => {\n if (text !== \"\" && !selectedValues.includes(text.toLowerCase())) {\n return [table, column, text];\n }\n return [table, column];\n};\n\nexport const useTypeaheadSuggestions = () =>\n useCallback<SuggestionFetcher>(async (params: TypeaheadParams) => {\n const rpcMessage =\n params.length === 2\n ? ({\n method: \"getUniqueFieldValues\",\n params,\n ...TYPEAHEAD_MESSAGE_CONSTANTS,\n } as ClientToServerGetUniqueValues)\n : ({\n method: \"getUniqueFieldValuesStartingWith\",\n params,\n ...TYPEAHEAD_MESSAGE_CONSTANTS,\n } as ClientToServerGetUniqueValuesStartingWith);\n return makeRpcCall<string[]>(rpcMessage);\n }, []);\n"],"names":[],"mappings":";;;AAUA,MAAM,2BAA8B,GAAA;AAAA,EAClC,IAAM,EAAA,UAAA;AAAA,EACN,OAAS,EAAA,qBAAA;AACX,CAAA,CAAA;AAEa,MAAA,kBAAA,GAAqB,CAChC,KACA,EAAA,MAAA,EACA,OAAO,EACP,EAAA,cAAA,GAA2B,EACP,KAAA;AACpB,EAAI,IAAA,IAAA,KAAS,MAAM,CAAC,cAAA,CAAe,SAAS,IAAK,CAAA,WAAA,EAAa,CAAG,EAAA;AAC/D,IAAO,OAAA,CAAC,KAAO,EAAA,MAAA,EAAQ,IAAI,CAAA,CAAA;AAAA,GAC7B;AACA,EAAO,OAAA,CAAC,OAAO,MAAM,CAAA,CAAA;AACvB,EAAA;AAEO,MAAM,uBAA0B,GAAA,MACrC,WAA+B,CAAA,OAAO,MAA4B,KAAA;AAChE,EAAM,MAAA,UAAA,GACJ,MAAO,CAAA,MAAA,KAAW,CACb,GAAA;AAAA,IACC,MAAQ,EAAA,sBAAA;AAAA,IACR,MAAA;AAAA,IACA,GAAG,2BAAA;AAAA,GAEJ,GAAA;AAAA,IACC,MAAQ,EAAA,kCAAA;AAAA,IACR,MAAA;AAAA,IACA,GAAG,2BAAA;AAAA,GACL,CAAA;AACN,EAAA,OAAO,YAAsB,UAAU,CAAA,CAAA;AACzC,CAAA,EAAG,EAAE;;;;"}
@@ -0,0 +1,210 @@
1
+ import { getFilterPredicate } from '@vuu-ui/vuu-filter-parser';
2
+ import { isGroupMenuItemDescriptor, getRowRecord, metadataKeys } from '@vuu-ui/vuu-utils';
3
+ import { useCallback } from 'react';
4
+
5
+ const addRowsFromInstruments = "addRowsFromInstruments";
6
+ const { KEY } = metadataKeys;
7
+ const NO_CONFIG = {};
8
+ const isMenuItem = (menu) => "rpcName" in menu;
9
+ const isGroupMenuItem = (menu) => "menus" in menu;
10
+ const isRoot = (menu) => menu.name === "ROOT";
11
+ const isCellMenu = (options) => options.context === "cell";
12
+ const isRowMenu = (options) => options.context === "row";
13
+ const isSelectionMenu = (options) => options.context === "selected-rows";
14
+ const vuuContextCompatibleWithTableLocation = (uiLocation, vuuContext, selectedRowCount = 0) => {
15
+ switch (uiLocation) {
16
+ case "grid":
17
+ if (vuuContext === "selected-rows") {
18
+ return selectedRowCount > 0;
19
+ } else {
20
+ return true;
21
+ }
22
+ case "header":
23
+ return vuuContext === "grid";
24
+ default:
25
+ return false;
26
+ }
27
+ };
28
+ const gridRowMeetsFilterCriteria = (context, row, selectedRows, filter, columnMap) => {
29
+ if (context === "cell" || context === "row") {
30
+ const filterPredicate = getFilterPredicate(columnMap, filter);
31
+ return filterPredicate(row);
32
+ } else if (context === "selected-rows") {
33
+ if (selectedRows.length === 0) {
34
+ return false;
35
+ } else {
36
+ const filterPredicate = getFilterPredicate(columnMap, filter);
37
+ return selectedRows.every(filterPredicate);
38
+ }
39
+ }
40
+ return true;
41
+ };
42
+ const getMenuRpcRequest = (options) => {
43
+ const { rpcName } = options;
44
+ if (isCellMenu(options)) {
45
+ return {
46
+ field: options.field,
47
+ rowKey: options.rowKey,
48
+ rpcName,
49
+ value: options.value,
50
+ type: "VIEW_PORT_MENU_CELL_RPC"
51
+ };
52
+ } else if (isRowMenu(options)) {
53
+ return {
54
+ rowKey: options.rowKey,
55
+ row: options.row,
56
+ rpcName,
57
+ type: "VIEW_PORT_MENU_ROW_RPC"
58
+ };
59
+ } else if (isSelectionMenu(options)) {
60
+ return {
61
+ rpcName,
62
+ type: "VIEW_PORT_MENUS_SELECT_RPC"
63
+ };
64
+ } else {
65
+ return {
66
+ rpcName,
67
+ type: "VIEW_PORT_MENU_TABLE_RPC"
68
+ };
69
+ }
70
+ };
71
+ const isTableLocation = (location) => ["grid", "header", "filter"].includes(location);
72
+ const hasFilter = ({ filter }) => typeof filter === "string" && filter.length > 0;
73
+ const getMenuItemOptions = (menu, options) => {
74
+ switch (menu.context) {
75
+ case "cell":
76
+ return {
77
+ ...menu,
78
+ field: options.columnName,
79
+ rowKey: options.row[KEY],
80
+ value: options.row[options.columnMap[options.columnName]]
81
+ };
82
+ case "row":
83
+ return {
84
+ ...menu,
85
+ row: getRowRecord(options.row, options.columnMap),
86
+ rowKey: options.row[KEY]
87
+ };
88
+ default:
89
+ return menu;
90
+ }
91
+ };
92
+ const menuShouldBeRenderedInThisContext = (menuItem, tableLocation, options) => {
93
+ if (isGroupMenuItem(menuItem)) {
94
+ return menuItem.menus.some(
95
+ (childMenu) => menuShouldBeRenderedInThisContext(childMenu, tableLocation, options)
96
+ );
97
+ }
98
+ if (!vuuContextCompatibleWithTableLocation(
99
+ tableLocation,
100
+ menuItem.context,
101
+ options.selectedRows?.length
102
+ )) {
103
+ return false;
104
+ }
105
+ if (tableLocation === "grid" && hasFilter(menuItem)) {
106
+ return gridRowMeetsFilterCriteria(
107
+ menuItem.context,
108
+ options.row,
109
+ options.selectedRows,
110
+ menuItem.filter,
111
+ options.columnMap
112
+ );
113
+ }
114
+ if (isCellMenu(menuItem) && menuItem.field !== "*") {
115
+ return menuItem.field === options.columnName;
116
+ }
117
+ return true;
118
+ };
119
+ const buildMenuDescriptor = (menu, tableLocation, options) => {
120
+ if (menuShouldBeRenderedInThisContext(menu, tableLocation, options)) {
121
+ if (isMenuItem(menu)) {
122
+ return {
123
+ label: menu.name,
124
+ action: "MENU_RPC_CALL",
125
+ options: getMenuItemOptions(menu, options)
126
+ };
127
+ } else {
128
+ const children = menu.menus.map(
129
+ (childMenu) => buildMenuDescriptor(childMenu, tableLocation, options)
130
+ ).filter(
131
+ (childMenu) => childMenu !== void 0
132
+ );
133
+ if (children.length > 0) {
134
+ return {
135
+ label: menu.name,
136
+ children
137
+ };
138
+ }
139
+ }
140
+ }
141
+ };
142
+ const useVuuMenuActions = ({
143
+ clientSideMenuActionHandler,
144
+ dataSource,
145
+ menuActionConfig = NO_CONFIG,
146
+ onRpcResponse
147
+ }) => {
148
+ const buildViewserverMenuOptions = useCallback(
149
+ (location, options) => {
150
+ const { links, menu } = dataSource;
151
+ const { visualLink } = menuActionConfig;
152
+ const descriptors = [];
153
+ if (location === "grid" && links && !visualLink) {
154
+ links.forEach((linkDescriptor) => {
155
+ const { link, label: linkLabel } = linkDescriptor;
156
+ const label = linkLabel ? linkLabel : link.toTable;
157
+ descriptors.push({
158
+ label: `Link to ${label}`,
159
+ action: "link-table",
160
+ options: linkDescriptor
161
+ });
162
+ });
163
+ }
164
+ if (menu && isTableLocation(location)) {
165
+ const menuDescriptor = buildMenuDescriptor(
166
+ menu,
167
+ location,
168
+ options
169
+ );
170
+ if (isRoot(menu) && isGroupMenuItemDescriptor(menuDescriptor)) {
171
+ descriptors.push(...menuDescriptor.children);
172
+ } else if (menuDescriptor) {
173
+ descriptors.push(menuDescriptor);
174
+ }
175
+ }
176
+ return descriptors;
177
+ },
178
+ [dataSource, menuActionConfig]
179
+ );
180
+ const handleMenuAction = useCallback(
181
+ ({ menuId, options }) => {
182
+ if (clientSideMenuActionHandler?.(menuId, options)) {
183
+ return true;
184
+ } else if (menuId === "MENU_RPC_CALL") {
185
+ const rpcRequest = getMenuRpcRequest(options);
186
+ dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {
187
+ if (onRpcResponse && rpcResponse) {
188
+ onRpcResponse && onRpcResponse(rpcResponse);
189
+ }
190
+ });
191
+ return true;
192
+ } else if (menuId === "link-table") {
193
+ return dataSource.visualLink = options, true;
194
+ } else {
195
+ console.log(
196
+ `useViewServer handleMenuAction, can't handle action type ${menuId}`
197
+ );
198
+ }
199
+ return false;
200
+ },
201
+ [clientSideMenuActionHandler, dataSource, onRpcResponse]
202
+ );
203
+ return {
204
+ buildViewserverMenuOptions,
205
+ handleMenuAction
206
+ };
207
+ };
208
+
209
+ export { addRowsFromInstruments, useVuuMenuActions };
210
+ //# sourceMappingURL=useVuuMenuActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVuuMenuActions.js","sources":["../../src/hooks/useVuuMenuActions.ts"],"sourcesContent":["import {\n ContextMenuItemDescriptor,\n DataSource,\n DataSourceRow,\n DataSourceVisualLinkCreatedMessage,\n MenuActionHandler,\n MenuBuilder,\n RpcResponseHandler,\n} from \"@vuu-ui/vuu-data-types\";\nimport { getFilterPredicate } from \"@vuu-ui/vuu-filter-parser\";\nimport type { MenuActionClosePopup } from \"@vuu-ui/vuu-popups\";\nimport {\n ClientToServerMenuCellRPC,\n ClientToServerMenuRowRPC,\n ClientToServerMenuRPC,\n LinkDescriptorWithLabel,\n VuuMenu,\n VuuMenuContext,\n VuuMenuItem,\n VuuRowDataItemType,\n} from \"@vuu-ui/vuu-protocol-types\";\nimport {\n ColumnMap,\n getRowRecord,\n isGroupMenuItemDescriptor,\n metadataKeys,\n} from \"@vuu-ui/vuu-utils\";\nimport { useCallback } from \"react\";\n\nexport const addRowsFromInstruments = \"addRowsFromInstruments\";\n\nexport interface VuuCellMenuItem extends VuuMenuItem {\n rowKey: string;\n field: string;\n value: VuuRowDataItemType;\n}\nexport interface VuuRowMenuItem extends VuuMenuItem {\n rowKey: string;\n row: { [key: string]: VuuRowDataItemType };\n}\n\nconst { KEY } = metadataKeys;\n\nconst NO_CONFIG: MenuActionConfig = {};\n\nconst isMenuItem = (menu: VuuMenuItem | VuuMenu): menu is VuuMenuItem =>\n \"rpcName\" in menu;\n\nconst isGroupMenuItem = (menu: VuuMenuItem | VuuMenu): menu is VuuMenu =>\n \"menus\" in menu;\n\nconst isRoot = (menu: VuuMenu) => menu.name === \"ROOT\";\n\nconst isCellMenu = (options: VuuMenuItem): options is VuuCellMenuItem =>\n options.context === \"cell\";\nconst isRowMenu = (options: VuuMenuItem): options is VuuRowMenuItem =>\n options.context === \"row\";\nconst isSelectionMenu = (options: VuuMenuItem): options is VuuMenuItem =>\n options.context === \"selected-rows\";\n\nconst vuuContextCompatibleWithTableLocation = (\n uiLocation: \"grid\" | \"header\" | \"filter\",\n vuuContext: VuuMenuContext,\n selectedRowCount = 0\n) => {\n switch (uiLocation) {\n case \"grid\":\n if (vuuContext === \"selected-rows\") {\n return selectedRowCount > 0;\n } else {\n return true;\n }\n case \"header\":\n return vuuContext === \"grid\";\n default:\n return false;\n }\n};\n\nconst gridRowMeetsFilterCriteria = (\n context: VuuMenuContext,\n row: DataSourceRow,\n selectedRows: DataSourceRow[],\n filter: string,\n columnMap: ColumnMap\n): boolean => {\n if (context === \"cell\" || context === \"row\") {\n const filterPredicate = getFilterPredicate(columnMap, filter);\n return filterPredicate(row);\n } else if (context === \"selected-rows\") {\n if (selectedRows.length === 0) {\n return false;\n } else {\n const filterPredicate = getFilterPredicate(columnMap, filter);\n return selectedRows.every(filterPredicate);\n }\n }\n return true;\n};\n\nconst getMenuRpcRequest = (\n options: VuuMenuItem\n): Omit<ClientToServerMenuRPC, \"vpId\"> => {\n const { rpcName } = options;\n if (isCellMenu(options)) {\n return {\n field: options.field,\n rowKey: options.rowKey,\n rpcName,\n value: options.value,\n type: \"VIEW_PORT_MENU_CELL_RPC\",\n } as Omit<ClientToServerMenuCellRPC, \"vpId\">;\n } else if (isRowMenu(options)) {\n return {\n rowKey: options.rowKey,\n row: options.row,\n rpcName,\n type: \"VIEW_PORT_MENU_ROW_RPC\",\n } as Omit<ClientToServerMenuRowRPC, \"vpId\">;\n } else if (isSelectionMenu(options)) {\n return {\n rpcName,\n type: \"VIEW_PORT_MENUS_SELECT_RPC\",\n } as Omit<ClientToServerMenuRPC, \"vpId\">;\n } else {\n return {\n rpcName,\n type: \"VIEW_PORT_MENU_TABLE_RPC\",\n } as Omit<ClientToServerMenuRPC, \"vpId\">;\n }\n};\n\nexport type VuuMenuActionHandler = (type: string, options: unknown) => boolean;\n\nexport interface ViewServerHookResult {\n buildViewserverMenuOptions: MenuBuilder;\n handleMenuAction: MenuActionHandler;\n}\n\nexport interface MenuActionConfig {\n vuuMenu?: VuuMenu;\n visualLink?: DataSourceVisualLinkCreatedMessage;\n visualLinks?: LinkDescriptorWithLabel[];\n}\n\nexport interface VuuMenuActionHookProps {\n /**\n * By default, vuuMenuActions will be handled automatically. When activated, a\n * message will be sent to server and response will be handled here too.\n * This prop allows client to provide a custom handler for a menu Item. This will\n * take priority and if handler returns true, no further processing for the menu\n * item will be handled by Vuu. This can also be used to prevent an item from being\n * actioned, even when no custom handling is intended. If the handler returns false,\n * Vuu will process the menuItem.\n */\n clientSideMenuActionHandler?: VuuMenuActionHandler;\n dataSource: DataSource;\n menuActionConfig?: MenuActionConfig;\n onRpcResponse?: RpcResponseHandler;\n}\n\ntype TableMenuLocation = \"grid\" | \"header\" | \"filter\";\n\nconst isTableLocation = (location: string): location is TableMenuLocation =>\n [\"grid\", \"header\", \"filter\"].includes(location);\n\nexport type VuuServerMenuOptions = {\n columnMap: ColumnMap;\n columnName: string;\n row: DataSourceRow;\n selectedRows: DataSourceRow[];\n viewport: string;\n};\n\nconst hasFilter = ({ filter }: VuuMenuItem) =>\n typeof filter === \"string\" && filter.length > 0;\n\nconst getMenuItemOptions = (\n menu: VuuMenuItem,\n options: VuuServerMenuOptions\n): VuuMenuItem => {\n switch (menu.context) {\n case \"cell\":\n return {\n ...menu,\n field: options.columnName,\n rowKey: options.row[KEY],\n value: options.row[options.columnMap[options.columnName]],\n } as VuuCellMenuItem;\n case \"row\":\n return {\n ...menu,\n row: getRowRecord(options.row, options.columnMap),\n rowKey: options.row[KEY],\n } as VuuRowMenuItem;\n default:\n return menu;\n }\n};\n\nconst menuShouldBeRenderedInThisContext = (\n menuItem: VuuMenu | VuuMenuItem,\n tableLocation: TableMenuLocation,\n options: VuuServerMenuOptions\n): boolean => {\n if (isGroupMenuItem(menuItem)) {\n return menuItem.menus.some((childMenu) =>\n menuShouldBeRenderedInThisContext(childMenu, tableLocation, options)\n );\n }\n if (\n !vuuContextCompatibleWithTableLocation(\n tableLocation,\n menuItem.context,\n options.selectedRows?.length\n )\n ) {\n return false;\n }\n\n if (tableLocation === \"grid\" && hasFilter(menuItem)) {\n return gridRowMeetsFilterCriteria(\n menuItem.context,\n options.row,\n options.selectedRows,\n menuItem.filter,\n options.columnMap\n );\n }\n\n if (isCellMenu(menuItem) && menuItem.field !== \"*\") {\n return menuItem.field === options.columnName;\n }\n\n return true;\n};\n\nconst buildMenuDescriptor = (\n menu: VuuMenu | VuuMenuItem,\n tableLocation: TableMenuLocation,\n options: VuuServerMenuOptions\n): ContextMenuItemDescriptor | undefined => {\n if (menuShouldBeRenderedInThisContext(menu, tableLocation, options)) {\n if (isMenuItem(menu)) {\n return {\n label: menu.name,\n action: \"MENU_RPC_CALL\",\n options: getMenuItemOptions(menu, options),\n };\n } else {\n const children = menu.menus\n .map((childMenu) =>\n buildMenuDescriptor(childMenu, tableLocation, options)\n )\n .filter(\n (childMenu) => childMenu !== undefined\n ) as ContextMenuItemDescriptor[];\n if (children.length > 0) {\n return {\n label: menu.name,\n children,\n };\n }\n }\n }\n};\n\nexport const useVuuMenuActions = ({\n clientSideMenuActionHandler,\n dataSource,\n menuActionConfig = NO_CONFIG,\n onRpcResponse,\n}: VuuMenuActionHookProps): ViewServerHookResult => {\n const buildViewserverMenuOptions: MenuBuilder = useCallback(\n (location, options) => {\n const { links, menu } = dataSource;\n const { visualLink } = menuActionConfig;\n const descriptors: ContextMenuItemDescriptor[] = [];\n\n if (location === \"grid\" && links && !visualLink) {\n links.forEach((linkDescriptor: LinkDescriptorWithLabel) => {\n const { link, label: linkLabel } = linkDescriptor;\n const label = linkLabel ? linkLabel : link.toTable;\n descriptors.push({\n label: `Link to ${label}`,\n action: \"link-table\",\n options: linkDescriptor,\n });\n });\n }\n\n if (menu && isTableLocation(location)) {\n const menuDescriptor = buildMenuDescriptor(\n menu,\n location,\n options as VuuServerMenuOptions\n );\n if (isRoot(menu) && isGroupMenuItemDescriptor(menuDescriptor)) {\n descriptors.push(...menuDescriptor.children);\n } else if (menuDescriptor) {\n descriptors.push(menuDescriptor);\n }\n }\n\n return descriptors;\n },\n [dataSource, menuActionConfig]\n );\n\n const handleMenuAction = useCallback(\n ({ menuId, options }: MenuActionClosePopup) => {\n if (clientSideMenuActionHandler?.(menuId, options)) {\n return true;\n } else if (menuId === \"MENU_RPC_CALL\") {\n const rpcRequest = getMenuRpcRequest(options as unknown as VuuMenuItem);\n dataSource.menuRpcCall(rpcRequest).then((rpcResponse) => {\n if (onRpcResponse && rpcResponse) {\n onRpcResponse && onRpcResponse(rpcResponse);\n }\n });\n return true;\n } else if (menuId === \"link-table\") {\n // return dataSource.createLink(options as LinkDescriptorWithLabel), true;\n return (\n (dataSource.visualLink = options as LinkDescriptorWithLabel), true\n );\n } else {\n console.log(\n `useViewServer handleMenuAction, can't handle action type ${menuId}`\n );\n }\n\n return false;\n },\n [clientSideMenuActionHandler, dataSource, onRpcResponse]\n );\n\n return {\n buildViewserverMenuOptions,\n handleMenuAction,\n };\n};\n"],"names":[],"mappings":";;;;AA6BO,MAAM,sBAAyB,GAAA,yBAAA;AAYtC,MAAM,EAAE,KAAQ,GAAA,YAAA,CAAA;AAEhB,MAAM,YAA8B,EAAC,CAAA;AAErC,MAAM,UAAA,GAAa,CAAC,IAAA,KAClB,SAAa,IAAA,IAAA,CAAA;AAEf,MAAM,eAAA,GAAkB,CAAC,IAAA,KACvB,OAAW,IAAA,IAAA,CAAA;AAEb,MAAM,MAAS,GAAA,CAAC,IAAkB,KAAA,IAAA,CAAK,IAAS,KAAA,MAAA,CAAA;AAEhD,MAAM,UAAa,GAAA,CAAC,OAClB,KAAA,OAAA,CAAQ,OAAY,KAAA,MAAA,CAAA;AACtB,MAAM,SAAY,GAAA,CAAC,OACjB,KAAA,OAAA,CAAQ,OAAY,KAAA,KAAA,CAAA;AACtB,MAAM,eAAkB,GAAA,CAAC,OACvB,KAAA,OAAA,CAAQ,OAAY,KAAA,eAAA,CAAA;AAEtB,MAAM,qCAAwC,GAAA,CAC5C,UACA,EAAA,UAAA,EACA,mBAAmB,CAChB,KAAA;AACH,EAAA,QAAQ,UAAY;AAAA,IAClB,KAAK,MAAA;AACH,MAAA,IAAI,eAAe,eAAiB,EAAA;AAClC,QAAA,OAAO,gBAAmB,GAAA,CAAA,CAAA;AAAA,OACrB,MAAA;AACL,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAAA,IACF,KAAK,QAAA;AACH,MAAA,OAAO,UAAe,KAAA,MAAA,CAAA;AAAA,IACxB;AACE,MAAO,OAAA,KAAA,CAAA;AAAA,GACX;AACF,CAAA,CAAA;AAEA,MAAM,6BAA6B,CACjC,OAAA,EACA,GACA,EAAA,YAAA,EACA,QACA,SACY,KAAA;AACZ,EAAI,IAAA,OAAA,KAAY,MAAU,IAAA,OAAA,KAAY,KA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@ -0,0 +1,37 @@
1
+ import { getServerAPI } from '@vuu-ui/vuu-data-remote';
2
+ import { useState, useCallback, useEffect } from 'react';
3
+
4
+ const useVuuTables = () => {
5
+ const [tables, setTables] = useState();
6
+ const buildTables = useCallback((schemas) => {
7
+ const vuuTables = /* @__PURE__ */ new Map();
8
+ schemas.forEach((schema) => {
9
+ vuuTables.set(schema.table.table, schema);
10
+ });
11
+ return vuuTables;
12
+ }, []);
13
+ useEffect(() => {
14
+ async function fetchTableMetadata() {
15
+ try {
16
+ const server = await getServerAPI();
17
+ const { tables: tables2 } = await server.getTableList();
18
+ const tableSchemas = buildTables(
19
+ await Promise.all(
20
+ tables2.map((vuuTable) => server.getTableSchema(vuuTable))
21
+ )
22
+ );
23
+ setTables(tableSchemas);
24
+ } catch (err) {
25
+ console.warn(
26
+ `useVuuTables: unable to connect to Vuu server ${String(err)}`
27
+ );
28
+ }
29
+ }
30
+ fetchTableMetadata();
31
+ }, [buildTables]);
32
+ return tables;
33
+ };
34
+ const getVuuTableSchema = (table) => getServerAPI().then((server) => server.getTableSchema(table));
35
+
36
+ export { getVuuTableSchema, useVuuTables };
37
+ //# sourceMappingURL=useVuuTables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVuuTables.js","sources":["../../src/hooks/useVuuTables.ts"],"sourcesContent":["import { getServerAPI } from \"@vuu-ui/vuu-data-remote\";\nimport { TableSchema } from \"@vuu-ui/vuu-data-types\";\nimport { VuuTable } from \"@vuu-ui/vuu-protocol-types\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nexport const useVuuTables = () => {\n const [tables, setTables] = useState<Map<string, TableSchema> | undefined>();\n\n const buildTables = useCallback((schemas: TableSchema[]) => {\n const vuuTables = new Map<string, TableSchema>();\n schemas.forEach((schema) => {\n vuuTables.set(schema.table.table, schema);\n });\n return vuuTables;\n }, []);\n\n useEffect(() => {\n async function fetchTableMetadata() {\n try {\n const server = await getServerAPI();\n const { tables } = await server.getTableList();\n const tableSchemas = buildTables(\n await Promise.all(\n tables.map((vuuTable) => server.getTableSchema(vuuTable))\n )\n );\n setTables(tableSchemas);\n } catch (err) {\n console.warn(\n `useVuuTables: unable to connect to Vuu server ${String(err)}`\n );\n }\n }\n\n fetchTableMetadata();\n }, [buildTables]);\n\n return tables;\n};\n\nexport const getVuuTableSchema = (table: VuuTable) =>\n getServerAPI().then((server) => server.getTableSchema(table));\n"],"names":["tables"],"mappings":";;;AAKO,MAAM,eAAe,MAAM;AAChC,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,QAA+C,EAAA,CAAA;AAE3E,EAAM,MAAA,WAAA,GAAc,WAAY,CAAA,CAAC,OAA2B,KAAA;AAC1D,IAAM,MAAA,SAAA,uBAAgB,GAAyB,EAAA,CAAA;AAC/C,IAAQ,OAAA,CAAA,OAAA,CAAQ,CAAC,MAAW,KAAA;AAC1B,MAAA,SAAA,CAAU,GAAI,CAAA,MAAA,CAAO,KAAM,CAAA,KAAA,EAAO,MAAM,CAAA,CAAA;AAAA,KACzC,CAAA,CAAA;AACD,IAAO,OAAA,SAAA,CAAA;AAAA,GACT,EAAG,EAAE,CAAA,CAAA;AAEL,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,eAAe,kBAAqB,GAAA;AAClC,MAAI,IAAA;AACF,QAAM,MAAA,MAAA,GAAS,MAAM,YAAa,EAAA,CAAA;AAClC,QAAA,MAAM,EAAE,MAAAA,EAAAA,OAAAA,EAAW,GAAA,MAAM,OAAO,YAAa,EAAA,CAAA;AAC7C,QAAA,MAAM,YAAe,GAAA,WAAA;AAAA,UACnB,MAAM,OAAQ,CAAA,GAAA;AAAA,YACZA,QAAO,GAAI,CAAA,CAAC,aAAa,MAAO,CAAA,cAAA,CAAe,QAAQ,CAAC,CAAA;AAAA,WAC1D;AAAA,SACF,CAAA;AACA,QAAA,SAAA,CAAU,YAAY,CAAA,CAAA;AAAA,eACf,GAAK,EAAA;AACZ,QAAQ,OAAA,CAAA,IAAA;AAAA,UACN,CAAA,8CAAA,EAAiD,MAAO,CAAA,GAAG,CAAC,CAAA,CAAA;AAAA,SAC9D,CAAA;AAAA,OACF;AAAA,KACF;AAEA,IAAmB,kBAAA,EAAA,CAAA;AAAA,GACrB,EAAG,CAAC,WAAW,CAAC,CAAA,CAAA;AAEhB,EAAO,OAAA,MAAA,CAAA;AACT,EAAA;AAEa,MAAA,iBAAA,GAAoB,CAAC,KAAA,KAChC,YAAa,EAAA,CAAE,IAAK,CAAA,CAAC,MAAW,KAAA,MAAA,CAAO,cAAe,CAAA,KAAK,CAAC;;;;"}
package/esm/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { MovingWindow, useDataSource } from './hooks/useDataSource.js';
2
+ export { getSelectedOption, useLookupValues } from './hooks/useLookupValues.js';
3
+ export { useServerConnectionStatus } from './hooks/useServerConnectionStatus.js';
4
+ export { useServerConnectionQuality } from './hooks/useServerConnectionQuality.js';
5
+ export { getTypeaheadParams, useTypeaheadSuggestions } from './hooks/useTypeaheadSuggestions.js';
6
+ export { addRowsFromInstruments, useVuuMenuActions } from './hooks/useVuuMenuActions.js';
7
+ export { getVuuTableSchema, useVuuTables } from './hooks/useVuuTables.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "version": "0.0.26",
3
+ "author": "heswell",
4
+ "license": "Apache-2.0",
5
+ "devDependencies": {
6
+ "@vuu-ui/vuu-data-types": "0.0.26",
7
+ "@vuu-ui/vuu-filter-types": "0.0.26",
8
+ "@vuu-ui/vuu-popups": "0.0.26",
9
+ "@vuu-ui/vuu-protocol-types": "0.0.26",
10
+ "@vuu-ui/vuu-table-types": "0.0.26"
11
+ },
12
+ "dependencies": {
13
+ "@vuu-ui/vuu-data-remote": "0.0.26",
14
+ "@vuu-ui/vuu-filter-parser": "0.0.26",
15
+ "@vuu-ui/vuu-popups": "0.0.26",
16
+ "@vuu-ui/vuu-shell": "0.0.26",
17
+ "@vuu-ui/vuu-utils": "0.0.26"
18
+ },
19
+ "peerDependencies": {
20
+ "react": ">=17.0.2",
21
+ "react-dom": ">=17.0.2"
22
+ },
23
+ "files": [
24
+ "README.md",
25
+ "esm",
26
+ "cjs",
27
+ "/types"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "require": "./cjs/index.js",
32
+ "import": "./esm/index.js",
33
+ "types": "./types/index.d.ts"
34
+ }
35
+ },
36
+ "main": "cjs/index.js",
37
+ "module": "esm/index.js",
38
+ "name": "@vuu-ui/vuu-data-react",
39
+ "type": "module",
40
+ "types": "types/index.d.ts"
41
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./useDataSource";
2
+ export * from "./useLookupValues";
3
+ export * from "./useServerConnectionStatus";
4
+ export * from "./useServerConnectionQuality";
5
+ export * from "./useTypeaheadSuggestions";
6
+ export * from "./useVuuMenuActions";
7
+ export * from "./useVuuTables";
@@ -0,0 +1,23 @@
1
+ import type { DataSource, DataSourceRow } from "@vuu-ui/vuu-data-types";
2
+ import type { VuuRange } from "@vuu-ui/vuu-protocol-types";
3
+ export interface DataSourceHookProps {
4
+ dataSource: DataSource;
5
+ renderBufferSize?: number;
6
+ }
7
+ export declare function useDataSource({ dataSource, renderBufferSize, }: DataSourceHookProps): [
8
+ DataSourceRow[],
9
+ number,
10
+ VuuRange,
11
+ (range: VuuRange) => void
12
+ ];
13
+ export declare class MovingWindow {
14
+ data: DataSourceRow[];
15
+ rowCount: number;
16
+ private range;
17
+ constructor({ from, to }: VuuRange);
18
+ setRowCount: (rowCount: number) => void;
19
+ add(data: DataSourceRow): void;
20
+ getAtIndex(index: number): DataSourceRow | undefined;
21
+ isWithinRange(index: number): boolean;
22
+ setRange(from: number, to: number): void;
23
+ }
@@ -0,0 +1,6 @@
1
+ import { ColumnDescriptor, ListOption } from "@vuu-ui/vuu-table-types";
2
+ export declare const getSelectedOption: (values: ListOption[], selectedValue: string | number | undefined) => ListOption | null;
3
+ export declare const useLookupValues: (column: ColumnDescriptor, initialValueProp: number | string) => {
4
+ initialValue: ListOption | null;
5
+ values: ListOption[];
6
+ };
@@ -0,0 +1 @@
1
+ export declare const useServerConnectionQuality: () => number;
@@ -0,0 +1 @@
1
+ export declare const useServerConnectionStatus: () => string;
@@ -0,0 +1,4 @@
1
+ import { SuggestionFetcher, TableSchemaTable } from "@vuu-ui/vuu-data-types";
2
+ import { TypeaheadParams } from "@vuu-ui/vuu-protocol-types";
3
+ export declare const getTypeaheadParams: (table: TableSchemaTable, column: string, text?: string, selectedValues?: string[]) => TypeaheadParams;
4
+ export declare const useTypeaheadSuggestions: () => SuggestionFetcher;
@@ -0,0 +1,48 @@
1
+ import { DataSource, DataSourceRow, DataSourceVisualLinkCreatedMessage, MenuActionHandler, MenuBuilder, RpcResponseHandler } from "@vuu-ui/vuu-data-types";
2
+ import { LinkDescriptorWithLabel, VuuMenu, VuuMenuItem, VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
3
+ import { ColumnMap } from "@vuu-ui/vuu-utils";
4
+ export declare const addRowsFromInstruments = "addRowsFromInstruments";
5
+ export interface VuuCellMenuItem extends VuuMenuItem {
6
+ rowKey: string;
7
+ field: string;
8
+ value: VuuRowDataItemType;
9
+ }
10
+ export interface VuuRowMenuItem extends VuuMenuItem {
11
+ rowKey: string;
12
+ row: {
13
+ [key: string]: VuuRowDataItemType;
14
+ };
15
+ }
16
+ export type VuuMenuActionHandler = (type: string, options: unknown) => boolean;
17
+ export interface ViewServerHookResult {
18
+ buildViewserverMenuOptions: MenuBuilder;
19
+ handleMenuAction: MenuActionHandler;
20
+ }
21
+ export interface MenuActionConfig {
22
+ vuuMenu?: VuuMenu;
23
+ visualLink?: DataSourceVisualLinkCreatedMessage;
24
+ visualLinks?: LinkDescriptorWithLabel[];
25
+ }
26
+ export interface VuuMenuActionHookProps {
27
+ /**
28
+ * By default, vuuMenuActions will be handled automatically. When activated, a
29
+ * message will be sent to server and response will be handled here too.
30
+ * This prop allows client to provide a custom handler for a menu Item. This will
31
+ * take priority and if handler returns true, no further processing for the menu
32
+ * item will be handled by Vuu. This can also be used to prevent an item from being
33
+ * actioned, even when no custom handling is intended. If the handler returns false,
34
+ * Vuu will process the menuItem.
35
+ */
36
+ clientSideMenuActionHandler?: VuuMenuActionHandler;
37
+ dataSource: DataSource;
38
+ menuActionConfig?: MenuActionConfig;
39
+ onRpcResponse?: RpcResponseHandler;
40
+ }
41
+ export type VuuServerMenuOptions = {
42
+ columnMap: ColumnMap;
43
+ columnName: string;
44
+ row: DataSourceRow;
45
+ selectedRows: DataSourceRow[];
46
+ viewport: string;
47
+ };
48
+ export declare const useVuuMenuActions: ({ clientSideMenuActionHandler, dataSource, menuActionConfig, onRpcResponse, }: VuuMenuActionHookProps) => ViewServerHookResult;
@@ -0,0 +1,4 @@
1
+ import { TableSchema } from "@vuu-ui/vuu-data-types";
2
+ import { VuuTable } from "@vuu-ui/vuu-protocol-types";
3
+ export declare const useVuuTables: () => Map<string, TableSchema> | undefined;
4
+ export declare const getVuuTableSchema: (table: VuuTable) => Promise<TableSchema>;
@@ -0,0 +1 @@
1
+ export * from "./hooks";