@linzjs/step-ag-grid 7.11.7 → 7.11.9

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.
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useMemo, useLayoutEffect, useEffect, createContext, memo, forwardRef, useRef, useContext, useState, useCallback, useReducer, cloneElement, useImperativeHandle, Fragment } from 'react';
3
3
  import ReactDOM, { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
4
- import { findIndex, debounce, negate, isEmpty, delay, sortBy, last, difference, castArray, remove, flatten, xorBy, partition, pick, groupBy, fromPairs, toPairs, omit } from 'lodash-es';
4
+ import { findIndex, debounce, negate, isEmpty, difference, delay, sortBy, defer as defer$1, last, castArray, remove, flatten, xorBy, partition, pick, groupBy, fromPairs, toPairs, omit } from 'lodash-es';
5
5
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
6
6
  import { AgGridReact } from 'ag-grid-react';
7
7
  import { LuiMiniSpinner, LuiIcon, LuiCheckboxInput, LuiButton } from '@linzjs/lui';
@@ -1427,8 +1427,8 @@ var ControlledMenuFr = function (_a, externalRef) {
1427
1427
  if (activeElement !== firstInputEl && activeElement !== lastInputEl)
1428
1428
  return;
1429
1429
  var isTextArea = activeElement.nodeName === "TEXTAREA";
1430
- var suppressEnterAutoSave = activeElement.getAttribute("data-disableenterautosave") || isTextArea;
1431
- var allowTabToSave = activeElement.getAttribute("data-allowtabtosave");
1430
+ var suppressEnterAutoSave = activeElement.getAttribute("data-disableenterautosave") != "false" || isTextArea;
1431
+ var allowTabToSave = activeElement.getAttribute("data-allowtabtosave") != "false";
1432
1432
  var invokeSave = function (reason) {
1433
1433
  var _a, _b;
1434
1434
  if (!(saveButtonRef === null || saveButtonRef === void 0 ? void 0 : saveButtonRef.current))
@@ -2060,68 +2060,68 @@ var GridContextProvider = function (props) {
2060
2060
  var _b = useState(false), gridReady = _b[0], setGridReady = _b[1];
2061
2061
  var idsBeforeUpdate = useRef([]);
2062
2062
  var externallySelectedItemsAreInSync = useRef(false);
2063
- var setGridApi = function (gridApi) {
2063
+ var setGridApi = useCallback(function (gridApi) {
2064
2064
  _setGridApi(gridApi);
2065
2065
  setGridReady(!!gridApi);
2066
- };
2066
+ }, []);
2067
2067
  /**
2068
2068
  * Wraps things that require gridApi in common handling, for when gridApi not present.
2069
2069
  *
2070
2070
  * @param hasApiFn Execute when api is ready.
2071
2071
  * @param noApiFn Execute if api is not ready.
2072
2072
  */
2073
- var gridApiOp = function (hasApiFn, noApiFn) {
2073
+ var gridApiOp = useCallback(function (hasApiFn, noApiFn) {
2074
2074
  if (!noApiFn) {
2075
2075
  noApiFn = (function () { });
2076
2076
  }
2077
2077
  return gridApi ? hasApiFn(gridApi) : noApiFn();
2078
- };
2078
+ }, [gridApi]);
2079
2079
  /**
2080
2080
  * Set the quick filter value to grid.
2081
2081
  */
2082
- var setQuickFilter = function (quickFilter) {
2082
+ var setQuickFilter = useCallback(function (quickFilter) {
2083
2083
  gridApiOp(function (gridApi) { return gridApi.setQuickFilter(quickFilter); });
2084
- };
2084
+ }, [gridApiOp]);
2085
2085
  /**
2086
2086
  * Get all row id's in grid.
2087
2087
  */
2088
- var _getAllRowIds = function () {
2088
+ var _getAllRowIds = useCallback(function () {
2089
2089
  var result = [];
2090
2090
  return gridApiOp(function (gridApi) {
2091
2091
  gridApi.forEachNode(function (node) { return result.push(node.data.id); });
2092
2092
  return result;
2093
2093
  }, function () { return result; });
2094
- };
2094
+ }, [gridApiOp]);
2095
2095
  /**
2096
2096
  * Record all row id's before update so that we can select/flash the new rows after update.
2097
2097
  */
2098
- var beforeUpdate = function () {
2098
+ var beforeUpdate = useCallback(function () {
2099
2099
  idsBeforeUpdate.current = _getAllRowIds();
2100
- };
2100
+ }, [_getAllRowIds]);
2101
2101
  /**
2102
2102
  * Find new row ids
2103
2103
  * Uses beforeUpdate ids to find new nodes.
2104
2104
  */
2105
- var _getNewNodes = function () {
2105
+ var _getNewNodes = useCallback(function () {
2106
2106
  return gridApiOp(function (gridApi) {
2107
2107
  return difference(_getAllRowIds(), idsBeforeUpdate.current)
2108
2108
  .map(function (rowId) { return gridApi.getRowNode("" + rowId); }) //
2109
2109
  .filter(function (r) { return r; });
2110
2110
  }, function () { return []; });
2111
- };
2111
+ }, [_getAllRowIds, gridApiOp]);
2112
2112
  /**
2113
2113
  * Get grid nodes via rowIds. If rowIds has no matching node the result may be smaller than expected.
2114
2114
  * This can happen if the grid has not re-rendered yet.
2115
2115
  *
2116
2116
  * @param rowIds Row ids to get from grid.
2117
2117
  */
2118
- var _rowIdsToNodes = function (rowIds) {
2118
+ var _rowIdsToNodes = useCallback(function (rowIds) {
2119
2119
  return gridApiOp(function (gridApi) {
2120
2120
  return rowIds
2121
2121
  .map(function (rowId) { return gridApi.getRowNode("" + rowId); }) //
2122
2122
  .filter(function (r) { return r; });
2123
2123
  }, function () { return []; });
2124
- };
2124
+ }, [gridApiOp]);
2125
2125
  /**
2126
2126
  * Internal method for selecting and flashing rows.
2127
2127
  *
@@ -2130,7 +2130,7 @@ var GridContextProvider = function (props) {
2130
2130
  * @param flash Whether to flash rows
2131
2131
  * @param retryCount Table updates may not be present when this is called, so retry is needed.
2132
2132
  */
2133
- var _selectRowsWithOptionalFlash = function (rowIds, select, flash, retryCount) {
2133
+ var _selectRowsWithOptionalFlash = useCallback(function (rowIds, select, flash, retryCount) {
2134
2134
  if (retryCount === void 0) { retryCount = 15; }
2135
2135
  return gridApiOp(function (gridApi) {
2136
2136
  var _a;
@@ -2153,7 +2153,10 @@ var GridContextProvider = function (props) {
2153
2153
  var rowIndex_1 = firstNode.rowIndex;
2154
2154
  if (rowIndex_1 != null && col != null) {
2155
2155
  var colId_1 = col.colId;
2156
- colId_1 != null && setTimeout(function () { return gridApi.setFocusedCell(rowIndex_1, colId_1); }, 100);
2156
+ // We need to make sure we aren't currently editing a cell otherwise tests will fail
2157
+ // as they will start to edit the cell before this stuff has a chance to run
2158
+ colId_1 != null &&
2159
+ defer$1(function () { return isEmpty(gridApi.getEditingCells()) && gridApi.setFocusedCell(rowIndex_1, colId_1); });
2157
2160
  }
2158
2161
  }
2159
2162
  }
@@ -2178,11 +2181,11 @@ var GridContextProvider = function (props) {
2178
2181
  }, 250);
2179
2182
  }
2180
2183
  });
2181
- };
2182
- var selectRowsById = function (rowIds) { return _selectRowsWithOptionalFlash(rowIds, true, false); };
2183
- var selectRowsByIdWithFlash = function (rowIds) { return _selectRowsWithOptionalFlash(rowIds, true, true); };
2184
- var flashRows = function (rowIds) { return _selectRowsWithOptionalFlash(rowIds, false, true); };
2185
- var selectRowsDiff = function (fn) { return __awaiter(void 0, void 0, void 0, function () {
2184
+ }, [_getNewNodes, _rowIdsToNodes, gridApiOp]);
2185
+ var selectRowsById = useCallback(function (rowIds) { return _selectRowsWithOptionalFlash(rowIds, true, false); }, [_selectRowsWithOptionalFlash]);
2186
+ var selectRowsByIdWithFlash = useCallback(function (rowIds) { return _selectRowsWithOptionalFlash(rowIds, true, true); }, [_selectRowsWithOptionalFlash]);
2187
+ var flashRows = useCallback(function (rowIds) { return _selectRowsWithOptionalFlash(rowIds, false, true); }, [_selectRowsWithOptionalFlash]);
2188
+ var selectRowsDiff = useCallback(function (fn) { return __awaiter(void 0, void 0, void 0, function () {
2186
2189
  return __generator(this, function (_a) {
2187
2190
  switch (_a.label) {
2188
2191
  case 0:
@@ -2194,8 +2197,8 @@ var GridContextProvider = function (props) {
2194
2197
  return [2 /*return*/];
2195
2198
  }
2196
2199
  });
2197
- }); };
2198
- var selectRowsWithFlashDiff = function (fn) { return __awaiter(void 0, void 0, void 0, function () {
2200
+ }); }, [_selectRowsWithOptionalFlash, beforeUpdate]);
2201
+ var selectRowsWithFlashDiff = useCallback(function (fn) { return __awaiter(void 0, void 0, void 0, function () {
2199
2202
  return __generator(this, function (_a) {
2200
2203
  switch (_a.label) {
2201
2204
  case 0:
@@ -2207,8 +2210,8 @@ var GridContextProvider = function (props) {
2207
2210
  return [2 /*return*/];
2208
2211
  }
2209
2212
  });
2210
- }); };
2211
- var flashRowsDiff = function (fn) { return __awaiter(void 0, void 0, void 0, function () {
2213
+ }); }, [_selectRowsWithOptionalFlash, beforeUpdate]);
2214
+ var flashRowsDiff = useCallback(function (fn) { return __awaiter(void 0, void 0, void 0, function () {
2212
2215
  return __generator(this, function (_a) {
2213
2216
  switch (_a.label) {
2214
2217
  case 0:
@@ -2220,15 +2223,15 @@ var GridContextProvider = function (props) {
2220
2223
  return [2 /*return*/];
2221
2224
  }
2222
2225
  });
2223
- }); };
2224
- var getSelectedRows = function () {
2226
+ }); }, [_selectRowsWithOptionalFlash, beforeUpdate]);
2227
+ var getSelectedRows = useCallback(function () {
2225
2228
  return gridApiOp(function (gridApi) { return gridApi.getSelectedRows(); }, function () { return []; });
2226
- };
2227
- var getSelectedRowIds = function () { return getSelectedRows().map(function (row) { return row.id; }); };
2228
- var editingCells = function () {
2229
+ }, [gridApiOp]);
2230
+ var getSelectedRowIds = useCallback(function () { return getSelectedRows().map(function (row) { return row.id; }); }, [getSelectedRows]);
2231
+ var editingCells = useCallback(function () {
2229
2232
  return gridApiOp(function (gridApi) { return isNotEmpty(gridApi.getEditingCells()); }, function () { return false; });
2230
- };
2231
- var ensureRowVisible = function (id) {
2233
+ }, [gridApiOp]);
2234
+ var ensureRowVisible = useCallback(function (id) {
2232
2235
  return gridApiOp(function (gridApi) {
2233
2236
  var node = gridApi.getRowNode("".concat(id));
2234
2237
  if (!node)
@@ -2236,29 +2239,38 @@ var GridContextProvider = function (props) {
2236
2239
  gridApi.ensureNodeVisible(node);
2237
2240
  return true;
2238
2241
  });
2239
- };
2242
+ }, [gridApiOp]);
2240
2243
  /**
2241
2244
  * Scroll last selected row into view on grid sort change
2242
2245
  */
2243
- var ensureSelectedRowIsVisible = function () {
2246
+ var ensureSelectedRowIsVisible = useCallback(function () {
2244
2247
  gridApiOp(function (gridApi) {
2245
2248
  var selectedNodes = gridApi.getSelectedNodes();
2246
2249
  if (isEmpty(selectedNodes))
2247
2250
  return;
2248
2251
  gridApi.ensureNodeVisible(last(selectedNodes));
2249
2252
  });
2250
- };
2253
+ }, [gridApiOp]);
2251
2254
  /**
2252
2255
  * Resize columns to fit container
2253
2256
  */
2254
- var sizeColumnsToFit = function () {
2257
+ var sizeColumnsToFit = useCallback(function () {
2255
2258
  gridApiOp(function (gridApi) {
2256
2259
  // Hide size columns to fit errors in tests
2257
2260
  document.body.clientWidth && gridApi.sizeColumnsToFit();
2258
2261
  });
2259
- };
2260
- var stopEditing = function () { return gridApiOp(function (gridApi) { return gridApi.stopEditing(); }); };
2261
- var updatingCells = function (props, fnUpdate, setSaving, tabDirection) { return __awaiter(void 0, void 0, void 0, function () {
2262
+ }, [gridApiOp]);
2263
+ var stopEditing = useCallback(function () { return gridApiOp(function (gridApi) { return gridApi.stopEditing(); }); }, [gridApiOp]);
2264
+ var selectNextCell = useCallback(function (tabDirection) {
2265
+ if (tabDirection === void 0) { tabDirection = 0; }
2266
+ gridApiOp(function (gridApi) {
2267
+ if (tabDirection == 1)
2268
+ gridApi.tabToNextCell();
2269
+ if (tabDirection == -1)
2270
+ gridApi.tabToPreviousCell();
2271
+ });
2272
+ }, [gridApiOp]);
2273
+ var updatingCells = useCallback(function (props, fnUpdate, setSaving, tabDirection) { return __awaiter(void 0, void 0, void 0, function () {
2262
2274
  return __generator(this, function (_a) {
2263
2275
  switch (_a.label) {
2264
2276
  case 0:
@@ -2319,25 +2331,16 @@ var GridContextProvider = function (props) {
2319
2331
  case 1: return [2 /*return*/, _a.sent()];
2320
2332
  }
2321
2333
  });
2322
- }); };
2323
- var redrawRows = function (rowNodes) {
2334
+ }); }, [gridApiOp, modifyUpdating, selectNextCell]);
2335
+ var redrawRows = useCallback(function (rowNodes) {
2324
2336
  gridApiOp(function (gridApi) {
2325
2337
  gridApi.redrawRows(rowNodes ? { rowNodes: rowNodes } : undefined);
2326
2338
  });
2327
- };
2328
- var selectNextCell = function (tabDirection) {
2329
- if (tabDirection === void 0) { tabDirection = 0; }
2330
- gridApiOp(function (gridApi) {
2331
- if (tabDirection == 1)
2332
- gridApi.tabToNextCell();
2333
- if (tabDirection == -1)
2334
- gridApi.tabToPreviousCell();
2335
- });
2336
- };
2337
- var setExternallySelectedItemsAreInSync = function (inSync) {
2339
+ }, [gridApiOp]);
2340
+ var setExternallySelectedItemsAreInSync = useCallback(function (inSync) {
2338
2341
  externallySelectedItemsAreInSync.current = inSync;
2339
- };
2340
- var waitForExternallySelectedItemsToBeInSync = function () { return __awaiter(void 0, void 0, void 0, function () {
2342
+ }, []);
2343
+ var waitForExternallySelectedItemsToBeInSync = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
2341
2344
  var i;
2342
2345
  return __generator(this, function (_a) {
2343
2346
  switch (_a.label) {
@@ -2356,7 +2359,7 @@ var GridContextProvider = function (props) {
2356
2359
  case 4: return [2 /*return*/];
2357
2360
  }
2358
2361
  });
2359
- }); };
2362
+ }); }, []);
2360
2363
  return (jsx(GridContext.Provider, __assign({ value: {
2361
2364
  gridReady: gridReady,
2362
2365
  setGridApi: setGridApi,
@@ -2679,9 +2682,9 @@ var GridHeaderSelect = function (_a) {
2679
2682
  // This is used to force an update on selection change
2680
2683
  var _b = useState(0), updateCounter = _b[0], setUpdateCounter = _b[1];
2681
2684
  var selectedNodeCount = api.getSelectedRows().length;
2682
- var clickHandler = function () {
2685
+ var clickHandler = useCallback(function () {
2683
2686
  setUpdateCounter(updateCounter + 1);
2684
- };
2687
+ }, [updateCounter]);
2685
2688
  useEffect(function () {
2686
2689
  api.addEventListener("selectionChanged", clickHandler);
2687
2690
  return function () { return api.removeEventListener("selectionChanged", clickHandler); };
@@ -2832,9 +2835,9 @@ var Grid = function (params) {
2832
2835
  else {
2833
2836
  e.api.deselectAll();
2834
2837
  }
2835
- return false;
2838
+ return true;
2836
2839
  }
2837
- return true;
2840
+ return false;
2838
2841
  },
2839
2842
  onCellClicked: clickSelectorCheckboxWhenContainingCellClicked
2840
2843
  }
@@ -3215,8 +3218,7 @@ var fieldToString = function (field) {
3215
3218
  return typeof field == "symbol" ? field.toString() : "".concat(field);
3216
3219
  };
3217
3220
  var GridFormDropDown = function (props) {
3218
- var stopEditing = useContext(GridContext).stopEditing;
3219
- var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue, data = _a.data;
3221
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, data = _a.data;
3220
3222
  // Save triggers during async action processing which triggers another selectItem(), this ref blocks that
3221
3223
  var _b = useState(""), filter = _b[0], setFilter = _b[1];
3222
3224
  var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
@@ -3225,7 +3227,8 @@ var GridFormDropDown = function (props) {
3225
3227
  var subComponentIsValid = useRef(false);
3226
3228
  var subComponentInitialValue = useRef(null);
3227
3229
  var _e = useState(null), subSelectedValue = _e[0], setSubSelectedValue = _e[1];
3228
- var _f = useState(null), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
3230
+ // Note: null is assumed to be the filter
3231
+ var _f = useState(null), selectedItem = _f[0], setSelectedItem = _f[1];
3229
3232
  var selectItemHandler = useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
3230
3233
  var hasChanged;
3231
3234
  return __generator(this, function (_a) {
@@ -3246,45 +3249,6 @@ var GridFormDropDown = function (props) {
3246
3249
  }
3247
3250
  });
3248
3251
  }); }, [field, props, selectedRows]);
3249
- var clickItemHandler = useCallback(function (value, subComponentValue, reason) { return __awaiter(void 0, void 0, void 0, function () {
3250
- return __generator(this, function (_a) {
3251
- if (subComponentValue !== undefined && !subComponentIsValid.current)
3252
- return [2 /*return*/, false];
3253
- return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3254
- return __generator(this, function (_a) {
3255
- switch (_a.label) {
3256
- case 0: return [4 /*yield*/, selectItemHandler(value, subComponentValue)];
3257
- case 1: return [2 /*return*/, _a.sent()];
3258
- }
3259
- });
3260
- }); }, reason === CloseReason.TAB_FORWARD ? 1 : reason === CloseReason.TAB_BACKWARD ? -1 : 0)];
3261
- });
3262
- }); }, [selectItemHandler, updateValue]);
3263
- var selectFilterHandler = useCallback(function (value) { return __awaiter(void 0, void 0, void 0, function () {
3264
- return __generator(this, function (_a) {
3265
- switch (_a.label) {
3266
- case 0: return [4 /*yield*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3267
- var _a;
3268
- return __generator(this, function (_b) {
3269
- switch (_b.label) {
3270
- case 0:
3271
- _a = props.onSelectFilter;
3272
- if (!_a) return [3 /*break*/, 2];
3273
- return [4 /*yield*/, props.onSelectFilter({ selectedRows: selectedRows, value: value })];
3274
- case 1:
3275
- _a = (_b.sent());
3276
- _b.label = 2;
3277
- case 2:
3278
- return [2 /*return*/, true];
3279
- }
3280
- });
3281
- }); }, 0)];
3282
- case 1:
3283
- _a.sent();
3284
- return [2 /*return*/];
3285
- }
3286
- });
3287
- }); }, [props, updateValue]);
3288
3252
  // Load up options list if it's async function
