aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-04-21 09:30:59 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-04-21 09:30:59 +0530
commit62936fbe7186956e038d4e7bffbeafd7873bcd8c (patch)
tree6221036f874254e595b8293d299a8a4d57a95e9c /src/client/views/search
parentcea978f8c3856c897efd92be4367ba31137e29d9 (diff)
parenta9b6fba3a742f95815e2664770079bebd3b87d5f (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/client/views/search')
-rw-r--r--src/client/views/search/IconBar.tsx4
-rw-r--r--src/client/views/search/SearchBox.tsx59
2 files changed, 29 insertions, 34 deletions
diff --git a/src/client/views/search/IconBar.tsx b/src/client/views/search/IconBar.tsx
index 9cf5a9c87..9b7cf2fc6 100644
--- a/src/client/views/search/IconBar.tsx
+++ b/src/client/views/search/IconBar.tsx
@@ -25,7 +25,7 @@ library.add(faGlobeAsia);
library.add(faBan);
export interface IconBarProps {
- setIcons: (icons: string[]) => {};
+ setIcons: (icons: string[]) => void;
}
@@ -44,7 +44,7 @@ export class IconBar extends React.Component<IconBarProps> {
@action.bound
updateIcon(newArray: string[]) {
- this._icons = newArray;
+ this._icons = newArray;
this.props.setIcons?.(this._icons);
}
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index 0947bff8d..b0a49f750 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -19,13 +19,17 @@ import { FieldView } from '../nodes/FieldView';
import { DocumentType } from "../../documents/DocumentTypes";
import { DocumentView } from '../nodes/DocumentView';
import { SelectionManager } from '../../util/SelectionManager';
+import { listSpec } from '../../../new_fields/Schema';
library.add(faTimes);
export interface SearchProps {
id: string;
- searchQuery?: string;
+ searchQuery: string;
filterQquery?: string;
+ setSearchQuery: (q: string) => {};
+ searchFileTypes: string[];
+ setSearchFileTypes: (types: string[]) => {}
}
export enum Keys {
@@ -37,7 +41,8 @@ export enum Keys {
@observer
export class SearchBox extends React.Component<SearchProps> {
- @observable private _searchString: string = "";
+ private get _searchString() { return this.props.searchQuery; }
+ private set _searchString(value) { this.props.setSearchQuery(value); }
@observable private _resultsOpen: boolean = false;
@observable private _searchbarOpen: boolean = false;
@observable private _results: [Doc, string[], string[]][] = [];
@@ -72,20 +77,16 @@ export class SearchBox extends React.Component<SearchProps> {
this.resultsScrolled = this.resultsScrolled.bind(this);
}
- componentDidMount = () => {
+ componentDidMount = action(() => {
if (this.inputRef.current) {
this.inputRef.current.focus();
- runInAction(() => this._searchbarOpen = true);
+ this._searchbarOpen = true;
}
- if (this.props.searchQuery && this.props.filterQquery) {
- console.log(this.props.searchQuery);
- const sq = this.props.searchQuery;
- runInAction(() => {
- this._searchString = sq;
- this.submitSearch();
- });
+ if (this.props.searchQuery) { // bcz: why was this here? } && this.props.filterQquery) {
+ this._searchString = this.props.searchQuery;
+ this.submitSearch();
}
- }
+ })
@action
@@ -133,7 +134,10 @@ export class SearchBox extends React.Component<SearchProps> {
//this also serves as an indicator if the word status filter is applied
@observable private _filterOpen: boolean = false;
//if icons = all icons, then no icon filter is applied
- @observable private _icons: string[] = this._allIcons;
+ get _icons() { return this.props.searchFileTypes; }
+ set _icons(value) {
+ this.props.setSearchFileTypes(value);
+ }
//if all of these are true, no key filter is applied
@observable private _titleFieldStatus: boolean = true;
@observable private _authorFieldStatus: boolean = true;
@@ -167,15 +171,7 @@ export class SearchBox extends React.Component<SearchProps> {
}
basicRequireWords(query: string): string {
- const oldWords = query.split(" ");
- const newWords: string[] = [];
- oldWords.forEach(word => {
- const newWrd = "+" + word;
- newWords.push(newWrd);
- });
- query = newWords.join(" ");
-
- return query;
+ return query.split(" ").join(" + ").replace(/ + /, "");
}
@action
@@ -214,12 +210,6 @@ export class SearchBox extends React.Component<SearchProps> {
return this._icons.length === this._allIcons.length ? undefined : this._icons;
}
- @action.bound
- updateIcon(newArray: string[]) { this._icons = newArray; }
-
- @action.bound
- getIcons(): string[] { return this._icons; }
-
//TODO: basically all of this
//gets all of the collections of all the docviews that are selected
//if a collection is the only thing selected, search only in that collection (not its container)
@@ -316,10 +306,13 @@ export class SearchBox extends React.Component<SearchProps> {
private get filterQuery() {
const types = this.filterTypes;
- const includeDeleted = this.getDataStatus() ? "" : " AND NOT deleted_b:true";
- const includeIcons = this.getDataStatus() ? "" : " AND NOT type_t:fonticonbox";
+ const baseExpr = "NOT baseProto_b:true";
+ const includeDeleted = this.getDataStatus() ? "" : " NOT deleted_b:true";
+ const includeIcons = this.getDataStatus() ? "" : " NOT type_t:fonticonbox";
+ const typeExpr = !types ? "" : ` (${types.map(type => `({!join from=id to=proto_i}type_t:"${type}" AND NOT type_t:*) OR type_t:"${type}"`).join(" ")})`;
// fq: type_t:collection OR {!join from=id to=proto_i}type_t:collection q:text_t:hello
- return "NOT baseProto_b:true" + includeDeleted + includeIcons + (types ? ` AND (${types.map(type => `({!join from=id to=proto_i}type_t:"${type}" AND NOT type_t:*) OR type_t:"${type}"`).join(" ")})` : "");
+ const query = [baseExpr, includeDeleted, includeIcons, typeExpr].join(" AND ").replace(/AND $/, "");
+ return query;
}
getDataStatus() { return this._deletedDocsStatus; }
@@ -653,7 +646,9 @@ export class SearchBox extends React.Component<SearchProps> {
<button className="filter-item" style={this._nodeStatus ? { background: "#aaaaa3" } : {}} onClick={this.handleNodeChange}>Nodes</button>
</div>
<div id={`node${this.props.id}`} className="filter-body" style={this._nodeStatus ? { borderTop: "grey 1px solid" } : { borderTop: "0px" }}>
- <IconBar setIcons={(icons: string[]) => this._icons = icons} />
+ <IconBar setIcons={(icons: string[]) => {
+ this._icons = icons;
+ }} />
</div>
<div className="filter-key" id={`key${this.props.id}`} style={this._keyStatus ? { borderTop: "grey 1px solid" } : { borderTop: "0px" }}>
<div className="filter-keybar">