aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search
diff options
context:
space:
mode:
authorAubrey Li <Aubrey-Li>2021-09-15 14:41:24 -0400
committerAubrey Li <Aubrey-Li>2021-09-15 14:41:24 -0400
commiteb63330e172935343767d0dcc7ffad9bfa1a75c4 (patch)
tree031bf155df50200f9652e881aec18002bc9e399e /src/client/views/search
parentb7a88c6292c2e7bfffc3cdc4f7c7037922b3de25 (diff)
parent8386ad690c10d5c76bbd1b4f85314514b7f11b55 (diff)
merge master into trails-aubrey
Diffstat (limited to 'src/client/views/search')
-rw-r--r--src/client/views/search/SearchBox.scss6
-rw-r--r--src/client/views/search/SearchBox.tsx101
2 files changed, 66 insertions, 41 deletions
diff --git a/src/client/views/search/SearchBox.scss b/src/client/views/search/SearchBox.scss
index 2586ef2ee..e8865b918 100644
--- a/src/client/views/search/SearchBox.scss
+++ b/src/client/views/search/SearchBox.scss
@@ -78,8 +78,10 @@
.searchBox-result-title {
display: relative;
float: left;
- width: calc(100% - 60px);
+ width: calc(100% - 45px);
text-align: left;
+ overflow: hidden;
+ text-overflow: ellipsis;
}
.searchBox-result-type {
@@ -87,7 +89,7 @@
margin-top: 6px;
display: relative;
float: right;
- width: 60px;
+ width: 45px;
text-align: right;
color: #222;
}
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index b07879674..9c353e9d0 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -7,23 +7,32 @@ import { Id } from '../../../fields/FieldSymbols';
import { createSchema, makeInterface } from '../../../fields/Schema';
import { StrCast } from '../../../fields/Types';
import { DocumentType } from "../../documents/DocumentTypes";
-import { DocumentManager } from "../../util/DocumentManager";
import { CollectionDockingView } from "../collections/CollectionDockingView";
import { ViewBoxBaseComponent } from "../DocComponent";
import { FieldView, FieldViewProps } from '../nodes/FieldView';
import "./SearchBox.scss";
+import { DocumentManager } from '../../util/DocumentManager';
+import { DocUtils } from '../../documents/Documents';
+import { Tooltip } from "@material-ui/core";
-export const searchSchema = createSchema({ Document: Doc });
+export const searchSchema = createSchema({
+ Document: Doc
+});
type SearchBoxDocument = makeInterface<[typeof documentSchema, typeof searchSchema]>;
const SearchBoxDocument = makeInterface(documentSchema, searchSchema);
+export interface SearchBoxProps extends FieldViewProps {
+ linkSearch: boolean;
+ linkFrom?: (() => Doc | undefined) | undefined;
+}
+
/**
* This is the SearchBox component. It represents the search box input and results in
* the search panel on the left side of the screen.
*/
@observer
-export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDocument>(SearchBoxDocument) {
+export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps, SearchBoxDocument>(SearchBoxDocument) {
public static LayoutString(fieldKey: string) { return FieldView.LayoutString(SearchBox, fieldKey); }
public static Instance: SearchBox;
@@ -100,6 +109,17 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
this._selectedResult = doc;
});
+ makeLink = action((linkTo: Doc) => {
+ console.log(linkTo.title);
+ if (this.props.linkFrom) {
+ const linkFrom = this.props.linkFrom();
+ if (linkFrom) {
+ console.log(linkFrom.title);
+ DocUtils.MakeLink({ doc: linkFrom }, { doc: linkTo }, "Link");
+ }
+ }
+ });
+
/**
* @param {Doc[]} docs - docs to be searched through recursively
* @param {number, Doc => void} func - function to be called on each doc
@@ -157,10 +177,10 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
* right side of each search result.
*/
static formatType(type: String): String {
- if (type == "pdf") {
+ if (type === "pdf") {
return "PDF";
}
- else if (type == "image") {
+ else if (type === "image") {
return "Img";
}
@@ -180,28 +200,25 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
const blockedTypes = [DocumentType.PRESELEMENT, DocumentType.KVP, DocumentType.FILTER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
const blockedKeys = ["x", "y", "proto", "width", "autoHeight", "acl-Override", "acl-Public", "context", "zIndex", "height", "text-scrollHeight", "text-height", "cloneFieldFilter", "isPrototype", "text-annotations",
"dragFactory-count", "text-noTemplate", "aliases", "system", "layoutKey", "baseProto", "xMargin", "yMargin", "links", "layout", "layout_keyValue", "fitWidth", "viewType", "title-custom",
- "panX", "panY", "viewScale"]
+ "panX", "panY", "viewScale"];
const collection = CollectionDockingView.Instance;
query = query.toLowerCase();
- this._results = []
- this._selectedResult = undefined
+ this._results = [];
+ this._selectedResult = undefined;
if (collection !== undefined) {
const docs = DocListCast(collection.rootDoc[Doc.LayoutFieldKey(collection.rootDoc)]);
- const docIDs: String[] = []
- console.log(docs.length)
+ const docIDs: String[] = [];
SearchBox.foreachRecursiveDoc(docs, (depth: number, doc: Doc) => {
const dtype = StrCast(doc.type, "string") as DocumentType;
if (dtype && !blockedTypes.includes(dtype) && !docIDs.includes(doc[Id]) && depth > 0) {
const hlights = new Set<string>();
SearchBox.documentKeys(doc).forEach(key => Field.toString(doc[key] as Field).toLowerCase().includes(query) && hlights.add(key));
- blockedKeys.forEach(key => {
- hlights.delete(key);
- })
+ blockedKeys.forEach(key => hlights.delete(key));
Array.from(hlights.keys()).length > 0 && this._results.push([doc, Array.from(hlights.keys())]);
}
- docIDs.push(doc[Id])
+ docIDs.push(doc[Id]);
});
}
}
@@ -225,7 +242,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
submitSearch = async () => {
this.resetSearch();
- let query = StrCast(this._searchString);
+ const query = StrCast(this._searchString);
Doc.SetSearchQuery(query);
this._results = [];
@@ -262,11 +279,9 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
*/
@computed
public get selectOptions() {
- const selectValues = ["all", "rtf", "image", "pdf", "web", "video", "audio", "collection"]
+ const selectValues = ["all", "rtf", "image", "pdf", "web", "video", "audio", "collection"];
- return selectValues.map(value => {
- return <option key={value} value={value}>{SearchBox.formatType(value)}</option>
- })
+ return selectValues.map(value => <option key={value} value={value}>{SearchBox.formatType(value)}</option>);
}
/**
@@ -275,46 +290,54 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
render() {
var validResults = 0;
+ const isLinkSearch: boolean = this.props.linkSearch;
+
+
const results = this._results.map(result => {
var className = "searchBox-results-scroll-view-result";
- if (this._selectedResult == result[0]) {
- className += " searchBox-results-scroll-view-result-selected"
+ if (this._selectedResult === result[0]) {
+ className += " searchBox-results-scroll-view-result-selected";
}
- if (this._docTypeString == "all" || this._docTypeString == result[0].type) {
+ const formattedType = SearchBox.formatType(StrCast(result[0].type));
+ const title = result[0].title;
+
+ if (this._docTypeString === "all" || this._docTypeString === result[0].type) {
validResults++;
return (
- <div key={result[0][Id]} onClick={() => this.onResultClick(result[0])} className={className}>
- <div className="searchBox-result-title">
- {result[0].title}
- </div>
- <div className="searchBox-result-type">
- {SearchBox.formatType(StrCast(result[0].type))}
+ <Tooltip key={result[0][Id]} placement={"right"} title={<><div className="dash-tooltip">{title}</div></>}>
+ <div onClick={isLinkSearch ? () => this.makeLink(result[0]) : () => this.onResultClick(result[0])} className={className}>
+ <div className="searchBox-result-title">
+ {title}
+ </div>
+ <div className="searchBox-result-type">
+ {formattedType}
+ </div>
+ <div className="searchBox-result-keys">
+ {result[1].join(", ")}
+ </div>
</div>
- <div className="searchBox-result-keys">
- {result[1].join(", ")}
- </div>
- </div>
- )
+ </Tooltip>
+ );
}
return null;
- })
+ });
results.filter(result => result);
return (
<div style={{ pointerEvents: "all" }} className="searchBox-container">
- <div className="searchBox-bar">
- <select name="type" id="searchBox-type" className="searchBox-type" onChange={this.onSelectChange}>
+ <div className="searchBox-bar" >
+ {isLinkSearch ? (null) : <select name="type" id="searchBox-type" className="searchBox-type" onChange={this.onSelectChange}>
{this.selectOptions}
- </select>
- <input defaultValue={""} autoComplete="off" onChange={this.onInputChange} type="text" placeholder="Search..." id="search-input" className="searchBox-input" ref={this._inputRef} />
+ </select>}
+ <input defaultValue={""} autoComplete="off" onChange={this.onInputChange} onKeyPress={e => e.key === "Enter" ? this.submitSearch() : null} type="text" placeholder="Search..." id="search-input" className="searchBox-input" style={{ width: isLinkSearch ? "100%" : undefined, borderRadius: isLinkSearch ? "5px" : undefined }} ref={this._inputRef} />
</div >
<div className="searchBox-results-container">
<div className="searchBox-results-count">
- {`${validResults}` + " result" + (validResults == 1 ? "" : "s")}
+ {`${validResults}` + " result" + (validResults === 1 ? "" : "s")}
</div>
<div className="searchBox-results-scroll-view">
{results}