3289
3253
  useEffect(function () {
3290
3254
  var _a;
@@ -3338,7 +3302,7 @@ var GridFormDropDown = function (props) {
3338
3302
  return undefined;
3339
3303
  }
3340
3304
  var str = option.label || "";
3341
- return str.toLowerCase().indexOf(filter.toLowerCase()) === -1 ? option.value : undefined;
3305
+ return str.toLowerCase().indexOf(filter.toLowerCase()) !== -1 ? option : undefined;
3342
3306
  })
3343
3307
  .filter(function (r) { return r !== undefined; }));
3344
3308
  }
@@ -3359,83 +3323,67 @@ var GridFormDropDown = function (props) {
3359
3323
  * Saves are wrapped in updateValue and triggered by blur events
3360
3324
  */
3361
3325
  var save = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
3326
+ var onSelectFilter;
3362
3327
  return __generator(this, function (_a) {
3363
3328
  switch (_a.label) {
3364
3329
  case 0:
3365
3330
  if (!options)
3366
3331
  return [2 /*return*/, true];
3367
- // Handler for sub-selected value
3368
- if (!selectedSubComponent)
3369
- return [2 /*return*/, true];
3370
- if (selectedSubComponent.subComponent && !subComponentIsValid.current)
3371
- return [2 /*return*/, false];
3372
- return [4 /*yield*/, selectItemHandler(selectedSubComponent.value, subSelectedValue)];
3332
+ if (!(selectedItem === null)) return [3 /*break*/, 5];
3333
+ if (!props.onSelectFilter) return [3 /*break*/, 2];
3334
+ onSelectFilter = props.onSelectFilter;
3335
+ return [4 /*yield*/, onSelectFilter({ selectedRows: selectedRows, value: filter })];
3373
3336
  case 1:
3374
3337
  _a.sent();
3375
3338
  return [2 /*return*/, true];
3339
+ case 2:
3340
+ if (!(filteredValues.length === 1)) return [3 /*break*/, 4];
3341
+ if (filteredValues[0].subComponent)
3342
+ return [2 /*return*/, false];
3343
+ return [4 /*yield*/, selectItemHandler(filteredValues[0].value, null)];
3344
+ case 3: return [2 /*return*/, _a.sent()];
3345
+ case 4: return [2 /*return*/, false];
3346
+ case 5:
3347
+ if (selectedItem.subComponent && !subComponentIsValid.current)
3348
+ return [2 /*return*/, false];
3349
+ return [4 /*yield*/, selectItemHandler(selectedItem.value, subSelectedValue)];
3350
+ case 6:
3351
+ _a.sent();
3352
+ return [2 /*return*/, true];
3376
3353
  }
3377
3354
  });
3378
- }); }, [options, selectItemHandler, selectedSubComponent, subSelectedValue]);
3355
+ }); }, [filter, filteredValues, options, props, selectItemHandler, selectedItem, selectedRows, subSelectedValue]);
3379
3356
  var popoverWrapper = useGridPopoverHook({
3380
3357
  className: props.className,
3381
- invalid: function () { return !!(selectedSubComponent && !subComponentIsValid.current); },
3358
+ invalid: function () { return !!(selectedItem && !subComponentIsValid.current); },
3382
3359
  save: save
3383
3360
  }).popoverWrapper;
