Skip to content

Commit 411e5d6

Browse files
authored
chore: filter out update queries from My Queries (#5156)
* chore: filter out update queries in my pages * chore: remove .only
1 parent 7cc5ea7 commit 411e5d6

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react';
2+
import { render, screen, cleanup } from '@testing-library/react';
3+
import { expect } from 'chai';
4+
5+
import { AggregationsQueriesList } from './aggregations-queries-list';
6+
import type { AggregationsQueriesListProps } from './aggregations-queries-list';
7+
import { Provider } from 'react-redux';
8+
import { configureStore } from '../stores';
9+
10+
function renderQueriesList(props: Partial<AggregationsQueriesListProps>) {
11+
const store = configureStore({
12+
globalAppRegistry: {} as any,
13+
dataService: {} as any,
14+
instance: {} as any,
15+
logger: {} as any,
16+
pipelineStorage: {} as any,
17+
queryStorage: {} as any,
18+
});
19+
20+
return render(
21+
<Provider store={store}>
22+
<AggregationsQueriesList
23+
items={props.items ?? []}
24+
loading={props.loading ?? false}
25+
onCopyToClipboard={props.onCopyToClipboard ?? (() => {})}
26+
onDeleteItem={props.onDeleteItem ?? (() => {})}
27+
onEditItem={props.onEditItem ?? (() => {})}
28+
onOpenItem={props.onOpenItem ?? (() => {})}
29+
onMount={props.onMount ?? (() => {})}
30+
/>
31+
</Provider>
32+
);
33+
}
34+
35+
describe('AggregationsQueriesList', function () {
36+
afterEach(function () {
37+
cleanup();
38+
});
39+
40+
it('should filter out updatemany queries', function () {
41+
renderQueriesList({
42+
items: [
43+
{
44+
type: 'query',
45+
name: 'shown',
46+
database: 'showndb',
47+
collection: 'showncoll',
48+
} as any,
49+
{
50+
type: 'updatemany',
51+
name: 'not shown',
52+
database: 'notshowndb',
53+
collection: 'notshowncoll',
54+
} as any,
55+
],
56+
});
57+
58+
expect(screen.getByText('shown')).to.exist;
59+
expect(screen.getByText('.find')).to.exist;
60+
expect(screen.queryByText('not shown')).to.not.exist;
61+
expect(screen.queryByText('.updatemany')).to.not.exist;
62+
});
63+
});

packages/compass-saved-aggregations-queries/src/components/aggregations-queries-list.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const GridControls = () => {
6969
);
7070
};
7171

72-
type AggregationsQueriesListProps = {
72+
export type AggregationsQueriesListProps = {
7373
loading: boolean;
7474
items: Item[];
7575
onMount(): void;
@@ -79,7 +79,7 @@ type AggregationsQueriesListProps = {
7979
onCopyToClipboard(id: string): void;
8080
};
8181

82-
const AggregationsQueriesList = ({
82+
export const AggregationsQueriesList = ({
8383
loading,
8484
items,
8585
onMount,
@@ -99,6 +99,7 @@ const AggregationsQueriesList = ({
9999
} = useGridFilters(items);
100100

101101
const filteredItems = useFilteredItems(items, filters, search)
102+
.filter((e) => e.item.type !== 'updatemany')
102103
.sort((a, b) => {
103104
return a.score - b.score;
104105
})

packages/compass-saved-aggregations-queries/src/stores/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Storages = {
2626
queryStorage: FavoriteQueryStorage;
2727
};
2828

29-
function configureStore({
29+
export function configureStore({
3030
globalAppRegistry,
3131
dataService,
3232
instance,

0 commit comments

Comments
 (0)