Skip to content

Commit

Permalink
[mongodb] Fix Collection Filter and Pagination
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ricoberger committed Feb 6, 2024
1 parent adb9641 commit 2d271de
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/packages/mongodb/src/components/Collections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Check warning on line 257 in app/packages/mongodb/src/components/Collections.tsx

View check run for this annotation

Codecov / codecov/patch

app/packages/mongodb/src/components/Collections.tsx#L257

Added line #L257 was not covered by tests
};

console.log(options);

return (
<>
<Box sx={{ mb: 6 }} component="form" onSubmit={handleSubmit}>
Expand Down Expand Up @@ -285,12 +287,15 @@ const CollectionList: FunctionComponent<{ collections: string[]; instance: IPlug
</Box>

<List disablePadding={true}>
{collections.map((collection, index) => (
<Fragment key={collection}>
<CollectionListItem instance={instance} collection={collection} />
{index + 1 !== collections.length && <Divider component="li" />}
</Fragment>
))}
{collections
.filter((collection) => collection.includes(options.filter))
.slice((options.page - 1) * options.perPage, options.page * options.perPage)
.map((collection, index) => (
<Fragment key={collection}>
<CollectionListItem instance={instance} collection={collection} />
{index + 1 !== collections.length && <Divider component="li" />}
</Fragment>
))}
</List>

<Pagination
Expand All @@ -313,12 +318,13 @@ export const Collections: FunctionComponent<{ description?: string; instance: IP
const { isError, isLoading, error, data, refetch } = useQuery<string[], APIError>(
['mongodb/collections', instance],
async () => {
return apiContext.client.get<string[]>(`/api/plugins/mongodb/collections`, {
const collections = await apiContext.client.get<string[]>(`/api/plugins/mongodb/collections`, {
headers: {
'x-kobs-cluster': instance.cluster,
'x-kobs-plugin': instance.name,
},
});
return collections.sort();
},
);

Expand Down

0 comments on commit 2d271de

Please sign in to comment.