Skip to content

feat(sidebar): filter both databases and collections with dot notation #6912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ const sidebarConnections: SidebarConnection[] = [
pipeline: [],
isNonExistent: false,
},
{
_id: 'coll_ready_1_1_2',
name: 'coll_ready_shared_name',
type: 'collection',
sourceName: '',
pipeline: [],
isNonExistent: false,
},
],
collectionsLength: 1,
collectionsStatus: 'ready',
Expand All @@ -70,6 +78,14 @@ const sidebarConnections: SidebarConnection[] = [
pipeline: [],
isNonExistent: false,
},
{
_id: 'coll_ready_1_2_2',
name: 'coll_ready_shared_name',
type: 'collection',
sourceName: '',
pipeline: [],
isNonExistent: false,
},
],
collectionsLength: 1,
collectionsStatus: 'ready',
Expand Down Expand Up @@ -626,6 +642,27 @@ describe('useFilteredConnections', function () {
});
});

it('should filter collection items and database items using dot notation', async function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
connections: mockSidebarConnections,
filter: {
regex: new RegExp('ready_1_1\\.coll_ready_shared_name', 'i'), // this matches only coll_ready_shared_name collection in ready_1_1 database
excludeInactive: false,
},
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
});

await waitFor(() => {
expect(
(result.current.filtered?.[0] as SidebarConnectedConnection)
.databases[0].collections
).to.have.length(1); // the result has 1 collection
});
});

it('as expanded, it should return an object containing an expanded object for the matching items', async function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const filterDatabases = (
const results: FilteredDatabase[] = [];
for (const db of databases) {
const isMatch = !regex || regex.test(db.name);
const childMatches = filterCollections(db.collections, regex);
const childMatches = filterCollections(db.collections, regex, db.name);

if (isMatch || childMatches.length) {
// If the db doesn't match, we want to use just the matching collections.
Expand All @@ -111,10 +111,14 @@ const filterDatabases = (

const filterCollections = (
collections: SidebarCollection[],
regex: RegExp | null
regex: RegExp | null,
dbName: string
): FilteredCollection[] => {
return collections
.filter(({ name }) => !regex || regex.test(name))
.filter(
({ name }) =>
!regex || regex.test(name) || regex.test(`${dbName}.${name}`)
)
.map((collection) => ({ ...collection, isMatch: true }));
};

Expand Down