aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search/SearchBox.tsx
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-07-16 17:48:16 -0400
committeryipstanley <stanley_yip@brown.edu>2019-07-16 17:48:16 -0400
commitf18be9418b9237acd847eaf71adc034226c54695 (patch)
tree55d1af22c1b008196eb68eb80f82d4c659259d8a /src/client/views/search/SearchBox.tsx
parent7a4310f95da38cf5de55e487030284157acc58d8 (diff)
parent2e12b7e348ec842ddc2deb6a47f58b6312f2aa95 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/client/views/search/SearchBox.tsx')
-rw-r--r--src/client/views/search/SearchBox.tsx40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index ec778b346..d07df7e58 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -6,7 +6,7 @@ import "./FilterBox.scss";
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { SetupDrag } from '../../util/DragManager';
import { Docs } from '../../documents/Documents';
-import { NumCast } from '../../../new_fields/Types';
+import { NumCast, Cast } from '../../../new_fields/Types';
import { Doc } from '../../../new_fields/Doc';
import { SearchItem } from './SearchItem';
import { DocServer } from '../../DocServer';
@@ -22,7 +22,9 @@ export class SearchBox extends React.Component {
@observable private _searchString: string = "";
@observable private _resultsOpen: boolean = false;
+ @observable private _searchbarOpen: boolean = false;
@observable private _results: Doc[] = [];
+ private _resultsSet = new Set<Doc>();
@observable private _openNoResults: boolean = false;
@observable private _visibleElements: JSX.Element[] = [];
@@ -60,6 +62,7 @@ export class SearchBox extends React.Component {
this._openNoResults = false;
this._results = [];
+ this._resultsSet.clear();
this._visibleElements = [];
this._numTotalResults = -1;
this._endIndex = -1;
@@ -91,8 +94,10 @@ export class SearchBox extends React.Component {
let query = this._searchString;
query = FilterBox.Instance.getFinalQuery(query);
this._results = [];
+ this._resultsSet.clear();
this._isSearch = [];
this._visibleElements = [];
+ FilterBox.Instance.closeFilter();
//if there is no query there should be no result
if (query === "") {
@@ -107,6 +112,7 @@ export class SearchBox extends React.Component {
runInAction(() => {
this._resultsOpen = true;
+ this._searchbarOpen = true;
this._openNoResults = true;
this.resultsScrolled();
});
@@ -118,7 +124,8 @@ export class SearchBox extends React.Component {
private get filterQuery() {
const types = FilterBox.Instance.filterTypes;
- return "proto_i:*" + (types ? ` AND (${types.map(type => `({!join from=id to=proto_i}type_t:"${type}" AND NOT type_t:*) OR type_t:"${type}"`).join(" ")})` : "");
+ const includeDeleted = FilterBox.Instance.getDataStatus();
+ return "NOT baseProto_b:true" + (includeDeleted ? "" : " AND NOT deleted:true") + (types ? ` AND (${types.map(type => `({!join from=id to=proto_i}type_t:"${type}" AND NOT type_t:*) OR type_t:"${type}"`).join(" ")})` : "");
}
@@ -129,15 +136,24 @@ export class SearchBox extends React.Component {
}
this.lockPromise = new Promise(async res => {
while (this._results.length <= this._endIndex && (this._numTotalResults === -1 || this._maxSearchIndex < this._numTotalResults)) {
- this._curRequest = SearchUtil.Search(query, this.filterQuery, true, this._maxSearchIndex, 10).then(action((res: SearchUtil.DocSearchResult) => {
+ this._curRequest = SearchUtil.Search(query, this.filterQuery, true, this._maxSearchIndex, 10).then(action(async (res: SearchUtil.DocSearchResult) => {
// happens at the beginning
if (res.numFound !== this._numTotalResults && this._numTotalResults === -1) {
this._numTotalResults = res.numFound;
}
- let filteredDocs = FilterBox.Instance.filterDocsByType(res.docs);
- this._results.push(...filteredDocs);
+ const docs = await Promise.all(res.docs.map(doc => Cast(doc.extendsDoc, Doc, doc as any)));
+ let filteredDocs = FilterBox.Instance.filterDocsByType(docs);
+ runInAction(() => {
+ // this._results.push(...filteredDocs);
+ filteredDocs.forEach(doc => {
+ if (!this._resultsSet.has(doc)) {
+ this._results.push(doc);
+ this._resultsSet.add(doc);
+ }
+ });
+ });
this._curRequest = undefined;
}));
@@ -198,6 +214,7 @@ export class SearchBox extends React.Component {
this._openNoResults = false;
FilterBox.Instance.closeFilter();
this._resultsOpen = true;
+ this._searchbarOpen = true;
FilterBox.Instance._pointerTime = e.timeStamp;
}
@@ -205,12 +222,14 @@ export class SearchBox extends React.Component {
closeSearch = () => {
FilterBox.Instance.closeFilter();
this.closeResults();
+ this._searchbarOpen = false;
}
@action.bound
closeResults() {
this._resultsOpen = false;
this._results = [];
+ this._resultsSet.clear();
this._visibleElements = [];
this._numTotalResults = -1;
this._endIndex = -1;
@@ -281,15 +300,10 @@ export class SearchBox extends React.Component {
}
@computed
- get resFull() {
- console.log(this._numTotalResults);
- return this._numTotalResults <= 8;
- }
+ get resFull() { return this._numTotalResults <= 8; }
@computed
- get resultHeight() {
- return this._numTotalResults * 70;
- }
+ get resultHeight() { return this._numTotalResults * 70; }
render() {
return (
@@ -300,7 +314,7 @@ export class SearchBox extends React.Component {
</span>
<input value={this._searchString} onChange={this.onChange} type="text" placeholder="Search..."
className="searchBox-barChild searchBox-input" onPointerDown={this.openSearch} onKeyPress={this.enter}
- style={{ width: this._resultsOpen ? "500px" : "100px" }} />
+ style={{ width: this._searchbarOpen ? "500px" : "100px" }} />
<button className="searchBox-barChild searchBox-submit" onClick={this.submitSearch} onPointerDown={FilterBox.Instance.stopProp}>Submit</button>
<button className="searchBox-barChild searchBox-filter" onClick={FilterBox.Instance.openFilter} onPointerDown={FilterBox.Instance.stopProp}>Filter</button>
</div>