3384
- var enterKeyPressedRef = useRef(false);
3385
- var handleKeyDown = useCallback(function (e) {
3386
- if (e.key === "Enter") {
3387
- e.stopPropagation();
3388
- e.preventDefault();
3389
- enterKeyPressedRef.current = true;
3390
- }
3391
- }, []);
3392
- var handleKeyUp = useCallback(function (e) { return __awaiter(void 0, void 0, void 0, function () {
3393
- var _a;
3394
- return __generator(this, function (_b) {
3395
- switch (_b.label) {
3396
- case 0:
3397
- if (!options)
3398
- return [2 /*return*/];
3399
- if (!(e.key === "Enter")) return [3 /*break*/, 3];
3400
- e.stopPropagation();
3401
- e.preventDefault();
3402
- if (!enterKeyPressedRef.current)
3403
- return [2 /*return*/];
3404
- _a = props.onSelectFilter;
3405
- if (!_a) return [3 /*break*/, 2];
3406
- return [4 /*yield*/, selectFilterHandler(filter)];
3407
- case 1:
3408
- _a = (_b.sent());
3409
- _b.label = 2;
3410
- case 2:
3411
- stopEditing();
3412
- _b.label = 3;
3413
- case 3: return [2 /*return*/];
3414
- }
3415
- });
3416
- }); }, [filter, options, props.onSelectFilter, selectFilterHandler, stopEditing]);
3417
- return popoverWrapper(jsxs(Fragment$1, { children: [props.filtered && (jsxs("div", __assign({ className: "GridFormDropDown-filter" }, { children: [jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
3361
+ return popoverWrapper(jsxs(Fragment$1, { children: [props.filtered && (jsxs("div", __assign({ className: "GridFormDropDown-filter" }, { children: [jsx(FocusableItem, __assign({ className: "filter-item", onFocus: function () {
3362
+ setSelectedItem(null);
3363
+ setSubSelectedValue(null);
3364
+ subComponentIsValid.current = true;
3365
+ } }, { children: function (_a) {
3418
3366
  var _b;
3419
3367
  var ref = _a.ref;
3420
- return (jsxs("div", __assign({ style: { display: "flex", flexDirection: "column", width: "100%" } }, { children: [jsx("input", { autoFocus: true, className: "LuiTextInput-input", ref: ref, type: "text", placeholder: (_b = props.filterPlaceholder) !== null && _b !== void 0 ? _b : "Placeholder", "data-testid": "filteredMenu-free-text-input", defaultValue: filter, "data-disableenterautosave": true, "data-allowtabtosave": true, onChange: function (e) { return setFilter(e.target.value); }, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }), props.filterHelpText && isNotEmpty(filter) && (jsx(FormError, { error: null, helpText: props.filterHelpText }))] })));
3421
- } })), jsx(MenuDivider, {}, "$$divider_filter")] }))), jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxs(Fragment$1, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && (jsx(MenuItem, __assign({ className: "GridPopoverEditDropDown-noOptions" }, { children: "No Options" }), "".concat(fieldToString(field), "-empty"))), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3368
+ return (jsxs("div", __assign({ style: { display: "flex", flexDirection: "column", width: "100%" } }, { children: [jsx("input", { className: "LuiTextInput-input", ref: ref, type: "text", placeholder: (_b = props.filterPlaceholder) !== null && _b !== void 0 ? _b : "Placeholder", "data-testid": "filteredMenu-free-text-input", defaultValue: filter, "data-allowtabtosave": true, "data-disableenterautosave": !props.onSelectFilter && !(filteredValues.length === 1 && !filteredValues[0].subComponent), onChange: function (e) { return setFilter(e.target.value); } }), props.filterHelpText && isNotEmpty(filter) && (jsx(FormError, { error: null, helpText: props.filterHelpText }))] })));
3369
+ } })), jsx(MenuDivider, {}, "$$divider_filter")] }))), jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxs(Fragment$1, { children: [options && isEmpty(filteredValues) && (jsx(MenuItem, __assign({ className: "GridPopoverEditDropDown-noOptions" }, { children: "No Options" }), "".concat(fieldToString(field), "-empty"))), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3422
3370
  var _a;
3423
- return item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsx(MenuHeader, { children: item.label }, "$$header_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxs("div", { children: [jsxs(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function (e) {
3371
+ return item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsx(MenuHeader, { children: item.label }, "$$header_".concat(index))) : (filteredValues.includes(item) && (jsxs("div", { children: [jsxs(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onFocus: function () {
3372
+ setSelectedItem(item);
3424
3373
  if (item.subComponent) {
3425
- // toggle selection
3426
- setSelectedSubComponent(selectedSubComponent === item ? null : item);
3374
+ setSelectedItem(item);
3427
3375
  subComponentIsValid.current = true;
3428
3376
  subComponentInitialValue.current = null;
3429
- e.keepOpen = true;
3430
3377
  }
3431
3378
  else {
3432
- clickItemHandler(item.value, undefined, e.key === "Tab"
3433
- ? e.shiftKey
3434
- ? CloseReason.TAB_BACKWARD
3435
- : CloseReason.TAB_FORWARD
3436
- : CloseReason.CLICK).then();
3379
+ setSubSelectedValue(null);
3380
+ subComponentIsValid.current = true;
3381
+ }
3382
+ }, onClick: function (e) {
3383
+ if (item.subComponent) {
3384
+ e.keepOpen = true;
3437
3385
  }
3438
- } }, { children: [(_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)), item.subComponent ? "..." : ""] }), "".concat(fieldToString(field), "-").concat(index)), item.subComponent && selectedSubComponent === item && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) { return (jsx(GridSubComponentContext.Provider, __assign({ value: {
3386
+ } }, { children: [(_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)), item.subComponent ? "..." : ""] }), "".concat(fieldToString(field), "-").concat(index)), item.subComponent && selectedItem === item && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) { return (jsx(GridSubComponentContext.Provider, __assign({ value: {
3439
3387
  context: { options: options },
3440
3388
  data: data,
3441
3389
  value: subSelectedValue,
@@ -3455,7 +3403,7 @@ var GridFormDropDown = function (props) {
3455
3403
  return [2 /*return*/];
3456
3404
  });
3457
3405
  }); }
3458
- } }, { children: item.subComponent && (jsx("div", __assign({ className: "subComponent" }, { children: jsx(item.subComponent, {}, "".concat(fieldToString(field), "-").concat(index, "_subcomponent_inner")) }))) }))); } }), "".concat(item.label, "_subcomponent")))] }, "menu-wrapper-".concat(index)));
3406
+ } }, { children: item.subComponent && (jsx("div", __assign({ className: "subComponent" }, { children: jsx(item.subComponent, {}, "".concat(fieldToString(field), "-").concat(index, "_subcomponent_inner")) }))) }))); } }), "".concat(item.label, "_subcomponent")))] }, "menu-wrapper-".concat(index))));
3459
3407
  })] }) }))] }));
3460
3408
  };
3461
3409