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
8 changes: 8 additions & 0 deletions packages/compass-saved-aggregations-queries/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ module.exports = {
tsconfigRootDir: __dirname,
project: ['./tsconfig-lint.json'],
},
overrides: [
{
files: ['**/*.ts'],
rules: {
'@typescript-eslint/switch-exhaustiveness-check': 'error',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could also enable this everywhere, but I imagine that could cause unintended failures we have to fix and I'd rather do that separately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you file a ticket to do this if we're not trying to do this right away?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

},
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('use-grid-header', function () {
result.current.search
)
).result.current.map((x) => x.item);
expect(gridItems).to.have.length(4);
expect(gridItems).to.have.length(5);
});

it('should filter items by search text - collection name', function () {
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('use-grid-header', function () {
result.current.search
)
).result.current.map((x) => x.item);
expect(gridItems).to.have.length(4);
expect(gridItems).to.have.length(5);
});

it('should not filter items by search text - sort key (num_of_host_spaces)', function () {
Expand Down
16 changes: 12 additions & 4 deletions packages/compass-saved-aggregations-queries/src/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getConnection() {
};
}

describe('AggregationsQueriesList', function () {
describe('AggregationsAndQueriesAndUpdatemanyList', function () {
const sandbox = Sinon.createSandbox();
const query = {
_id: '123',
Expand All @@ -51,6 +51,14 @@ describe('AggregationsQueriesList', function () {
filter: { foo: 'bar' },
sort: { bar: -1 },
} as any;
const updatemany = {
_id: '5667',
_name: 'Updatemany',
_ns: 'bar.baz',
_dateSaved: new Date(),
filter: { foo: 'baz' },
sort: { baz: -1 },
} as any;
const aggregation = {
id: '123',
name: 'Aggregation',
Expand Down Expand Up @@ -153,7 +161,7 @@ describe('AggregationsQueriesList', function () {
});

it('should load queries and display them in the list', async function () {
sandbox.stub(queryStorage, 'loadAll').resolves([query]);
sandbox.stub(queryStorage, 'loadAll').resolves([query, updatemany]);
renderPlugin();
expect(await screen.findByText('Query')).to.exist;
await waitFor(() => expect(screen.findByText(query._name)).to.exist);
Expand All @@ -168,7 +176,7 @@ describe('AggregationsQueriesList', function () {

describe('copy to clipboard', function () {
it('should copy query to the clipboard', async function () {
sandbox.stub(queryStorage, 'loadAll').resolves([query]);
sandbox.stub(queryStorage, 'loadAll').resolves([query, updatemany]);
renderPlugin();
expect(await screen.findByText(query._name)).to.exist;

Expand Down Expand Up @@ -386,7 +394,7 @@ describe('AggregationsQueriesList', function () {
};

beforeEach(function () {
sandbox.stub(queryStorage, 'loadAll').resolves([query]);
sandbox.stub(queryStorage, 'loadAll').resolves([query, updatemany]);
});

context('when not connected to any connection', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ export const confirmDeleteItem = (
undefined // this event is connection scoped when triggered from the aggregation or query screen
);

if (item.type === 'aggregation') {
await pipelineStorage?.delete(item.id);
} else {
// query or updatemany
await queryStorage?.delete(item.id);
switch (item.type) {
case 'aggregation':
await pipelineStorage?.delete(item.id);
break;
case 'query':
case 'updatemany':
await queryStorage?.delete(item.id);
break;
}

dispatch({ type: ActionTypes.DeleteItemConfirm, id: item.id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ export const updateItem =
return;
}

if (item.type === 'aggregation') {
await pipelineStorage?.updateAttributes(id, attributes);
} else {
// query or updatemany
await queryStorage?.updateAttributes(id, {
_name: attributes.name,
_dateModified: new Date(),
});
switch (item.type) {
case 'aggregation':
await pipelineStorage?.updateAttributes(id, attributes);
break;
case 'query':
case 'updatemany':
await queryStorage?.updateAttributes(id, {
_name: attributes.name,
_dateModified: new Date(),
});
break;
}

dispatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,16 @@ export const openSelectedItem =
const id = selectedItem.id;
const newNamespace = `${selectedDatabase}.${selectedCollection}`;

if (selectedItem.type === 'aggregation') {
await pipelineStorage?.updateAttributes(id, {
namespace: newNamespace,
});
} else {
// query or updatemany
await queryStorage?.updateAttributes(id, { _ns: newNamespace });
switch (selectedItem.type) {
case 'aggregation':
await pipelineStorage?.updateAttributes(id, {
namespace: newNamespace,
});
break;
case 'query':
case 'updatemany':
await queryStorage?.updateAttributes(id, { _ns: newNamespace });
break;
}
}

Expand Down
31 changes: 31 additions & 0 deletions packages/compass-saved-aggregations-queries/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,37 @@ export const queries = [
},
},
},
{
id: '9999',
name: 'update some things',
database: 'airbnb',
collection: 'hosts',
lastModified: 13,
type: 'updatemany' as const,
query: {
_id: '9012',
_name: 'update some things',
_ns: 'airbnb.hosts',
_dateSaved: DATE,
_dateModified: DATE,
_lastExecuted: DATE,
filter: {
host_location: RegExp('berlin'),
},
project: {
id: 1,
name: 1,
},
sort: {
reviews: -1,
},
skip: 0,
limit: 10,
collation: {
locale: 'simple',
},
},
},
];

export const pipelines = [
Expand Down
Loading