Merge pull request #21099 from strapi/v5/fix-issue-21079

fix: issue 21079 on v5
This commit is contained in:
Alexandre BODIN 2024-08-29 09:34:52 +02:00 committed by GitHub
commit 2842f97374
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View File

@ -46,7 +46,7 @@ export declare namespace FindAll {
// TODO make the types for this
export interface Request {
body: {};
query: Modules.EntityService.Params.Pick<'admin::user', 'filters'> & {
query: Modules.EntityService.Params.Pick<'admin::user', 'filters' | '_q'> & {
[key: string]: any;
};
}

View File

@ -13,6 +13,7 @@ import { useIntl } from 'react-intl';
import { CREATOR_FIELDS } from '../../../constants/attributes';
import { useContentTypeSchema } from '../../../hooks/useContentTypeSchema';
import { useDebounce } from '../../../hooks/useDebounce';
import { Schema } from '../../../hooks/useDocument';
import { useGetContentTypeConfigurationQuery } from '../../../services/contentTypes';
import { getMainField } from '../../../utils/attributes';
@ -224,20 +225,26 @@ const FiltersImpl = ({ disabled, schema }: FiltersProps) => {
* -----------------------------------------------------------------------------------------------*/
const AdminUsersFilter = ({ name }: Filters.ValueInputProps) => {
const [page, setPage] = React.useState(1);
const [pageSize, setPageSize] = React.useState(10);
const [search, setSearch] = React.useState('');
const { formatMessage } = useIntl();
const debouncedSearch = useDebounce(search, 300);
const { data, isLoading } = useAdminUsers({
page,
pageSize,
_q: debouncedSearch,
});
const field = useField(name);
const handleOpenChange = (isOpen?: boolean) => {
if (!isOpen) {
setPage(1);
setPageSize(10);
}
};
const users = data?.users || [];
const { users = [], pagination } = data ?? {};
const { pageCount = 1, page = 1 } = pagination ?? {};
return (
<Combobox
@ -249,7 +256,11 @@ const AdminUsersFilter = ({ name }: Filters.ValueInputProps) => {
onOpenChange={handleOpenChange}
onChange={(value) => field.onChange(name, value)}
loading={isLoading}
onLoadMore={() => setPage((prev) => prev + 1)}
onLoadMore={() => setPageSize(pageSize + 10)}
hasMoreItems={page < pageCount}
onInputChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setSearch(e.currentTarget.value);
}}
>
{users.map((user) => {
return (