Skip to content

Commit 7475afd

Browse files
committed
fix: pass query filter directly
1 parent 3c14dbd commit 7475afd

File tree

6 files changed

+14
-25
lines changed

6 files changed

+14
-25
lines changed

packages/compass-components/src/components/document-list/document.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ import { usePrevious } from './use-previous';
1616
import VisibleFieldsToggle from './visible-field-toggle';
1717
import { documentTypography } from './typography';
1818

19-
export type Query = {
20-
filter?: Record<string, unknown>;
21-
};
22-
2319
function useHadronDocument(doc: HadronDocumentType) {
2420
const prevDoc = usePrevious(doc);
2521
const forceUpdate = useForceUpdate();
@@ -91,7 +87,7 @@ const HadronDocument: React.FunctionComponent<{
9187
onEditStart?: () => void;
9288
extraGutterWidth?: number;
9389
onAddToQuery?: (field: string, value: unknown) => void;
94-
query?: Query;
90+
query?: Record<string, unknown>;
9591
}> = ({
9692
value: document,
9793
editable = false,

packages/compass-components/src/components/document-list/element.spec.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('HadronElement', function () {
4242
lineNumberSize={1}
4343
onAddElement={() => {}}
4444
onAddToQuery={mockOnAddToQuery}
45-
query={{ filter: {} }}
45+
query={{}}
4646
/>
4747
);
4848

@@ -64,9 +64,7 @@ describe('HadronElement', function () {
6464

6565
// Now simulate that the field is in query
6666
const queryWithField = {
67-
filter: {
68-
'user.name': nestedElement.generateObject(),
69-
},
67+
'user.name': nestedElement.generateObject(),
7068
};
7169

7270
// Re-render with updated query state
@@ -220,7 +218,7 @@ describe('HadronElement', function () {
220218
lineNumberSize={1}
221219
onAddElement={() => {}}
222220
onAddToQuery={mockOnAddToQuery}
223-
query={{ filter: {} }}
221+
query={{}}
224222
/>
225223
);
226224

packages/compass-components/src/components/document-list/element.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { useDarkMode } from '../../hooks/use-theme';
3131
import VisibleFieldsToggle from './visible-field-toggle';
3232
import { useContextMenuItems } from '../context-menu';
3333
import { hasDistinctValue } from 'mongodb-query-util';
34-
import type { Query } from './document';
3534

3635
function getEditorByType(type: HadronElementType['type']) {
3736
switch (type) {
@@ -466,7 +465,7 @@ export const HadronElement: React.FunctionComponent<{
466465
onAddElement(el: HadronElementType): void;
467466
extraGutterWidth?: number;
468467
onAddToQuery?: (field: string, value: unknown) => void;
469-
query?: Query;
468+
query?: Record<string, unknown>;
470469
}> = ({
471470
value: element,
472471
editable,
@@ -500,18 +499,16 @@ export const HadronElement: React.FunctionComponent<{
500499
collapse,
501500
} = useHadronElement(element);
502501

503-
const queryFilter = query?.filter;
504-
505502
// Function to check if a field is in the query
506503
// TODO: COMPASS-9541 Improve the functionality when checking for nested objects.
507504
const isFieldInQuery = useCallback(
508505
(field: string, fieldValue: unknown): boolean => {
509506
return hasDistinctValue(
510-
queryFilter?.[field] as Record<string, unknown>,
507+
query?.[field] as Record<string, unknown>,
511508
fieldValue
512509
);
513510
},
514-
[queryFilter]
511+
[query]
515512
);
516513

517514
// Add context menu hook for the field

packages/compass-crud/src/components/document.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const Document = (props: DocumentProps) => {
3737
}, [_doc]);
3838

3939
const changeQuery = useChangeQueryBarQuery();
40-
const query = useQueryBarQuery();
40+
const queryBarQuery = useQueryBarQuery();
4141

4242
const handleAddToQuery = useCallback(
4343
(field: string, value: unknown) => {
@@ -58,7 +58,7 @@ const Document = (props: DocumentProps) => {
5858
void openInsertDocumentDialog?.(doc, cloned);
5959
}}
6060
onAddToQuery={handleAddToQuery}
61-
query={query}
61+
query={queryBarQuery.filter}
6262
/>
6363
);
6464
}
@@ -69,7 +69,7 @@ const Document = (props: DocumentProps) => {
6969
{...props}
7070
doc={doc}
7171
onAddToQuery={handleAddToQuery}
72-
query={query}
72+
query={queryBarQuery.filter}
7373
/>
7474
);
7575
}
@@ -79,7 +79,7 @@ const Document = (props: DocumentProps) => {
7979
doc={doc}
8080
copyToClipboard={copyToClipboard}
8181
onAddToQuery={handleAddToQuery}
82-
query={query}
82+
query={queryBarQuery.filter}
8383
/>
8484
);
8585
};

packages/compass-crud/src/components/editable-document.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { Document } from 'hadron-document';
44
import HadronDocument from 'hadron-document';
55
import { DocumentList, css } from '@mongodb-js/compass-components';
66
import { withPreferences } from 'compass-preferences-model/provider';
7-
import type { Query } from '@mongodb-js/compass-query-bar';
87

98
import { documentStyles, documentContentStyles } from './readonly-document';
109
import { getInsightsForDocument } from '../utils';
@@ -23,7 +22,7 @@ export type EditableDocumentProps = {
2322
copyToClipboard?: CrudActions['copyToClipboard'];
2423
showInsights?: boolean;
2524
onAddToQuery?: (field: string, value: unknown) => void;
26-
query?: Query;
25+
query?: Record<string, unknown>;
2726
};
2827

2928
type EditableDocumentState = {
@@ -270,7 +269,7 @@ class EditableDocument extends React.Component<
270269
doc={this.props.doc}
271270
editing={this.state.editing}
272271
deleting={this.state.deleting}
273-
onUpdate={(force: boolean) => {
272+
onUpdate={(force) => {
274273
if (force) {
275274
void this.props.replaceDocument?.(this.props.doc);
276275
} else {

packages/compass-crud/src/components/readonly-document.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { TypeCastMap } from 'hadron-type-checker';
66
import { withPreferences } from 'compass-preferences-model/provider';
77
import { getInsightsForDocument } from '../utils';
88
import { DocumentEvents } from 'hadron-document';
9-
import type { Query } from '@mongodb-js/compass-query-bar';
109
type BSONObject = TypeCastMap['Object'];
1110

1211
export const documentStyles = css({
@@ -31,7 +30,7 @@ export type ReadonlyDocumentProps = {
3130
doc: Document;
3231
showInsights?: boolean;
3332
onAddToQuery?: (field: string, value: unknown) => void;
34-
query?: Query;
33+
query?: Record<string, unknown>;
3534
};
3635

3736
type ReadonlyDocumentState = {

0 commit comments

Comments
 (0)