From 2d271dec1f8f0d1d48c65f58b463632a2b9ac972 Mon Sep 17 00:00:00 2001 From: ricoberger Date: Tue, 6 Feb 2024 14:09:37 +0100 Subject: [PATCH] [mongodb] Fix Collection Filter and Pagination The pagination and filter on the collections page was not working, because we forgot to add the `filter` and `slice` (for pagination) to the array of collections. This should now be fixed, so that a user can view all collections and filter them. --- .../mongodb/src/components/Collections.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/packages/mongodb/src/components/Collections.tsx b/app/packages/mongodb/src/components/Collections.tsx index 482de054..1cf40305 100644 --- a/app/packages/mongodb/src/components/Collections.tsx +++ b/app/packages/mongodb/src/components/Collections.tsx @@ -254,9 +254,11 @@ const CollectionList: FunctionComponent<{ collections: string[]; instance: IPlug const handleClear = () => { setFilter(''); - setOptions({ filter: filter, page: 1, perPage: options.perPage }); + setOptions({ filter: '', page: 1, perPage: options.perPage }); }; + console.log(options); + return ( <> @@ -285,12 +287,15 @@ const CollectionList: FunctionComponent<{ collections: string[]; instance: IPlug - {collections.map((collection, index) => ( - - - {index + 1 !== collections.length && } - - ))} + {collections + .filter((collection) => collection.includes(options.filter)) + .slice((options.page - 1) * options.perPage, options.page * options.perPage) + .map((collection, index) => ( + + + {index + 1 !== collections.length && } + + ))} ( ['mongodb/collections', instance], async () => { - return apiContext.client.get(`/api/plugins/mongodb/collections`, { + const collections = await apiContext.client.get(`/api/plugins/mongodb/collections`, { headers: { 'x-kobs-cluster': instance.cluster, 'x-kobs-plugin': instance.name, }, }); + return collections.sort(); }, );