diff options
author | Lionel Han <47760119+IGoByJoe@users.noreply.github.com> | 2020-09-09 22:18:39 -0700 |
---|---|---|
committer | Lionel Han <47760119+IGoByJoe@users.noreply.github.com> | 2020-09-09 22:18:39 -0700 |
commit | 1b8eb5a59edfcef36e8f6450aca82de46d2044eb (patch) | |
tree | e9f4aaaa27c71ca51fca9ee18af00d88b827574c /src/client/views/collections/CollectionView.tsx | |
parent | e641fd8c6f5a84800af173db02bd012eecb04b7a (diff) | |
parent | 5a4dad460f611cb8138faf08796dda4763f4daf4 (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into bug_fixes
Diffstat (limited to 'src/client/views/collections/CollectionView.tsx')
-rw-r--r-- | src/client/views/collections/CollectionView.tsx | 49 |
1 files changed, 7 insertions, 42 deletions
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index ba8e23447..6939399e6 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -71,10 +71,9 @@ export enum CollectionViewType { } export interface CollectionViewCustomProps { filterAddDocument?: (doc: Doc | Doc[]) => boolean; // allows a document that renders a Collection view to filter or modify any documents added to the collection (see PresBox for an example) - childLayoutTemplate?: () => Opt<Doc>; // specify a layout Doc template to use for children of the collection - childLayoutString?: string; // specify a layout string to use for children of the collection childOpacity?: () => number; hideFilter?: true; + childIgnoreNativeSize?: boolean; } export interface CollectionRenderProps { @@ -85,8 +84,8 @@ export interface CollectionRenderProps { whenActiveChanged: (isActive: boolean) => void; PanelWidth: () => number; PanelHeight: () => number; - ChildLayoutTemplate?: () => Doc; - ChildLayoutString?: string; + ChildLayoutTemplate?: () => Doc;// specify a layout Doc template to use for children of the collection + ChildLayoutString?: string;// specify a layout string to use for children of the collection } @observer @@ -244,7 +243,8 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus } screenToLocalTransform = () => this.props.renderDepth ? this.props.ScreenToLocalTransform() : this.props.ScreenToLocalTransform().scale(this.props.PanelWidth() / this.bodyPanelWidth()); - private SubViewHelper = (type: CollectionViewType, renderProps: CollectionRenderProps) => { + private SubView = (type: CollectionViewType, renderProps: CollectionRenderProps) => { + TraceMobx(); const props: SubCollectionViewProps = { ...this.props, ...renderProps, ScreenToLocalTransform: this.screenToLocalTransform, CollectionView: this, annotationsKey: "" }; switch (type) { case CollectionViewType.Schema: return (<CollectionSchemaView key="collview" {...props} />); @@ -263,14 +263,10 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus case CollectionViewType.Map: return (<CollectionMapView key="collview" {...props} />); case CollectionViewType.Grid: return (<CollectionGridView key="gridview" {...props} />); case CollectionViewType.Freeform: - default: { this.props.Document._freeformLayoutEngine = undefined; return (<CollectionFreeFormView key="collview" {...props} />); } + default: { this.props.Document._freeformLayoutEngine = undefined; return (<CollectionFreeFormView key="collview" {...props} ChildLayoutString={props.ChildLayoutString} />); } } } - private SubView = (type: CollectionViewType, renderProps: CollectionRenderProps) => { - return this.SubViewHelper(type, renderProps); - } - setupViewTypes(category: string, func: (viewType: CollectionViewType) => Doc, addExtras: boolean) { const subItems: ContextMenuProps[] = []; @@ -372,37 +368,6 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus bodyPanelWidth = () => this.props.PanelWidth(); facetWidth = () => Math.max(0, Math.min(this.props.PanelWidth() - 25, this._facetWidth)); - - @computed get dataDoc() { - return (this.props.DataDoc && this.props.Document.isTemplateForField ? Doc.GetProto(this.props.DataDoc) : - this.props.Document.resolvedDataDoc ? this.props.Document : Doc.GetProto(this.props.Document)); // if the layout document has a resolvedDataDoc, then we don't want to get its parent which would be the unexpanded template - } - // The data field for rendering this collection will be on the this.props.Document unless we're rendering a template in which case we try to use props.DataDoc. - // When a document has a DataDoc but it's not a template, then it contains its own rendering data, but needs to pass the DataDoc through - // to its children which may be templates. - // If 'annotationField' is specified, then all children exist on that field of the extension document, otherwise, they exist directly on the data document under 'fieldKey' - @computed get dataField() { - return this.dataDoc[this.props.fieldKey]; - } - - get childLayoutPairs(): { layout: Doc; data: Doc; }[] { - const { Document, DataDoc } = this.props; - const validPairs = this.childDocs.map(doc => Doc.GetLayoutDataDocPair(Document, DataDoc, doc)).filter(pair => pair.layout); - return validPairs.map(({ data, layout }) => ({ data: data as Doc, layout: layout! })); // this mapping is a bit of a hack to coerce types - } - - get childDocList() { - return Cast(this.dataField, listSpec(Doc)); - } - - get childDocs() { - const dfield = this.dataField; - const rawdocs = (dfield instanceof Doc) ? [dfield] : Cast(dfield, listSpec(Doc), Cast(this.props.Document.rootDocument, Doc, null) ? [Cast(this.props.Document.rootDocument, Doc, null)] : []); - const docs = rawdocs.filter(d => d && !(d instanceof Promise)).map(d => d as Doc); - const viewSpecScript = ScriptCast(this.props.Document.viewSpecScript); - return viewSpecScript ? docs.filter(d => viewSpecScript.script.run({ doc: d }, console.log).result) : docs; - } - onPointerDown = (e: React.PointerEvent) => { setupMoveUpEvents(this, e, action((e: PointerEvent, down: number[], delta: number[]) => { this._facetWidth = this.props.PanelWidth() - Math.max(this.props.ScreenToLocalTransform().transformPoint(e.clientX, 0)[0], 0); @@ -411,7 +376,7 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus } childLayoutTemplate = () => this.props.childLayoutTemplate?.() || Cast(this.props.Document.childLayoutTemplate, Doc, null); - childLayoutString = this.props.childLayoutString || StrCast(this.props.Document.childLayoutString); + @computed get childLayoutString() { return StrCast(this.props.Document.childLayoutString); } render() { TraceMobx(); |