diff options
| author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-09-18 20:43:14 -0400 |
|---|---|---|
| committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-09-18 20:43:14 -0400 |
| commit | e0b354b275c3a025b93f93815bd1828ba9cec5a8 (patch) | |
| tree | 6b83c490b3d1c016ffd4d869520a500caf5aa6a8 /src/client/views/collections | |
| parent | a734c38aa317b8ca9bf2b19853115872824f2b97 (diff) | |
fixed filtering; cells update properly with input
Diffstat (limited to 'src/client/views/collections')
| -rw-r--r-- | src/client/views/collections/collectionSchema/CollectionSchemaView.tsx | 48 | ||||
| -rw-r--r-- | src/client/views/collections/collectionSchema/SchemaCellField.tsx | 12 |
2 files changed, 53 insertions, 7 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 59ccec71f..9623b0d12 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -45,6 +45,7 @@ import { docs_v1 } from 'googleapis'; import { SchemaCellField } from './SchemaCellField'; import { threadId } from 'worker_threads'; import { FontIconBox } from '../../nodes/FontIconBox/FontIconBox'; +import { SnappingManager } from '../../../util/SnappingManager'; const { SCHEMA_NEW_NODE_HEIGHT } = require('../../global/globalCssVariables.module.scss'); // prettier-ignore @@ -1271,6 +1272,49 @@ export class CollectionSchemaView extends CollectionSubView() { return toReturn; } + @computed get filteredDocs() { + const childDocFilters = this.childDocFilters(); + const childFiltersByRanges = this.childDocRangeFilters(); + const searchDocs = this.searchFilterDocs(); + + const docsforFilter: Doc[] = []; + this._docs.forEach(d => { + // dragging facets + const dragged = this._props.childFilters?.().some(f => f.includes(ClientUtils.noDragDocsFilter)); + if (dragged && SnappingManager.CanEmbed && DragManager.docsBeingDragged.includes(d)) return; + let notFiltered = d.z || Doc.IsSystem(d) || DocUtils.FilterDocs([d], this.unrecursiveDocFilters(), childFiltersByRanges, this.Document).length > 0; + if (notFiltered) { + notFiltered = (!searchDocs.length || searchDocs.includes(d)) && DocUtils.FilterDocs([d], childDocFilters, childFiltersByRanges, this.Document).length > 0; + const fieldKey = Doc.LayoutFieldKey(d); + const isAnnotatableDoc = d[fieldKey] instanceof List && !(d[fieldKey] as List<Doc>)?.some(ele => !(ele instanceof Doc)); + const docChildDocs = d[isAnnotatableDoc ? fieldKey + '_annotations' : fieldKey]; + const sidebarDocs = isAnnotatableDoc && d[fieldKey + '_sidebar']; + if (docChildDocs !== undefined || sidebarDocs !== undefined) { + let subDocs = [...DocListCast(docChildDocs), ...DocListCast(sidebarDocs)]; + if (subDocs.length > 0) { + let newarray: Doc[] = []; + notFiltered = notFiltered || (!searchDocs.length && DocUtils.FilterDocs(subDocs, childDocFilters, childFiltersByRanges, d).length); + while (subDocs.length > 0 && !notFiltered) { + newarray = []; + // eslint-disable-next-line no-loop-func + subDocs.forEach(t => { + const docFieldKey = Doc.LayoutFieldKey(t); + const isSubDocAnnotatable = t[docFieldKey] instanceof List && !(t[docFieldKey] as List<Doc>)?.some(ele => !(ele instanceof Doc)); + notFiltered = + notFiltered || ((!searchDocs.length || searchDocs.includes(t)) && ((!childDocFilters.length && !childFiltersByRanges.length) || DocUtils.FilterDocs([t], childDocFilters, childFiltersByRanges, d).length)); + DocListCast(t[isSubDocAnnotatable ? docFieldKey + '_annotations' : docFieldKey]).forEach(newdoc => newarray.push(newdoc)); + isSubDocAnnotatable && DocListCast(t[docFieldKey + '_sidebar']).forEach(newdoc => newarray.push(newdoc)); + }); + subDocs = newarray; + } + } + } + } + notFiltered && docsforFilter.push(d); + }); + return docsforFilter; + } + @computed get docs() { let docsFromChildren: Doc[] = []; @@ -1279,7 +1323,7 @@ export class CollectionSchemaView extends CollectionSubView() { let docsNotAlreadyDisplayed = this.subCollectionDocs(d, true).filter(dc => !this._docs.includes(dc)); docsFromChildren = docsFromChildren.concat(docsNotAlreadyDisplayed); }); - let docs = this._docs.concat(docsFromChildren); + let docs = this.filteredDocs; return docs; } @@ -1288,7 +1332,7 @@ export class CollectionSchemaView extends CollectionSubView() { const numbers: Doc[] = []; const strings: Doc[] = []; - this._docs.forEach(doc => { + this.docs.forEach(doc => { if (!isNaN(Number(Field.toString(doc[field] as FieldType)))) numbers.push(doc); else strings.push(doc); }); diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx index e1059b8fc..1ee79fa0b 100644 --- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx +++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx @@ -151,6 +151,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro setContent = (content: string, restoreCursorPos?: boolean) => { const pos = this.cursorPosition; this._displayedContent = this.makeSpans(content); + console.log('print', content); restoreCursorPos && setTimeout(() => this.setCursorPosition(pos)); } @@ -217,10 +218,11 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro setRange(this._inputref.childNodes); }; - shouldUpdate = (prevVal: string, currVal: string) => { - if (this._props.getCells(currVal).length !== this._props.getCells(prevVal).length) return true; - //if (contains self-ref pattern) - }; + //This function checks if a visual update (eg. coloring a cell reference) should be made. It's meant to + //save on processing upkeep vs. constantly rerendering, but I think the savings are minimal for now + // shouldUpdate = (prevVal: string, currVal: string) => { + // if (this._props.getCells(currVal).length !== this._props.getCells(prevVal).length) return true; + // }; onChange = (e: FormEvent<HTMLDivElement> | undefined, newText?: string) => { const prevVal = this._unrenderedContent; @@ -233,7 +235,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro } this._unrenderedContent = targVal; this._props.highlightCells?.(targVal); - if (this.shouldUpdate(prevVal, targVal)) {this.setContent(targVal, true)}; + this.setContent(targVal, true); this.setupRefSelect(this.refSelectConditionMet); }; |
