From 88b06945c8a1fcb7bc518de878a4894de70dda94 Mon Sep 17 00:00:00 2001 From: bobzel Date: Sat, 22 Aug 2020 14:21:41 -0400 Subject: major overhaul of search to avoid writing anything to filtered documents and to make the UI work properly. --- src/client/views/search/SearchBox.tsx | 128 +++++++++++++--------------------- 1 file changed, 49 insertions(+), 79 deletions(-) (limited to 'src/client/views/search') diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx index c571adefe..9c9900bfb 100644 --- a/src/client/views/search/SearchBox.tsx +++ b/src/client/views/search/SearchBox.tsx @@ -1,6 +1,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Tooltip } from '@material-ui/core'; -import { action, computed, IReactionDisposer, observable, runInAction } from 'mobx'; +import { action, computed, IReactionDisposer, observable, reaction, runInAction } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; import { Doc, DocListCast, Field, Opt } from '../../../fields/Doc'; @@ -17,8 +17,8 @@ import { SetupDrag } from '../../util/DragManager'; import { SearchUtil } from '../../util/SearchUtil'; import { SelectionManager } from '../../util/SelectionManager'; import { Transform } from '../../util/Transform'; -import { ColumnType } from "../collections/CollectionSchemaView"; -import { CollectionView, CollectionViewType } from '../collections/CollectionView'; +import { CollectionSchemaView, ColumnType } from "../collections/CollectionSchemaView"; +import { CollectionViewType } from '../collections/CollectionView'; import { ViewBoxBaseComponent } from "../DocComponent"; import { DocumentView } from '../nodes/DocumentView'; import { FieldView, FieldViewProps } from '../nodes/FieldView'; @@ -46,11 +46,11 @@ export class SearchBox extends ViewBoxBaseComponent(); + @observable _currentSelectedCollection: DocumentView | undefined = undefined; @observable _icons: string[] = this._allIcons; @observable _results: [Doc, string[], string[]][] = []; @observable _visibleElements: JSX.Element[] = []; @@ -64,9 +64,7 @@ export class SearchBox extends ViewBoxBaseComponent this.props.Document._docFilters, + (filters: any) => this.setSearchFilter(this._currentSelectedCollection, this.filter ? undefined : this.docsforfilter)); }); componentWillUnmount() { @@ -89,14 +89,12 @@ export class SearchBox extends ViewBoxBaseComponent(docsforFilter); - this.setSearchDocsRecursive(selectedCollection, docsforFilter); - } + this.setSearchFilter(selectedCollection, this.filter && found.length ? docsforFilter : undefined); this._numTotalResults = found.length; this.realTotalResults = found.length; } @@ -277,23 +269,17 @@ export class SearchBox extends ViewBoxBaseComponent { - if (this.currentSelectedCollection !== undefined) { - this.setSearchDocsRecursive(this.currentSelectedCollection, undefined); - } - if (reset) { - this.layoutDoc._searchString = ""; - } + submitSearch = async () => { + this.resetSearch(false); + //this.props.Document._docFilters = new List(); this._noResults = ""; this.dataDoc[this.fieldKey] = new List([]); - this.headercount = 0; this.children = 0; let query = StrCast(this.layoutDoc._searchString); Doc.SetSearchQuery(query); - this._searchFullDB ? query = this.getFinalQuery(query) : console.log("local"); - this.closeSearch(false); + this._searchFullDB && (query = this.getFinalQuery(query)); this._results = []; this._resultsSet.clear(); this._visibleElements = []; @@ -425,12 +411,14 @@ export class SearchBox extends ViewBoxBaseComponent { + resetSearch = (close: boolean) => { this._results.forEach(result => { Doc.UnBrushDoc(result[0]); Doc.ClearSearchMatches(); }); - closesearchbar && (this._searchbarOpen = false); + if (close) { + this._searchbarOpen = false; + } } @action.bound @@ -482,7 +470,6 @@ export class SearchBox extends ViewBoxBaseComponent typeof i === "string" ? new SchemaHeaderField(i, "#f1efeb") : i); @@ -491,7 +478,6 @@ export class SearchBox extends ViewBoxBaseComponent(newSchemaHeaders); } else if (this.props.Document._schemaHeaders === undefined) { this.props.Document._schemaHeaders = new List([new SchemaHeaderField("title", "#f1efeb")]); @@ -518,12 +504,10 @@ export class SearchBox extends ViewBoxBaseComponent { - scope && (this.filter = false); + this.docsforfilter = undefined; + this.setSearchFilter(this._currentSelectedCollection, undefined); this._searchFullDB = scope; this.dataDoc[this.fieldKey] = new List([]); - if (this.currentSelectedCollection !== undefined) { - this.setSearchDocsRecursive(this.currentSelectedCollection, undefined); - } this.submitSearch(); } @@ -558,28 +542,14 @@ export class SearchBox extends ViewBoxBaseComponent; } - setSearchDocsRecursive = (collectionView: DocumentView, filter: Doc[] | undefined) => { - let docs = DocListCast(collectionView.dataDoc[Doc.LayoutFieldKey(collectionView.dataDoc)]); - let newarray: Doc[] = []; - while (docs.length > 0) { - newarray = []; - docs.forEach(d => { - const subDocs = DocListCast(d.data); - if (subDocs.length) { - d._searchDocs = filter ? new List(filter) : undefined; - DocListCast(d.data).forEach(newdoc => newarray.push(newdoc)); - } - }); - docs = newarray; + setSearchFilter = (collectionView: DocumentView | undefined, docsForFilter: Doc[] | undefined) => { + if (collectionView) { + const docFilters = Cast(this.props.Document._docFilters, listSpec("string"), null); + collectionView.props.Document._searchFilterDocs = docsForFilter?.length ? new List(docsForFilter) : undefined; + collectionView.props.Document._docFilters = docsForFilter?.length && docFilters?.length ? new List(docFilters) : undefined; } - collectionView.props.Document._searchDocs = filter ? new List(filter) : undefined; - this.props.Document.selectedDoc = filter ? collectionView.props.Document : undefined; } - render() { - this.props.Document._chromeStatus === "disabled"; - this.props.Document._searchDoc = true; - const rows = this.children; return (
{`${Doc.CurrentUserEmail}/${Cast(Doc.UserDoc().activeDashboard, Doc, null)?.title}`}
@@ -604,34 +574,34 @@ export class SearchBox extends ViewBoxBaseComponent { e.stopPropagation(); SetupDrag(this.collectionRef, () => this.layoutDoc._searchString ? this.startDragCollection() : undefined); }} - onClick={action(() => { - this.filter = !this.filter && !this._searchFullDB; - this.currentSelectedCollection && this.setSearchDocsRecursive(this.currentSelectedCollection, this.filter ? this.docsforfilter : undefined); - })} /> + onClick={action(() => this.setSearchFilter(this._currentSelectedCollection, this.filter ? undefined : this.docsforfilter))} />
{this.scopeButtons} - - {!this._searchbarOpen ? (null) :
-
-
- window.innerWidth || rows > 6 ? true : false} - focus={this.selectElement} - ScreenToLocalTransform={Transform.Identity} - /> + {!this._searchbarOpen ? (null) : +
r?.focus()}> +
+
+ window.innerWidth || this.children > 6 ? true : false} + focus={this.selectElement} + ScreenToLocalTransform={Transform.Identity} + /> +
-
}
); -- cgit v1.2.3-70-g09d2