Skip to content

Commit 188afe7

Browse files
committed
fix up
1 parent 2fb87f6 commit 188afe7

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

packages/compass-query-bar/src/components/option-editor.spec.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import sinon from 'sinon';
1414
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
1515
import type { PreferencesAccess } from 'compass-preferences-model';
1616
import { PreferencesProvider } from 'compass-preferences-model/provider';
17+
import type { RecentQuery } from '@mongodb-js/my-queries-storage';
1718

1819
class MockPasteEvent extends window.Event {
1920
constructor(private text: string) {
@@ -309,21 +310,21 @@ describe('OptionEditor', function () {
309310
skip: 1,
310311
limit: 1,
311312
},
312-
];
313+
] as unknown as RecentQuery[];
313314

314315
it('filters out update queries', function () {
315316
const queries = getOptionBasedQueries('filter', 'recent', [
316317
...savedQueries,
317318
{ _lastExecuted: new Date(), update: { a: 1 }, filter: { a: 2 } },
318-
]);
319+
] as unknown as RecentQuery[]);
319320
expect(queries.length).to.equal(1);
320321
});
321322

322323
it('filters out empty queries', function () {
323324
const queries = getOptionBasedQueries('filter', 'recent', [
324325
...savedQueries,
325326
{ _lastExecuted: new Date() },
326-
]);
327+
] as unknown as RecentQuery[]);
327328
expect(queries.length).to.equal(1);
328329
});
329330

@@ -334,7 +335,7 @@ describe('OptionEditor', function () {
334335
...savedQueries,
335336
{ _lastExecuted: new Date() },
336337
{ _lastExecuted: new Date() },
337-
]);
338+
] as unknown as RecentQuery[]);
338339
expect(queries.length).to.equal(1);
339340
});
340341

packages/compass-query-bar/src/components/option-editor.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type {
4040
RecentQuery,
4141
} from '@mongodb-js/my-queries-storage';
4242
import _ from 'lodash';
43+
import type { QueryOptionOfTypeDocument } from '../constants/query-option-definition';
4344

4445
const editorContainerStyles = css({
4546
position: 'relative',
@@ -97,9 +98,8 @@ const insightsBadgeStyles = css({
9798
flex: 'none',
9899
});
99100

100-
type OptionEditorName = Exclude<QueryProperty, 'maxTimeMS' | 'limit' | 'skip'>;
101101
type OptionEditorProps = {
102-
optionName: OptionEditorName;
102+
optionName: QueryOptionOfTypeDocument;
103103
namespace: string;
104104
id?: string;
105105
hasError?: boolean;
@@ -299,7 +299,7 @@ export const OptionEditor: React.FunctionComponent<OptionEditorProps> = ({
299299
};
300300

301301
export function getOptionBasedQueries(
302-
optionName: OptionEditorName,
302+
optionName: QueryOptionOfTypeDocument,
303303
type: 'recent' | 'favorite',
304304
queries: (RecentQuery | FavoriteQuery)[]
305305
) {
@@ -339,7 +339,10 @@ export function getOptionBasedQueries(
339339
);
340340
}
341341

342-
const mapStateToProps = (state: RootState, ownProps: OptionEditorProps) => ({
342+
const mapStateToProps = (
343+
state: RootState,
344+
ownProps: Pick<OptionEditorProps, 'optionName'>
345+
) => ({
343346
namespace: state.queryBar.namespace,
344347
serverVersion: state.queryBar.serverVersion,
345348
savedQueries: [

packages/compass-query-bar/src/components/query-option.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
import { connect } from '../stores/context';
1313
import OptionEditor from './option-editor';
1414
import { OPTION_DEFINITION } from '../constants/query-option-definition';
15-
import type { QueryOption as QueryOptionType } from '../constants/query-option-definition';
15+
import type {
16+
QueryOptionOfTypeDocument,
17+
QueryOption as QueryOptionType,
18+
} from '../constants/query-option-definition';
1619
import { changeField } from '../stores/query-bar-reducer';
1720
import type { QueryProperty } from '../constants/query-properties';
1821
import type { RootState } from '../stores/query-bar-store';
@@ -187,7 +190,7 @@ const QueryOption: React.FunctionComponent<QueryOptionProps> = ({
187190
<div className={cx(isDocumentEditor && documentEditorOptionStyles)}>
188191
{isDocumentEditor ? (
189192
<OptionEditor
190-
optionName={name}
193+
optionName={name as QueryOptionOfTypeDocument}
191194
hasError={hasError}
192195
id={id}
193196
onChange={onValueChange}

packages/compass-query-bar/src/constants/query-option-definition.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { usePreference } from 'compass-preferences-model/provider';
44
import type { QueryProperty } from './query-properties';
55

66
export type QueryOption = Exclude<QueryProperty, 'update'>;
7+
export type QueryOptionOfTypeDocument = Exclude<
8+
QueryProperty,
9+
'maxTimeMS' | 'limit' | 'skip'
10+
>;
711

812
export const OPTION_DEFINITION: {
913
[optionName in QueryOption]: {

packages/compass-query-bar/src/stores/query-bar-reducer.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,15 @@ export const applyFromHistory = (
229229
): QueryBarThunkAction<void, ApplyFromHistoryAction> => {
230230
return (dispatch, getState, { localAppRegistry, preferences }) => {
231231
const currentFields = getState().queryBar.fields;
232-
const currentQuery = currentQueryFieldsToRetain.reduce((acc, key) => {
233-
if (currentFields[key]?.value) {
234-
acc[key] = currentFields[key].value;
232+
const currentQuery = currentQueryFieldsToRetain.reduce<
233+
Record<string, Document | number>
234+
>((acc, key) => {
235+
const { value } = currentFields[key];
236+
if (value) {
237+
acc[key] = value;
235238
}
236239
return acc;
237-
}, {} as Record<string, number | Document>);
240+
}, {});
238241
const fields = mapQueryToFormFields(
239242
{ maxTimeMS: preferences.getPreferences().maxTimeMS },
240243
{

0 commit comments

Comments
 (0)