aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-06-23 21:44:01 -0400
committerbobzel <zzzman@gmail.com>2023-06-23 21:44:01 -0400
commit85c017527f209c9d007d67ac70958843ab45e729 (patch)
treee2649860002e0c60e98d84439a67235002ddd9a4 /src/client/views/search
parente9d5dbeef2bf1dab9dfb863d970b70b3074e3d0a (diff)
parent1429ab79eac9aa316082f52c14c576f6b3a97111 (diff)
Merge branch 'master' into heartbeat
Diffstat (limited to 'src/client/views/search')
-rw-r--r--src/client/views/search/SearchBox.tsx117
1 files changed, 69 insertions, 48 deletions
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index c5177de90..d13c09443 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -2,12 +2,15 @@ import { Tooltip } from '@material-ui/core';
import { action, computed, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-import { DirectLinksSym, Doc, DocListCast, DocListCastAsync, Field } from '../../../fields/Doc';
+import { Doc, DocListCast, DocListCastAsync, Field, Opt } from '../../../fields/Doc';
+import { DirectLinks } from '../../../fields/DocSymbols';
import { Id } from '../../../fields/FieldSymbols';
-import { StrCast } from '../../../fields/Types';
+import { DocCast, StrCast } from '../../../fields/Types';
import { DocUtils } from '../../documents/Documents';
import { DocumentType } from '../../documents/DocumentTypes';
import { DocumentManager } from '../../util/DocumentManager';
+import { LinkManager } from '../../util/LinkManager';
+import { undoBatch } from '../../util/UndoManager';
import { CollectionDockingView } from '../collections/CollectionDockingView';
import { ViewBoxBaseComponent } from '../DocComponent';
import { FieldView, FieldViewProps } from '../nodes/FieldView';
@@ -20,6 +23,8 @@ const ERROR = 0.03;
export interface SearchBoxProps extends FieldViewProps {
linkSearch: boolean;
linkFrom?: (() => Doc | undefined) | undefined;
+ linkCreateAnchor?: () => Doc | undefined;
+ linkCreated?: (link: Doc) => void;
}
/**
@@ -43,7 +48,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
@observable _linkedDocsIn: Map<Doc, Set<Doc>> = new Map<Doc, Set<Doc>>();
@observable _selectedResult: Doc | undefined = undefined;
@observable _deletedDocsStatus: boolean = false;
- @observable _onlyAliases: boolean = true;
+ @observable _onlyEmbeddings: boolean = true;
/**
* This is the constructor for the SearchBox class.
@@ -109,13 +114,12 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
this.selectElement(doc, () => DocumentManager.Instance.getFirstDocumentView(doc)?.ComponentView?.search?.(this._searchString, undefined, false));
});
- // TODO: nda -- Change this method to change what happens when you click on the item.
+ @undoBatch
makeLink = action((linkTo: Doc) => {
- if (this.props.linkFrom) {
- const linkFrom = this.props.linkFrom();
- if (linkFrom) {
- DocUtils.MakeLink({ doc: linkFrom }, { doc: linkTo });
- }
+ const linkFrom = this.props.linkCreateAnchor?.();
+ if (linkFrom) {
+ const link = DocUtils.MakeLink(linkFrom, linkTo, {});
+ link && this.props.linkCreated?.(link);
}
});
@@ -136,8 +140,10 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
visited.push(d);
const fieldKey = Doc.LayoutFieldKey(d);
const annos = !Field.toString(Doc.LayoutField(d) as Field).includes('CollectionView');
- const data = d[annos ? fieldKey + '-annotations' : fieldKey];
+ const data = d[annos ? fieldKey + '_annotations' : fieldKey];
data && newarray.push(...DocListCast(data));
+ const sidebar = d[fieldKey + '_sidebar'];
+ sidebar && newarray.push(...DocListCast(sidebar));
func(depth, d);
});
docs = newarray;
@@ -163,7 +169,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
.map(async d => {
const fieldKey = Doc.LayoutFieldKey(d);
const annos = !Field.toString(Doc.LayoutField(d) as Field).includes('CollectionView');
- const data = d[annos ? fieldKey + '-annotations' : fieldKey];
+ const data = d[annos ? fieldKey + '_annotations' : fieldKey];
const docs = await DocListCastAsync(data);
docs && newarray.push(...docs);
func(depth, d);
@@ -201,53 +207,57 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
*/
@action
searchCollection(query: string) {
- const blockedTypes = [DocumentType.PRESELEMENT, DocumentType.KVP, DocumentType.FILTER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
+ this._selectedResult = undefined;
+ this._results = SearchBox.staticSearchCollection(CollectionDockingView.Instance?.rootDoc, query);
+
+ this.computePageRanks();
+ }
+ @action
+ static staticSearchCollection(rootDoc: Opt<Doc>, query: string) {
+ const blockedTypes = [DocumentType.PRESELEMENT, DocumentType.CONFIG, DocumentType.KVP, DocumentType.FILTER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
const blockedKeys = [
'x',
'y',
'proto',
'width',
- 'autoHeight',
+ 'layout_autoHeight',
'acl-Override',
'acl-Public',
- 'context',
+ 'embedContainer',
'zIndex',
'height',
- 'text-scrollHeight',
- 'text-height',
+ 'text_scrollHeight',
+ 'text_height',
'cloneFieldFilter',
- 'isPrototype',
- 'text-annotations',
- 'dragFactory-count',
- 'text-noTemplate',
- 'aliases',
- 'system',
- 'layoutKey',
- 'baseProto',
+ 'isDataDoc',
+ 'text_annotations',
+ 'dragFactory_count',
+ 'text_noTemplate',
+ 'proto_embeddings',
+ 'isSystem',
+ 'layout_fieldKey',
+ 'isBaseProto',
'xMargin',
'yMargin',
'links',
'layout',
'layout_keyValue',
- 'fitWidth',
- 'viewType',
- 'title-custom',
- 'panX',
- 'panY',
- 'viewScale',
+ 'layout_fitWidth',
+ 'type_collection',
+ 'title_custom',
+ 'freeform_panX',
+ 'freeform_panY',
+ 'freeform_scale',
];
- const collection = CollectionDockingView.Instance;
query = query.toLowerCase();
- this._results.clear();
- this._selectedResult = undefined;
-
- if (collection !== undefined) {
- const docs = DocListCast(collection.rootDoc[Doc.LayoutFieldKey(collection.rootDoc)]);
+ const results = new Map<Doc, string[]>();
+ if (rootDoc) {
+ const docs = DocListCast(rootDoc[Doc.LayoutFieldKey(rootDoc)]);
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 dtype = StrCast(doc.type) as DocumentType;
+ if (dtype && !blockedTypes.includes(dtype) && !docIDs.includes(doc[Id]) && depth >= 0) {
const hlights = new Set<string>();
SearchBox.documentKeys(doc).forEach(
key =>
@@ -258,14 +268,13 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
blockedKeys.forEach(key => hlights.delete(key));
if (Array.from(hlights.keys()).length > 0) {
- this._results.set(doc, Array.from(hlights.keys()));
+ results.set(doc, Array.from(hlights.keys()));
}
}
docIDs.push(doc[Id]);
});
}
-
- this.computePageRanks();
+ return results;
}
/**
@@ -284,7 +293,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
this._results.forEach((_, doc) => {
this._pageRanks.set(doc, 1.0 / this._results.size);
- if (Doc.GetProto(doc)[DirectLinksSym].size === 0) {
+ if (Doc.GetProto(doc)[DirectLinks].size === 0) {
this._linkedDocsOut.set(doc, new Set(this._results.keys()));
this._results.forEach((_, linkedDoc) => {
@@ -293,9 +302,9 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
} else {
const linkedDocSet = new Set<Doc>();
- Doc.GetProto(doc)[DirectLinksSym].forEach(link => {
- const d1 = link?.anchor1 as Doc;
- const d2 = link?.anchor2 as Doc;
+ Doc.GetProto(doc)[DirectLinks].forEach(link => {
+ const d1 = link?.link_anchor_1 as Doc;
+ const d2 = link?.link_anchor_2 as Doc;
if (doc === d1 && this._results.has(d2)) {
linkedDocSet.add(d2);
this._linkedDocsIn.get(d2)?.add(doc);
@@ -380,7 +389,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
const query = StrCast(this._searchString);
Doc.SetSearchQuery(query);
- Array.from(this._results.keys()).forEach(doc => DocumentManager.Instance.getFirstDocumentView(doc)?.ComponentView?.search?.(this._searchString, undefined, true));
+ if (!this.props.linkSearch) Array.from(this._results.keys()).forEach(doc => DocumentManager.Instance.getFirstDocumentView(doc)?.ComponentView?.search?.(this._searchString, undefined, true));
this._results.clear();
if (query) {
@@ -407,7 +416,7 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
* or opening it in a new tab.
*/
selectElement = async (doc: Doc, finishFunc: () => void) => {
- await DocumentManager.Instance.jumpToDocument(doc, true, undefined, [], undefined, undefined, undefined, finishFunc);
+ await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, finishFunc);
};
/**
@@ -437,6 +446,8 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
const resultsJSX = Array();
+ const fromDoc = this.props.linkFrom?.();
+
sortedResults.forEach(result => {
var className = 'searchBox-results-scroll-view-result';
@@ -460,6 +471,13 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
e.stopPropagation();
}
}
+ style={{
+ fontWeight: LinkManager.Links(fromDoc).find(
+ link => Doc.AreProtosEqual(LinkManager.getOppositeAnchor(link, fromDoc!), result[0] as Doc) || Doc.AreProtosEqual(DocCast(LinkManager.getOppositeAnchor(link, fromDoc!)?.annotationOn), result[0] as Doc)
+ )
+ ? 'bold'
+ : '',
+ }}
className={className}>
<div className="searchBox-result-title">{title as string}</div>
<div className="searchBox-result-type">{formattedType}</div>
@@ -482,7 +500,10 @@ export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps>() {
defaultValue={''}
autoComplete="off"
onChange={this.onInputChange}
- onKeyPress={e => (e.key === 'Enter' ? this.submitSearch() : null)}
+ onKeyPress={e => {
+ e.key === 'Enter' ? this.submitSearch() : null;
+ e.stopPropagation();
+ }}
type="text"
placeholder="Search..."
id="search-input"