Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Copy link
Contributor

@kraenhansen kraenhansen May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, the . has special meaning in the regular expression and I believe it should be escaped here to capture the intent of the change, to mean a literal "." (dot).

Suggested change
regex: new RegExp('ready_1_1.coll_ready_shared_name', 'i'), // this matches only coll_ready_shared_name collection in ready_1_1 database
regex: new RegExp('ready_1_1\.coll_ready_shared_name', 'i'), // this matches only coll_ready_shared_name collection in ready_1_1 database

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

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
Loading