Skip to content
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

fix(compass-sidebar): do not filter out low level items when a top level item matches the filter COMPASS-8026 #6027

Merged
merged 4 commits into from
Jul 16, 2024
Merged
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 @@ -52,7 +52,8 @@ const filterDatabases = (
results.push({
...db,
isMatch,
collections: childMatches.length ? childMatches : db.collections,
collections:
!isMatch && childMatches.length ? childMatches : db.collections,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ const sidebarConnections: SidebarConnection[] = [
sourceName: '',
pipeline: [],
},
{
_id: 'coll_ready_2_2',
name: 'coll_ready_2_2',
type: 'collection',
sourceName: '',
pipeline: [],
},
],
collectionsLength: 1,
collectionsStatus: 'ready',
Expand Down Expand Up @@ -499,6 +506,40 @@ describe('useFilteredConnections', function () {
});
});

it('should not filter the database items if the parent is also a match', async function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
connections: [
{
...mockSidebarConnections[0],
name: 'Matching connection',
databases: [
{
...(mockSidebarConnections[0] as SidebarConnectedConnection)
.databases[0],
name: 'Matching database',
},
{
...(mockSidebarConnections[0] as SidebarConnectedConnection)
.databases[1],
name: 'Another database',
},
],
} as SidebarConnectedConnection,
],
filterRegex: new RegExp('Matching', 'i'), // this matches connection as well as database
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
});

await waitFor(() => {
expect(
(result.current.filtered?.[0] as SidebarConnectedConnection).databases
).to.have.length(2); // both databases are included
});
});

it('should match the collection items', async function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
Expand All @@ -516,17 +557,40 @@ describe('useFilteredConnections', function () {
{
...matchedItem,
// will only match the second database's collection
databases: [matchedItem.databases[0]],
databases: [
{
...matchedItem.databases[0],
collections: [matchedItem.databases[0].collections[0]],
},
],
},
]);
});
});

it('should not filter the collection items if the parent is also a match', async function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
connections: mockSidebarConnections,
filterRegex: new RegExp('ready_2_1', 'i'), // this matches 1 database and 1 collection
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
});

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

it('as expanded, it should return an object containing an expanded object for the matching items', async function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
connections: mockSidebarConnections,
filterRegex: new RegExp('_1_1', 'i'),
filterRegex: new RegExp('coll_ready_1_1', 'i'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
Expand Down Expand Up @@ -568,7 +632,7 @@ describe('useFilteredConnections', function () {

rerender({
connections: mockSidebarConnections,
filterRegex: new RegExp('_1_1', 'i'),
filterRegex: new RegExp('coll_ready_1_1', 'i'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
});
Expand All @@ -591,7 +655,7 @@ describe('useFilteredConnections', function () {
{
initialProps: {
connections: mockSidebarConnections,
filterRegex: new RegExp('_1_1', 'i'),
filterRegex: new RegExp('coll_ready_1_1', 'i'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
Expand Down Expand Up @@ -630,7 +694,7 @@ describe('useFilteredConnections', function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
connections: mockSidebarConnections,
filterRegex: new RegExp('_1_1', 'i'),
filterRegex: new RegExp('coll_ready_1_1', 'i'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
Expand Down Expand Up @@ -662,7 +726,7 @@ describe('useFilteredConnections', function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
connections: mockSidebarConnections,
filterRegex: new RegExp('_1_1', 'i'),
filterRegex: new RegExp('coll_ready_1_1', 'i'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
Expand Down Expand Up @@ -700,7 +764,7 @@ describe('useFilteredConnections', function () {
const { result } = renderHookWithContext(useFilteredConnections, {
initialProps: {
connections: mockSidebarConnections,
filterRegex: new RegExp('_1_1', 'i'),
filterRegex: new RegExp('coll_ready_1_1', 'i'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ const filterConnections = (
isMatch,
...(connection.connectionStatus === ConnectionStatus.Connected
? {
databases: childMatches.length
? childMatches
: connection.databases,
databases:
!isMatch && childMatches.length
? childMatches
: connection.databases,
}
: {}),
});
Expand All @@ -83,7 +84,8 @@ const filterDatabases = (
results.push({
...db,
isMatch,
collections: childMatches.length ? childMatches : db.collections,
collections:
!isMatch && childMatches.length ? childMatches : db.collections,
});
}
}
Expand Down
Loading