1- import React , { useMemo , useCallback } from 'react' ;
1+ import React , { useMemo } from 'react' ;
22import PropTypes from 'prop-types' ;
33import HadronDocument from 'hadron-document' ;
44import type { EditableDocumentProps } from './editable-document' ;
55import EditableDocument from './editable-document' ;
66import type { ReadonlyDocumentProps } from './readonly-document' ;
77import ReadonlyDocument from './readonly-document' ;
88import type { BSONObject } from '../stores/crud-store' ;
9- import {
10- useChangeQueryBarQuery ,
11- useQueryBarQuery ,
12- } from '@mongodb-js/compass-query-bar' ;
139
1410export type DocumentProps = {
1511 doc : HadronDocument | BSONObject ;
1612 editable : boolean ;
1713 isTimeSeries ?: boolean ;
14+ onUpdateQuery ?: ( field : string , value : unknown ) => void ;
15+ query ?: BSONObject ;
1816} & Omit < EditableDocumentProps , 'doc' | 'expandAll' > &
1917 Pick < ReadonlyDocumentProps , 'copyToClipboard' | 'openInsertDocumentDialog' > ;
2018
@@ -25,6 +23,8 @@ const Document = (props: DocumentProps) => {
2523 copyToClipboard,
2624 openInsertDocumentDialog,
2725 doc : _doc ,
26+ onUpdateQuery,
27+ query,
2828 } = props ;
2929
3030 const doc = useMemo ( ( ) => {
@@ -36,19 +36,6 @@ const Document = (props: DocumentProps) => {
3636 return new HadronDocument ( _doc as Record < string , unknown > ) ;
3737 } , [ _doc ] ) ;
3838
39- const changeQuery = useChangeQueryBarQuery ( ) ;
40- const queryBarQuery = useQueryBarQuery ( ) ;
41-
42- const handleAddToQuery = useCallback (
43- ( field : string , value : unknown ) => {
44- changeQuery ( 'toggleDistinctValue' , {
45- field,
46- value,
47- } ) ;
48- } ,
49- [ changeQuery ]
50- ) ;
51-
5239 if ( editable && isTimeSeries ) {
5340 return (
5441 < ReadonlyDocument
@@ -57,8 +44,8 @@ const Document = (props: DocumentProps) => {
5744 openInsertDocumentDialog = { ( doc , cloned ) => {
5845 void openInsertDocumentDialog ?.( doc , cloned ) ;
5946 } }
60- onUpdateQuery = { handleAddToQuery }
61- query = { queryBarQuery . filter }
47+ onUpdateQuery = { onUpdateQuery }
48+ query = { query }
6249 />
6350 ) ;
6451 }
@@ -68,8 +55,8 @@ const Document = (props: DocumentProps) => {
6855 < EditableDocument
6956 { ...props }
7057 doc = { doc }
71- onUpdateQuery = { handleAddToQuery }
72- query = { queryBarQuery . filter }
58+ onUpdateQuery = { onUpdateQuery }
59+ query = { query }
7360 />
7461 ) ;
7562 }
@@ -78,8 +65,8 @@ const Document = (props: DocumentProps) => {
7865 < ReadonlyDocument
7966 doc = { doc }
8067 copyToClipboard = { copyToClipboard }
81- onUpdateQuery = { handleAddToQuery }
82- query = { queryBarQuery . filter }
68+ onUpdateQuery = { onUpdateQuery }
69+ query = { query }
8370 />
8471 ) ;
8572} ;
0 commit comments