Skip to content

Commit

Permalink
Fix inventory list double refresh on load (#4480)
Browse files Browse the repository at this point in the history
* eeej small files

* console debugging

* combine sort and filter change and ignore on initial load

* precommit

* remove debug logs

* refactor

---------

Co-authored-by: Katherine Fleming <[email protected]>
  • Loading branch information
perryr16 and kflemin authored Jan 18, 2024
1 parent acc3198 commit cc89f5a
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions seed/static/seed/js/controllers/inventory_list_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,9 @@ angular.module('BE.seed.controller.inventory_list', []).controller('inventory_li
const restoreGridSettings = () => {
$scope.restore_status = RESTORE_SETTINGS;
let state = inventory_service.loadGridSettings(`${localStorageKey}.sort`);
// If save state has filters or sorts, ignore the grids first attempt to run filterChanged or sortChanged
const columns = JSON.parse(state).columns
$scope.ignore_filter_or_sort = !_.isEmpty(columns)
if (!_.isNull(state)) {
state = JSON.parse(state);
$scope.gridApi.saveState.restore($scope, state).then(() => {
Expand All @@ -1822,6 +1825,16 @@ angular.module('BE.seed.controller.inventory_list', []).controller('inventory_li
$scope.update_selected_display();
};

const filterOrSortChanged = _.debounce(() => {
if ($scope.ignore_filter_or_sort) {
$scope.ignore_filter_or_sort = false;
} else if ($scope.restore_status === RESTORE_COMPLETE) {
updateColumnFilterSort();
$scope.load_inventory(1);
}
}, 1000)


$scope.gridOptions = {
data: 'data',
enableFiltering: true,
Expand Down Expand Up @@ -1890,24 +1903,8 @@ angular.module('BE.seed.controller.inventory_list', []).controller('inventory_li
saveSettings();
});
gridApi.core.on.columnVisibilityChanged($scope, saveSettings);
gridApi.core.on.filterChanged(
$scope,
_.debounce(() => {
if ($scope.restore_status === RESTORE_COMPLETE) {
updateColumnFilterSort();
$scope.load_inventory(1);
}
}, 1000)
);
gridApi.core.on.sortChanged(
$scope,
_.debounce(() => {
if ($scope.restore_status === RESTORE_COMPLETE) {
updateColumnFilterSort();
$scope.load_inventory(1);
}
}, 1000)
);
gridApi.core.on.filterChanged($scope, filterOrSortChanged)
gridApi.core.on.sortChanged($scope, filterOrSortChanged);
gridApi.pinning.on.columnPinned($scope, (colDef, container) => {
if (container) {
saveSettings();
Expand Down

0 comments on commit cc89f5a

Please sign in to comment.