Skip to content

Commit

Permalink
Merge pull request #1790 from mzedel/3.0.x-picks2
Browse files Browse the repository at this point in the history
3.0.x picks2
  • Loading branch information
mzedel committed Jul 12, 2021
2 parents 78de789 + 7d624bb commit 3e226fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/js/actions/deviceActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ export const removeDynamicGroup = groupName => (dispatch, getState) => {
*/
export const selectGroup = (group, filters = []) => (dispatch, getState) => {
const groupName = group === DeviceConstants.UNGROUPED_GROUP.id || group === DeviceConstants.UNGROUPED_GROUP.name ? DeviceConstants.UNGROUPED_GROUP.id : group;
if (getState().devices.groups.selectedGroup === groupName && filters.length === 0) {
const state = getState();
const selectedGroup = state.devices.groups.byId[groupName];
const groupFilterLength = selectedGroup?.filters?.length || 0;
if (state.devices.groups.selectedGroup === groupName && filters.length === 0 && !groupFilterLength) {
return;
}
let tasks = [];
const state = getState();
const selectedGroup = state.devices.groups.byId[groupName];
if (selectedGroup?.filters?.length) {
if (groupFilterLength) {
const cleanedFilters = (filters.length ? filters : selectedGroup.filters).filter(
(item, index, array) => array.findIndex(filter => deepCompare(filter, item)) == index
);
Expand Down
12 changes: 9 additions & 3 deletions src/js/components/devices/device-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,16 @@ export const DeviceGroups = ({
const [openPreauth, setOpenPreauth] = useState(false);
const [removeGroup, setRemoveGroup] = useState(false);
const [tmpDevices, setTmpDevices] = useState([]);
const [isReconciling, setIsReconciling] = useState(false);

const { state: selectedState } = deviceListState;

useEffect(() => {
const { filters: filterQuery = '', status = '' } = match.params;
maybeSetGroupAndFilters(filterQuery, history.location.search, filteringAttributes, filters);
if (status && selectedState !== status) {
setDeviceListState({ state: status });
setIsReconciling(true);
setDeviceListState({ state: status }).then(() => setIsReconciling(false));
}
const { pathname, search } = generateBrowserLocation(status, filters, selectedGroup, history.location, true);
if (pathname !== history.location.pathname || history.location.search !== `?${search}`) {
Expand Down Expand Up @@ -282,9 +284,13 @@ export const DeviceGroups = ({
if (!deviceTimer) {
return;
}
const { filters: filterQuery = '' } = match.params;
const { filters: filterQuery = '', status = '' } = match.params;
maybeSetGroupAndFilters(filterQuery, history.location.search, filteringAttributes, filters);
}, [filters, match.params.filters, history.location.search]);
if (selectedState !== status && !isReconciling) {
setIsReconciling(true);
setDeviceListState({ state: status ? status : routes.devices.key }).then(() => setIsReconciling(false));
}
}, [filters, match.params, history.location.search]);

const maybeSetGroupAndFilters = (filterQuery, search, attributes, currentFilters) => {
const query = filterQuery || search;
Expand Down

0 comments on commit 3e226fe

Please sign in to comment.