Skip to content

Commit

Permalink
Debounced searching for users and groups in controlpanel (#6153)
Browse files Browse the repository at this point in the history
Co-authored-by: Katja Süss <[email protected]>
Co-authored-by: ichim-david <[email protected]>
  • Loading branch information
3 people committed Jul 23, 2024
1 parent b958cb2 commit a937f98
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/6153.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Debounced searching for users and groups in the `User Group Membership` Control Panel. @pnicolli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { cloneDeep, uniqBy } from 'lodash';
import React, { useEffect, useState, useMemo } from 'react';
import { cloneDeep, uniqBy, debounce } from 'lodash';
import { useIntl } from 'react-intl';
import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import jwtDecode from 'jwt-decode';
Expand Down Expand Up @@ -114,25 +114,41 @@ const ListingTemplate = ({
matrix_options = [];
}

const debouncedListUsers = useMemo(
() =>
debounce((query_user, groups_filter, userLimit) => {
dispatch(
listUsers({
search: query_user,
groups_filter: groups_filter.map((el) => el.value),
limit: userLimit,
}),
);
}, 300),
[dispatch],
);

useEffect(() => {
// Get users.
if (show_users) {
dispatch(
listUsers({
search: query_user,
groups_filter: groups_filter.map((el) => el.value),
limit: userLimit,
}),
);
debouncedListUsers(query_user, groups_filter, userLimit);
}
}, [dispatch, query_user, groups_filter, show_users, userLimit]);
}, [debouncedListUsers, query_user, groups_filter, show_users, userLimit]);

const debouncedListGroups = useMemo(
() =>
debounce((query_group) => {
dispatch(listGroups(query_group));
}, 300),
[dispatch],
);

useEffect(() => {
// Get matrix groups.
if (show_matrix_options) {
dispatch(listGroups(query_group));
debouncedListGroups(query_group);
}
}, [dispatch, query_group, show_matrix_options, groups_filter]);
}, [debouncedListGroups, query_group, show_matrix_options]);

const onSelectOptionHandler = (selectedvalue, checked, singleClick) => {
singleClick = singleClick ?? false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useMemo } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useIntl } from 'react-intl';
import { Checkbox, Form, Input } from 'semantic-ui-react';

import { isEqual } from 'lodash';
import { isEqual, debounce } from 'lodash';

import { messages } from '@plone/volto/helpers';
import { listGroups } from '@plone/volto/actions'; // getRegistry
Expand Down Expand Up @@ -38,12 +38,20 @@ const UserGroupMembershipMatrix = ({ many_users, many_groups }) => {
});
}

const debouncedListGroups = useMemo(
() =>
debounce((query_group_filter) => {
dispatch(listGroups('', query_group_filter));
}, 300),
[dispatch],
);

useEffect(() => {
// TODO fetch group for at least query_group_filter.length > 1?
if (!many_groups || (many_groups && query_group_filter.length > 1)) {
dispatch(listGroups('', query_group_filter));
debouncedListGroups(query_group_filter);
}
}, [dispatch, many_groups, query_group_filter]);
}, [debouncedListGroups, many_groups, query_group_filter]);

const onReset = (event) => {
// event.preventDefault();
Expand Down

0 comments on commit a937f98

Please sign in to comment.