@visns-studio/visns-components 6.6.0 → 6.6.2
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/package.json +1 -1
- package/src/components/DataGrid.jsx +27 -0
package/package.json
CHANGED
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
92
92
|
},
|
|
93
93
|
"name": "@visns-studio/visns-components",
|
|
94
|
-
"version": "6.6.
|
|
94
|
+
"version": "6.6.2",
|
|
95
95
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
96
96
|
"main": "src/index.js",
|
|
97
97
|
"files": [
|
|
@@ -871,6 +871,25 @@ const DataGrid = forwardRef(
|
|
|
871
871
|
return initialLimit;
|
|
872
872
|
});
|
|
873
873
|
const [search, setSearch] = useState('');
|
|
874
|
+
|
|
875
|
+
// This component instance survives client-side route changes — React Router
|
|
876
|
+
// reconciles the new page's grid into the same DataGrid element, and only the
|
|
877
|
+
// inner ReactDataGrid remounts (its key includes the ajax url). Without this
|
|
878
|
+
// reset the previous page's filters and search ride into the new page's very
|
|
879
|
+
// first request, including whereHas relations the new page's model may not
|
|
880
|
+
// have at all, which the backend answers with a 500. It has to happen during
|
|
881
|
+
// render rather than in an effect: an effect would fire only after the
|
|
882
|
+
// remounted inner grid has already mounted and issued that first fetch, so
|
|
883
|
+
// adjusting the state here is what keeps the stale values from ever reaching
|
|
884
|
+
// it. The equality guards keep this from looping.
|
|
885
|
+
const prevAjaxUrlRef = useRef(ajaxSetting?.url);
|
|
886
|
+
if (prevAjaxUrlRef.current !== ajaxSetting?.url) {
|
|
887
|
+
prevAjaxUrlRef.current = ajaxSetting?.url;
|
|
888
|
+
if (filterValue.length > 0) setFilterValue([]);
|
|
889
|
+
if (search !== '') setSearch('');
|
|
890
|
+
if (dSearch !== '') setDSearch('');
|
|
891
|
+
}
|
|
892
|
+
|
|
874
893
|
const [selected, setSelected] = useState({});
|
|
875
894
|
const [inputDebounceTimers] = useState({});
|
|
876
895
|
const [localInputValues, setLocalInputValues] = useState({});
|
|
@@ -3566,6 +3585,7 @@ const DataGrid = forwardRef(
|
|
|
3566
3585
|
};
|
|
3567
3586
|
|
|
3568
3587
|
useEffect(() => {
|
|
3588
|
+
const requestUrl = ajaxSetting?.url;
|
|
3569
3589
|
const dropdownFetches = columns
|
|
3570
3590
|
.filter((column) =>
|
|
3571
3591
|
['dropdown', 'multiDropdown'].includes(column.type)
|
|
@@ -3582,6 +3602,12 @@ const DataGrid = forwardRef(
|
|
|
3582
3602
|
|
|
3583
3603
|
Promise.all(dropdownFetches)
|
|
3584
3604
|
.then((results) => {
|
|
3605
|
+
// The page changed while these dropdown fetches were in
|
|
3606
|
+
// flight — these columns/filters belong to the previous page.
|
|
3607
|
+
if (requestUrl !== prevAjaxUrlRef.current) {
|
|
3608
|
+
return;
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3585
3611
|
// Merge all resolved objects into a single object
|
|
3586
3612
|
const dropdownData = results.reduce((acc, result) => {
|
|
3587
3613
|
return { ...acc, ...result };
|
|
@@ -4622,6 +4648,7 @@ const DataGrid = forwardRef(
|
|
|
4622
4648
|
newColumns.push({
|
|
4623
4649
|
name: 'setting',
|
|
4624
4650
|
header: 'Action',
|
|
4651
|
+
sortable: false,
|
|
4625
4652
|
defaultWidth: actionColumnWidth,
|
|
4626
4653
|
minWidth: actionColumnWidth,
|
|
4627
4654
|
textAlign: 'center',
|