From 884e1f73f6a3ff47d286b13ff58166b62026cc18 Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Sun, 21 Jun 2020 19:46:01 -0500 Subject: changed to previews --- .../views/collections/CollectionSchemaCells.tsx | 54 +++++------------- .../views/collections/CollectionSchemaView.tsx | 66 +++++++++++++++++++++- 2 files changed, 79 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx index 30278db32..4231a3941 100644 --- a/src/client/views/collections/CollectionSchemaCells.tsx +++ b/src/client/views/collections/CollectionSchemaCells.tsx @@ -56,6 +56,7 @@ export interface CellProps { setPreviewDoc: (doc: Doc) => void; setComputed: (script: string, doc: Doc, field: string, row: number, col: number) => boolean; getField: (row: number, col?: number) => void; + showDoc: (doc: Doc | undefined, dataDoc?: any, screenX?: number, screenY?: number) => void; } @observer @@ -398,16 +399,18 @@ export class CollectionSchemaDocCell extends CollectionSchemaCell { } @action - showPreview = (bool: boolean) => { - console.log("show preview"); - this._preview = bool; - } - - getPreviewTransform = (): Transform => { - return this.prop.ScreenToLocalTransform().translate(- this.borderWidth - 4 - this.tableWidth, - this.borderWidth); + showPreview = (bool: boolean, e: any) => { + if (this._isEditing) { + this._preview = false; + } else { + if (bool) { + this.props.showDoc(this._doc, this.prop.DataDoc, e.screenX, e.screenY); + } else { + this.props.showDoc(undefined); + } + } } - render() { const dragRef: React.RefObject = React.createRef(); @@ -418,38 +421,9 @@ export class CollectionSchemaDocCell extends CollectionSchemaCell { return (
{ this.showPreview(true); }} - onPointerLeave={() => { this.showPreview(false); }}> - - {this._preview ?
false} - PanelWidth={() => 150} - PanelHeight={() => 150} - ScreenToLocalTransform={this.getPreviewTransform} - docFilters={returnEmptyFilter} - ContainingCollectionDoc={this.props.CollectionView?.props.Document} - ContainingCollectionView={this.props.CollectionView} - moveDocument={this.props.moveDocument} - parentActive={this.prop.active} - whenActiveChanged={this.prop.whenActiveChanged} - addDocTab={this.props.addDocTab} - pinToPres={this.props.pinToPres} - bringToFront={returnFalse} - ContentScaling={returnOne}> -
: null} + onPointerEnter={(e) => { this.showPreview(true, e); }} + onPointerLeave={(e) => { this.showPreview(false, e); }} + >
void; } + + + + + + + + @observer export class SchemaTable extends React.Component { private DIVIDER_WIDTH = 4; @@ -237,6 +246,10 @@ export class SchemaTable extends React.Component { @observable _focusedCell: { row: number, col: number } = { row: 0, col: 0 }; @observable _openCollections: Array = []; + @observable _showDoc: Doc | undefined; + @observable _showDataDoc: any = ""; + @observable _showDocPos: number[] = []; + @computed get previewWidth() { return () => NumCast(this.props.Document.schemaPreviewWidth); } @computed get previewHeight() { return () => this.props.PanelHeight() - 2 * this.borderWidth; } @computed get tableWidth() { return this.props.PanelWidth() - 2 * this.borderWidth - this.DIVIDER_WIDTH - this.previewWidth(); } @@ -349,6 +362,7 @@ export class SchemaTable extends React.Component { setPreviewDoc: this.props.setPreviewDoc, setComputed: this.setComputed, getField: this.getField, + showDoc: this.showDoc, }; const colType = this.getColumnType(col); @@ -756,8 +770,58 @@ export class SchemaTable extends React.Component { return false; } + + showDoc(doc: Doc | undefined, dataDoc?: Doc, screenX?: number, screenY?: number) { + this._showDoc = doc; + if (dataDoc && screenX && screenY) { + this._showDocPos = this.props.ScreenToLocalTransform().transformPoint(screenX, screenY); + } + } + + @action + onOpenClick = () => { + if (this._showDoc) { + this.props.addDocTab(this._showDoc, "onRight"); + } + } + + getPreviewTransform = (): Transform => { + return this.props.ScreenToLocalTransform().translate(- this.borderWidth - 4 - this.tableWidth, - this.borderWidth); + } + render() { + + const preview = ""; + return
this.props.active(true) && e.stopPropagation()} onDrop={e => this.props.onDrop(e, {})} onContextMenu={this.onContextMenu} > + {this._showDoc ?
{ this.onOpenClick(); }} style={{ + position: "absolute", transform: `translate(${this._showDocPos[0]}, ${this._showDocPos[1]})` + }} + ref="overlay"> false} + PanelWidth={() => 150} + PanelHeight={() => 150} + ScreenToLocalTransform={this.getPreviewTransform} + docFilters={returnEmptyFilter} + ContainingCollectionDoc={this.props.CollectionView?.props.Document} + ContainingCollectionView={this.props.CollectionView} + moveDocument={this.props.moveDocument} + parentActive={this.props.active} + whenActiveChanged={emptyFunction} + addDocTab={this.props.addDocTab} + pinToPres={this.props.pinToPres} + bringToFront={returnFalse} + ContentScaling={returnOne}> +
: null} {this.reactTable}
this.createRow()}>+ new
; -- cgit v1.2.3-70-g09d2