@linzjs/step-ag-grid 2.4.2 → 2.4.4
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/dist/index.js +111 -40
- package/dist/index.js.map +1 -1
- package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +2 -1
- package/dist/src/contexts/GridContext.d.ts +2 -1
- package/dist/src/lui/ActionButton.d.ts +6 -3
- package/dist/step-ag-grid.esm.js +111 -40
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/PostSortRowsHook.ts +78 -25
- package/src/components/gridForm/GridFormSubComponentTextInput.tsx +12 -1
- package/src/contexts/GridContext.tsx +5 -1
- package/src/contexts/GridContextProvider.tsx +7 -0
- package/src/lui/ActionButton.tsx +23 -13
- package/src/stories/components/ActionButton.stories.tsx +6 -1
package/dist/index.js
CHANGED
|
@@ -1868,7 +1868,10 @@ var GridContext = react.createContext({
|
|
|
1868
1868
|
console.error("no context provider for modifyUpdating");
|
|
1869
1869
|
return [2 /*return*/, false];
|
|
1870
1870
|
});
|
|
1871
|
-
}); }
|
|
1871
|
+
}); },
|
|
1872
|
+
redrawRows: function () {
|
|
1873
|
+
console.error("no context provider for redrawRows");
|
|
1874
|
+
}
|
|
1872
1875
|
});
|
|
1873
1876
|
|
|
1874
1877
|
/**
|
|
@@ -2122,6 +2125,11 @@ var GridContextProvider = function (props) {
|
|
|
2122
2125
|
}
|
|
2123
2126
|
});
|
|
2124
2127
|
}); };
|
|
2128
|
+
var redrawRows = function (rowNodes) {
|
|
2129
|
+
gridApiOp(function (gridApi) {
|
|
2130
|
+
gridApi.redrawRows(rowNodes ? { rowNodes: rowNodes } : undefined);
|
|
2131
|
+
});
|
|
2132
|
+
};
|
|
2125
2133
|
return (jsxRuntime.jsx(GridContext.Provider, __assign({ value: {
|
|
2126
2134
|
gridReady: gridReady,
|
|
2127
2135
|
setGridApi: setGridApi,
|
|
@@ -2139,7 +2147,8 @@ var GridContextProvider = function (props) {
|
|
|
2139
2147
|
ensureSelectedRowIsVisible: ensureSelectedRowIsVisible,
|
|
2140
2148
|
sizeColumnsToFit: sizeColumnsToFit,
|
|
2141
2149
|
stopEditing: stopEditing,
|
|
2142
|
-
updatingCells: updatingCells
|
|
2150
|
+
updatingCells: updatingCells,
|
|
2151
|
+
redrawRows: redrawRows
|
|
2143
2152
|
} }, { children: props.children })));
|
|
2144
2153
|
};
|
|
2145
2154
|
|
|
@@ -2188,6 +2197,7 @@ function clsx () {
|
|
|
2188
2197
|
*/
|
|
2189
2198
|
var usePostSortRowsHook = function (_a) {
|
|
2190
2199
|
var setStaleGrid = _a.setStaleGrid;
|
|
2200
|
+
var redrawRows = react.useContext(GridContext).redrawRows;
|
|
2191
2201
|
// On first run we need to init the first backed up sort order
|
|
2192
2202
|
var initialised = react.useRef(false);
|
|
2193
2203
|
// Used to detect sort order has changed since last run
|
|
@@ -2203,14 +2213,20 @@ var usePostSortRowsHook = function (_a) {
|
|
|
2203
2213
|
var previousQuickFilter = react.useRef("");
|
|
2204
2214
|
return react.useCallback(function (_a) {
|
|
2205
2215
|
var api = _a.api, columnApi = _a.columnApi, nodes = _a.nodes;
|
|
2216
|
+
// Grid is destroyed
|
|
2217
|
+
if (!api || !columnApi)
|
|
2218
|
+
return;
|
|
2206
2219
|
var previousRowSortIndex = previousRowSortIndexRef.current;
|
|
2220
|
+
var hashNode = function (node) {
|
|
2221
|
+
return node ? JSON.stringify(node.data) : "";
|
|
2222
|
+
};
|
|
2207
2223
|
var copyCurrentSortSettings = function () {
|
|
2208
2224
|
return columnApi.getColumnState().map(function (row) { return ({ colId: row.colId, sort: row.sort, sortIndex: row.sortIndex }); });
|
|
2209
2225
|
};
|
|
2210
2226
|
var backupSortOrder = function () {
|
|
2211
2227
|
for (var x in previousRowSortIndex)
|
|
2212
2228
|
delete previousRowSortIndex[x];
|
|
2213
|
-
nodes.forEach(function (
|
|
2229
|
+
nodes.forEach(function (node, index) { return (previousRowSortIndex["".concat(node.data.id)] = { index: index, hash: hashNode(node) }); });
|
|
2214
2230
|
};
|
|
2215
2231
|
// Check if column is the first sorted column. Note: column is preconfigured to sort its sortIndex is null not 1
|
|
2216
2232
|
var isFirstSortColumn = function (row) { var _a; return row.sort && [0, null].includes((_a = row.sortIndex) !== null && _a !== void 0 ? _a : null); };
|
|
@@ -2218,19 +2234,11 @@ var usePostSortRowsHook = function (_a) {
|
|
|
2218
2234
|
return col1 && col2 && col1.colId === col2.colId && col1.sort != col2.sort;
|
|
2219
2235
|
};
|
|
2220
2236
|
var restorePreviousSortColumnState = function () { return columnApi.applyColumnState({ state: previousColSort.current }); };
|
|
2221
|
-
var hasNewRows = function () { return nodes.some(function (row) { return previousRowSortIndex[row.data.id] == null; }); };
|
|
2222
|
-
var sortIsStale = function () {
|
|
2223
|
-
// If there are new rows we want to them to be at the bottom of the grid, so we treat it as sort not stale
|
|
2224
|
-
if (hasNewRows())
|
|
2225
|
-
return false;
|
|
2226
|
-
// Otherwise check if the stored sort index matches the new sort index
|
|
2227
|
-
return nodes.some(function (node, index) { return previousRowSortIndex[node.data.id] != index; });
|
|
2228
|
-
};
|
|
2229
2237
|
var sortNodesByPreviousSort = function () {
|
|
2230
|
-
|
|
2231
|
-
var _a, _b;
|
|
2232
|
-
return ((_a = previousRowSortIndex[a.data.id]) !== null &&
|
|
2233
|
-
((
|
|
2238
|
+
nodes.sort(function (a, b) {
|
|
2239
|
+
var _a, _b, _c, _d;
|
|
2240
|
+
return ((_b = (_a = previousRowSortIndex["".concat(a.data.id)]) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER) -
|
|
2241
|
+
((_d = (_c = previousRowSortIndex["".concat(b.data.id)]) === null || _c === void 0 ? void 0 : _c.index) !== null && _d !== void 0 ? _d : Number.MAX_SAFE_INTEGER);
|
|
2234
2242
|
});
|
|
2235
2243
|
};
|
|
2236
2244
|
// On first load copy the current sort
|
|
@@ -2245,6 +2253,9 @@ var usePostSortRowsHook = function (_a) {
|
|
|
2245
2253
|
previousQuickFilter.current = quickFilter;
|
|
2246
2254
|
sortOrderChanged = true;
|
|
2247
2255
|
}
|
|
2256
|
+
if (lodashEs.isEmpty(previousRowSortIndex)) {
|
|
2257
|
+
backupSortOrder();
|
|
2258
|
+
}
|
|
2248
2259
|
if (sortOrderChanged) {
|
|
2249
2260
|
var thisFirstCol = copyCurrentSortSettings().find(isFirstSortColumn);
|
|
2250
2261
|
var previousFirstCol = previousColSort.current.find(isFirstSortColumn);
|
|
@@ -2275,22 +2286,72 @@ var usePostSortRowsHook = function (_a) {
|
|
|
2275
2286
|
}
|
|
2276
2287
|
}
|
|
2277
2288
|
else {
|
|
2278
|
-
|
|
2289
|
+
var firstChangedNodeIndex = -1;
|
|
2290
|
+
var lastNewNode = undefined;
|
|
2291
|
+
var changedRowCount = 0;
|
|
2292
|
+
var newRowCount = 0;
|
|
2293
|
+
var index = 0;
|
|
2294
|
+
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
|
|
2295
|
+
var node = nodes_1[_i];
|
|
2296
|
+
var psr = previousRowSortIndex["".concat(node.data.id)];
|
|
2297
|
+
if (psr) {
|
|
2298
|
+
if (psr.hash != hashNode(node)) {
|
|
2299
|
+
if (firstChangedNodeIndex === -1)
|
|
2300
|
+
firstChangedNodeIndex = index;
|
|
2301
|
+
changedRowCount++;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
else {
|
|
2305
|
+
lastNewNode = node;
|
|
2306
|
+
newRowCount++;
|
|
2307
|
+
}
|
|
2308
|
+
index++;
|
|
2309
|
+
}
|
|
2310
|
+
var wasStale = false;
|
|
2311
|
+
if (changedRowCount === 0 && newRowCount === 1) {
|
|
2312
|
+
// insert new row at end
|
|
2313
|
+
var newIndex = index - 1;
|
|
2314
|
+
previousRowSortIndex["".concat(lastNewNode === null || lastNewNode === void 0 ? void 0 : lastNewNode.data.id)] = { index: newIndex, hash: hashNode(lastNewNode) };
|
|
2315
|
+
wasStale = true;
|
|
2316
|
+
}
|
|
2317
|
+
else if (changedRowCount === 2 && newRowCount === 0) {
|
|
2318
|
+
// This must be a swap rows
|
|
2319
|
+
backupSortOrder();
|
|
2320
|
+
wasStale = false;
|
|
2321
|
+
}
|
|
2322
|
+
else if (changedRowCount > 1 && newRowCount === 1) {
|
|
2323
|
+
// This must be a insert so, insert new row near the row that changed
|
|
2324
|
+
previousRowSortIndex["".concat(lastNewNode === null || lastNewNode === void 0 ? void 0 : lastNewNode.data.id)] = {
|
|
2325
|
+
index: firstChangedNodeIndex + 0.5,
|
|
2326
|
+
hash: hashNode(lastNewNode)
|
|
2327
|
+
};
|
|
2328
|
+
wasStale = true;
|
|
2329
|
+
// For some reason AgGrid mis-positions the inserted row.
|
|
2330
|
+
lastNewNode && redrawRows();
|
|
2331
|
+
}
|
|
2332
|
+
else if (changedRowCount == 1 && newRowCount === 0) {
|
|
2333
|
+
// User edited one row so, do nothing, retain sort
|
|
2334
|
+
wasStale = true;
|
|
2335
|
+
}
|
|
2336
|
+
else if (changedRowCount !== 0 || newRowCount != 0) {
|
|
2337
|
+
// too many rows changed, resort
|
|
2338
|
+
backupSortOrder();
|
|
2339
|
+
}
|
|
2340
|
+
if (wasStale) {
|
|
2341
|
+
// Check if the sort order the aggrid passed matches our stale sort order
|
|
2342
|
+
var stillStale = Object.keys(previousRowSortIndex).length != nodes.length ||
|
|
2343
|
+
nodes.some(function (node, index) { var _a; return ((_a = previousRowSortIndex["".concat(node.data.id)]) === null || _a === void 0 ? void 0 : _a.index) !== index; });
|
|
2279
2344
|
// If we haven't already processed a stale sort then...
|
|
2280
|
-
if (!sortWasStale.current) {
|
|
2345
|
+
if (stillStale && !sortWasStale.current) {
|
|
2281
2346
|
// backup sort state, so we can restore it when sort is clicked on a stale column
|
|
2282
2347
|
previousColSort.current = copyCurrentSortSettings();
|
|
2283
|
-
backupSortOrder();
|
|
2284
2348
|
sortWasStale.current = true;
|
|
2285
2349
|
setStaleGrid(true);
|
|
2286
2350
|
}
|
|
2287
|
-
sortNodesByPreviousSort();
|
|
2288
2351
|
}
|
|
2289
|
-
|
|
2290
|
-
// which would cause two new rows to sort out of sequence
|
|
2291
|
-
backupSortOrder();
|
|
2352
|
+
sortNodesByPreviousSort();
|
|
2292
2353
|
}
|
|
2293
|
-
}, [setStaleGrid]);
|
|
2354
|
+
}, [redrawRows, setStaleGrid]);
|
|
2294
2355
|
};
|
|
2295
2356
|
|
|
2296
2357
|
/**
|
|
@@ -3661,10 +3722,11 @@ var GridPopoverTextInput = function (colDef, params) {
|
|
|
3661
3722
|
};
|
|
3662
3723
|
|
|
3663
3724
|
var GridFormSubComponentTextInput = function (_a) {
|
|
3664
|
-
var keyDown = _a.keyDown, placeholder = _a.placeholder, setValue = _a.setValue;
|
|
3725
|
+
var keyDown = _a.keyDown, placeholder = _a.placeholder, setValue = _a.setValue, className = _a.className;
|
|
3665
3726
|
var placeholderText = placeholder || "Other...";
|
|
3727
|
+
var inputClass = className || "";
|
|
3666
3728
|
var _b = react.useState(""), inputValue = _b[0], setInputValue = _b[1];
|
|
3667
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(TextInputFormatted, { value: inputValue, onChange: function (e) {
|
|
3729
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(TextInputFormatted, { className: inputClass, value: inputValue, onChange: function (e) {
|
|
3668
3730
|
var value = e.target.value;
|
|
3669
3731
|
setValue(value);
|
|
3670
3732
|
setInputValue(value);
|
|
@@ -3675,6 +3737,9 @@ var GridFormSubComponentTextInput = function (_a) {
|
|
|
3675
3737
|
if (document.activeElement != e.currentTarget) {
|
|
3676
3738
|
e.currentTarget.focus();
|
|
3677
3739
|
}
|
|
3740
|
+
},
|
|
3741
|
+
style: {
|
|
3742
|
+
width: "100%"
|
|
3678
3743
|
}
|
|
3679
3744
|
} }) }));
|
|
3680
3745
|
};
|
|
@@ -3793,38 +3858,44 @@ var useStateDeferred = function (initialValue) {
|
|
|
3793
3858
|
// Kept this less than one second, so I don't have issues with waitFor as it defaults to 1s
|
|
3794
3859
|
var minimumInProgressTimeMs = 950;
|
|
3795
3860
|
var ActionButton = function (_a) {
|
|
3796
|
-
var _b;
|
|
3797
|
-
var
|
|
3798
|
-
var
|
|
3799
|
-
var _e = react.useState(false), inProgress = _e[0], setInProgress = _e[1];
|
|
3861
|
+
var _b, _c, _d;
|
|
3862
|
+
var icon = _a.icon, name = _a.name, inProgressName = _a.inProgressName, dataTestId = _a.dataTestId, className = _a.className, title = _a.title, onAction = _a.onAction, externalSetInProgress = _a.externalSetInProgress, _e = _a.size, size = _e === void 0 ? "sm" : _e, _f = _a.level, level = _f === void 0 ? "tertiary" : _f, ariaLabel = _a["aria-label"];
|
|
3863
|
+
var _g = react.useState(false), inProgress = _g[0], setInProgress = _g[1];
|
|
3800
3864
|
var lastInProgress = usePrevious(inProgress !== null && inProgress !== void 0 ? inProgress : false);
|
|
3801
|
-
var
|
|
3865
|
+
var _h = useStateDeferred(inProgress), localInProgress = _h[0], setLocalInProgress = _h[1], setLocalInProgressDeferred = _h[2];
|
|
3802
3866
|
react.useEffect(function () {
|
|
3803
3867
|
if (inProgress == lastInProgress)
|
|
3804
3868
|
return;
|
|
3805
3869
|
inProgress ? setLocalInProgress(true) : setLocalInProgressDeferred(false, minimumInProgressTimeMs);
|
|
3806
3870
|
}, [inProgress, lastInProgress, setLocalInProgress, setLocalInProgressDeferred]);
|
|
3807
|
-
return (jsxRuntime.jsxs(lui.LuiButton, __assign({ "data-testid": dataTestId, type: "button", level:
|
|
3871
|
+
return (jsxRuntime.jsxs(lui.LuiButton, __assign({ "data-testid": dataTestId, type: "button", level: level, title: (_b = title !== null && title !== void 0 ? title : ariaLabel) !== null && _b !== void 0 ? _b : name, "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : name, className: clsx("lui-button-icon", "ActionButton", className, localInProgress && "ActionButton-inProgress"), size: "lg", style: name == null ? { padding: "8px 5px" } : {}, onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
3872
|
+
var promise, isPromise;
|
|
3808
3873
|
return __generator(this, function (_a) {
|
|
3809
3874
|
switch (_a.label) {
|
|
3810
3875
|
case 0:
|
|
3876
|
+
promise = onAction();
|
|
3877
|
+
isPromise = typeof promise !== "undefined";
|
|
3878
|
+
if (!isPromise) return [3 /*break*/, 3];
|
|
3811
3879
|
setInProgress(true);
|
|
3812
3880
|
externalSetInProgress && setInProgress(true);
|
|
3813
|
-
return [
|
|
3881
|
+
if (!isPromise) return [3 /*break*/, 2];
|
|
3882
|
+
return [4 /*yield*/, promise];
|
|
3814
3883
|
case 1:
|
|
3815
3884
|
_a.sent();
|
|
3885
|
+
_a.label = 2;
|
|
3886
|
+
case 2:
|
|
3816
3887
|
externalSetInProgress && setInProgress(false);
|
|
3817
3888
|
setInProgress(false);
|
|
3818
|
-
|
|
3889
|
+
_a.label = 3;
|
|
3890
|
+
case 3: return [2 /*return*/];
|
|
3819
3891
|
}
|
|
3820
3892
|
});
|
|
3821
|
-
}); }, disabled: localInProgress }, { children: [localInProgress ? (jsxRuntime.jsx(lui.LuiMiniSpinner, { size: 16, divProps:
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
_b) })) : (jsxRuntime.jsx(lui.LuiIcon, { name: icon, alt: name, size: size })), jsxRuntime.jsxs("span", __assign({ className: "ActionButton-minimalArea" }, { children: [jsxRuntime.jsx("span", __assign({ className: "ActionButton-minimalAreaDisplay" }, { children: (_c = (localInProgress ? inProgressName : name)) !== null && _c !== void 0 ? _c : name })), jsxRuntime.jsx("span", __assign({ className: "ActionButton-minimalAreaExpand" }, { children: name }))] }))] })));
|
|
3893
|
+
}); }, disabled: localInProgress }, { children: [localInProgress ? (jsxRuntime.jsx(lui.LuiMiniSpinner, { size: 16, divProps: {
|
|
3894
|
+
"data-testid": "loading-spinner",
|
|
3895
|
+
style: { margin: 0, paddingRight: 5, paddingLeft: 3, paddingBottom: 0, paddingTop: 0 },
|
|
3896
|
+
role: "status",
|
|
3897
|
+
"aria-label": "Loading"
|
|
3898
|
+
} })) : (jsxRuntime.jsx(lui.LuiIcon, { name: icon, alt: (_c = ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : name) !== null && _c !== void 0 ? _c : "", size: size })), jsxRuntime.jsxs("span", __assign({ className: "ActionButton-minimalArea" }, { children: [jsxRuntime.jsx("span", __assign({ className: "ActionButton-minimalAreaDisplay" }, { children: (_d = (localInProgress ? inProgressName : name)) !== null && _d !== void 0 ? _d : name })), jsxRuntime.jsx("span", __assign({ className: "ActionButton-minimalAreaExpand" }, { children: name }))] }))] })));
|
|
3828
3899
|
};
|
|
3829
3900
|
|
|
3830
3901
|
exports.ActionButton = ActionButton;
|