aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/SidebarAnnos.tsx
diff options
context:
space:
mode:
authorbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-01-19 14:33:22 -0500
committerbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-01-19 14:33:22 -0500
commit0ef7050b0792ce183c7d5cda637cb79b7a92b704 (patch)
treed1dca8f09ddc2954c2ce88439172aeded672c0b6 /src/client/views/SidebarAnnos.tsx
parentceb338752aacc383c97a0e3a9b608365a1cf39b6 (diff)
parentd5f796b433d7e72130d4109a3775347ccb10c454 (diff)
Merge branch 'master' of github.com:brown-dash/Dash-Web into master
Diffstat (limited to 'src/client/views/SidebarAnnos.tsx')
-rw-r--r--src/client/views/SidebarAnnos.tsx97
1 files changed, 82 insertions, 15 deletions
diff --git a/src/client/views/SidebarAnnos.tsx b/src/client/views/SidebarAnnos.tsx
index 12f41394d..6d06bbbf6 100644
--- a/src/client/views/SidebarAnnos.tsx
+++ b/src/client/views/SidebarAnnos.tsx
@@ -1,9 +1,9 @@
import { computed } from 'mobx';
import { observer } from 'mobx-react';
-import { Doc, DocListCast, StrListCast } from '../../fields/Doc';
+import { Doc, DocListCast, Field, FieldResult, StrListCast } from '../../fields/Doc';
import { Id } from '../../fields/FieldSymbols';
import { List } from '../../fields/List';
-import { NumCast, StrCast } from '../../fields/Types';
+import { DocCast, NumCast, StrCast } from '../../fields/Types';
import { emptyFunction, OmitKeys, returnAll, returnOne, returnTrue, returnZero } from '../../Utils';
import { Docs, DocUtils } from '../documents/Documents';
import { CollectionViewType, DocumentType } from '../documents/DocumentTypes';
@@ -15,6 +15,7 @@ import { SearchBox } from './search/SearchBox';
import './SidebarAnnos.scss';
import { StyleProp } from './StyleProvider';
import React = require('react');
+import { RichTextField } from '../../fields/RichTextField';
interface ExtraProps {
fieldKey: string;
@@ -38,12 +39,13 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
}
_stackRef = React.createRef<CollectionStackingView>();
@computed get allMetadata() {
- const keys = new Set<string>();
- DocListCast(this.props.rootDoc[this.sidebarKey]).forEach(doc => SearchBox.documentKeys(doc).forEach(key => keys.add(key)));
- return Array.from(keys.keys())
- .filter(key => key[0])
- .filter(key => key[0] !== '_' && key[0] === key[0].toUpperCase())
- .sort();
+ const keys = new Map<string, FieldResult<Field>>();
+ DocListCast(this.props.rootDoc[this.sidebarKey]).forEach(doc =>
+ SearchBox.documentKeys(doc)
+ .filter(key => key[0] && key[0] !== '_' && key[0] === key[0].toUpperCase())
+ .map(key => keys.set(key, doc[key]))
+ );
+ return keys;
}
@computed get allUsers() {
const keys = new Set<string>();
@@ -70,10 +72,67 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
});
FormattedTextBox.SelectOnLoad = target[Id];
FormattedTextBox.DontSelectInitialText = true;
- this.allMetadata.map(tag => (target[tag] = tag));
- DocUtils.MakeLink({ doc: anchor }, { doc: target }, 'inline comment:comment on');
+ const link = DocUtils.MakeLink({ doc: anchor }, { doc: target }, 'inline comment:comment on');
+ link && (link.linkDisplay = false);
+
+ const taggedContent = this.docFilters()
+ .filter(data => data.split(':')[0])
+ .map(data => {
+ const key = data.split(':')[0];
+ const val = Field.Copy(this.allMetadata.get(key));
+ Doc.GetProto(target)[key] = val;
+ return {
+ type: 'dashField',
+ attrs: { fieldKey: key, docid: '', hideKey: false, editable: true },
+ marks: [{ type: 'pFontSize', attrs: { fontSize: '12px' } }, { type: 'strong' }, { type: 'user_mark', attrs: { userid: Doc.CurrentUserEmail, modified: 0 } }],
+ };
+ });
+
+ const textLines: any = [
+ {
+ type: 'paragraph',
+ attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null },
+ content: [
+ {
+ type: 'dashField',
+ marks: [
+ {
+ type: 'linkAnchor',
+ attrs: {
+ allAnchors: [{ href: `/doc/${target[Id]}`, title: 'Anchored Selection', anchorId: `${target[Id]}` }],
+ location: 'add:right',
+ title: 'Anchored Selection',
+ noPreview: true,
+ docref: false,
+ },
+ },
+ { type: 'pFontSize', attrs: { fontSize: '8px' } },
+ { type: 'em' },
+ ],
+ attrs: { fieldKey: 'text', docid: anchor[Id], hideKey: true, editable: false },
+ },
+ ],
+ },
+ { type: 'paragraph', attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null } },
+ ];
+ const metadatatext = {
+ type: 'paragraph',
+ attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null },
+ content: taggedContent,
+ };
+ if (taggedContent.length) textLines.push(metadatatext);
+ Doc.GetProto(target).text = new RichTextField(
+ JSON.stringify({
+ doc: {
+ type: 'doc',
+ content: textLines,
+ },
+ selection: { type: 'text', anchor: 4, head: 4 }, // set selection to middle paragraph
+ }),
+ ''
+ );
this.addDocument(target);
- this._stackRef.current?.focusDocument(target, {});
+ setTimeout(() => this._stackRef.current?.focusDocument(target, {}));
return target;
};
makeDocUnfiltered = (doc: Doc) => {
@@ -111,6 +170,11 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
docFilters = () => [...StrListCast(this.props.layoutDoc._docFilters), ...StrListCast(this.props.layoutDoc[this.filtersKey])];
showTitle = () => 'title';
setHeightCallback = (height: number) => this.props.setHeight?.(height + this.filtersHeight());
+ sortByLinkAnchorY = (a: Doc, b: Doc) => {
+ const ay = DocListCast(a.links).length && DocCast(DocListCast(a.links)[0].anchor1).y;
+ const by = DocListCast(b.links).length && DocCast(DocListCast(b.links)[0].anchor1).y;
+ return NumCast(ay) - NumCast(by);
+ };
render() {
const renderTag = (tag: string) => {
const active = StrListCast(this.props.rootDoc[this.filtersKey]).includes(`${tag}:${tag}:check`);
@@ -120,10 +184,10 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
</div>
);
};
- const renderMeta = (tag: string) => {
- const active = StrListCast(this.props.rootDoc[this.filtersKey]).includes(`${tag}:${tag}:exists`);
+ const renderMeta = (tag: string, dflt: FieldResult<Field>) => {
+ const active = StrListCast(this.props.rootDoc[this.filtersKey]).includes(`${tag}:${dflt}:exists`);
return (
- <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this.props.rootDoc, tag, tag, 'exists', true, this.sidebarKey, e.shiftKey)}>
+ <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this.props.rootDoc, tag, dflt, 'exists', true, this.sidebarKey, e.shiftKey)}>
{tag}
</div>
);
@@ -150,7 +214,9 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
}}>
<div className="sidebarAnnos-tagList" style={{ height: this.filtersHeight() }} onWheel={e => e.stopPropagation()}>
{this.allUsers.map(renderUsers)}
- {this.allMetadata.map(renderMeta)}
+ {Array.from(this.allMetadata.keys())
+ .sort()
+ .map(key => renderMeta(key, this.allMetadata.get(key)))}
</div>
<div style={{ width: '100%', height: `calc(100% - 38px)`, position: 'relative' }}>
<CollectionStackingView
@@ -162,6 +228,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
PanelWidth={this.panelWidth}
docFilters={this.docFilters}
scaleField={this.sidebarKey + '-scale'}
+ sortFunc={this.sortByLinkAnchorY}
setHeight={this.setHeightCallback}
isAnnotationOverlay={false}
select={emptyFunction}