From 61ce7b4d434aff7e642d2af17b8643297f99e4a3 Mon Sep 17 00:00:00 2001 From: mehekj Date: Wed, 15 Mar 2023 18:15:18 -0400 Subject: column drag in progress --- .../collectionSchema/CollectionSchemaView.scss | 112 +++++++++++---------- .../collectionSchema/CollectionSchemaView.tsx | 40 ++++---- .../collectionSchema/SchemaColumnHeader.tsx | 21 ++-- .../collectionSchema/SchemaTableCell.tsx | 16 +-- 4 files changed, 103 insertions(+), 86 deletions(-) (limited to 'src/client/views/collections') diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.scss b/src/client/views/collections/collectionSchema/CollectionSchemaView.scss index 5eb5cc86d..1853fb589 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.scss +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.scss @@ -8,6 +8,7 @@ .schema-table { background-color: $white; + cursor: default; .schema-column-menu, .schema-filter-menu { @@ -80,68 +81,70 @@ align-self: center; } } + } - .schema-header-row { - justify-content: flex-end; + .schema-preview-divider { + height: 100%; + background: black; + cursor: ew-resize; + } +} - .row-menu { - display: flex; - justify-content: flex-end; - } +.schema-header-row { + cursor: grab; + justify-content: flex-end; - .schema-column-header { - font-weight: bold; - display: flex; - flex-direction: row; - justify-content: space-between; - align-items: center; - padding: 0; - z-index: 1; - - .schema-column-title { - flex-grow: 2; - margin: 5px; - } + .row-menu { + display: flex; + justify-content: flex-end; + } +} - .schema-header-menu { - margin: 5px; - } +.schema-column-header { + background-color: $light-gray; + font-weight: bold; + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + padding: 0; + z-index: 1; - .schema-column-resizer { - height: 100%; - width: 3px; - cursor: ew-resize; + .schema-column-title { + flex-grow: 2; + margin: 5px; + } - &:hover { - background-color: $light-blue; - } - } + .schema-header-menu { + margin: 5px; + } - .schema-column-resizer.right { - margin-left: 5px; - align-self: flex-end; - } + .schema-column-resizer { + height: 100%; + width: 3px; + cursor: ew-resize; - .schema-column-resizer.left { - margin-right: 5px; - align-self: flex-start; - } - } + &:hover { + background-color: $light-blue; } + } - .schema-header-menu { - display: flex; - flex-direction: row; - } + .schema-column-resizer.right { + margin-left: 5px; + align-self: flex-end; } - .schema-preview-divider { - height: 100%; - background: black; - cursor: ew-resize; + .schema-column-resizer.left { + margin-right: 5px; + align-self: flex-start; } } +.schema-header-menu { + display: flex; + flex-direction: row; +} + .schema-row-wrapper { // max-height: 70px; overflow: hidden; @@ -158,17 +161,18 @@ height: 100%; // max-height: 70px; overflow: auto; +} - .schema-column-header, - .schema-table-cell, - .row-menu { - border: 1px solid $medium-gray; - padding: 5px; - overflow: hidden; - } +.schema-column-header, +.schema-table-cell, +.row-menu { + border: 1px solid $medium-gray; + padding: 5px; + overflow: hidden; } .schema-row { + cursor: default; justify-content: flex-end; background: white; diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index e1c2d989f..b0114a226 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -54,6 +54,7 @@ export class CollectionSchemaView extends CollectionSubView() { @observable _lastSelectedRow: number | undefined; @observable _selectedDocs: ObservableSet = new ObservableSet(); @observable _rowEles: ObservableMap = new ObservableMap(); + @observable _colEles: HTMLDivElement[] = []; @observable _isDragging: boolean = false; @observable _displayColumnWidths: number[] | undefined; @observable _columnMenuIndex: number | undefined; @@ -301,29 +302,32 @@ export class CollectionSchemaView extends CollectionSubView() { this.layoutDoc.columnWidths = new List(currWidths); }; - // @action - // dragColumn = (e: any, index: number) => { - // e.stopPropagation(); - // e.preventDefault(); - // const rect = e.target.getBoundingClientRect(); - // if (e.clientX < rect.x) { - // if (index < 1) return true; - // this.swapColumns(index - 1, index); - // return true; - // } - // if (e.clientX > rect.x + rect.width) { - // if (index === this.columnKeys.length) return true; - // this.swapColumns(index, index + 1); - // return true; - // } - // return false; - // }; + @action + dragColumn = (e: PointerEvent, index: number) => { + const dragData = new DragManager.ColumnDragData(index); + const dragEles = [this._colEles[index]]; + this.childDocs.forEach(doc => { + dragEles.push(this._rowEles.get(doc).children[1].children[index]); + }); + DragManager.StartColumnDrag(dragEles, dragData, e.x, e.y); + + return true; + }; @action addRowRef = (doc: Doc, ref: HTMLDivElement) => { this._rowEles.set(doc, ref); }; + @action + setColRef = (index: number, ref: HTMLDivElement) => { + if (this._colEles.length <= index) { + this._colEles.push(ref); + } else { + this._colEles[index] = ref; + } + }; + @action addDocToSelection = (doc: Doc, extendSelection: boolean, index: number) => { this._selectedDocs.add(doc); @@ -842,6 +846,8 @@ export class CollectionSchemaView extends CollectionSubView() { removeColumn={this.removeColumn} resizeColumn={this.startResize} openContextMenu={this.openContextMenu} + dragColumn={this.dragColumn} + setColRef={this.setColRef} /> ); })} diff --git a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx index 42626697a..e648356f4 100644 --- a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx +++ b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx @@ -26,8 +26,9 @@ export interface SchemaColumnHeaderProps { setSort: (field: string, desc: boolean) => void; removeColumn: (index: number) => void; resizeColumn: (e: any, index: number, left: boolean) => void; - // dragColumn: (e: any, index: number) => boolean; + dragColumn: (e: any, index: number) => boolean; openContextMenu: (x: number, y: number, index: number) => void; + setColRef: (index: number, ref: HTMLDivElement) => void; } @observer @@ -47,16 +48,20 @@ export class SchemaColumnHeader extends React.Component } }; - // @action - // onPointerDown = (e: React.PointerEvent) => { - // e.stopPropagation(); - - // setupMoveUpEvents(this, e, e => this.props.dragColumn(e, this.props.columnIndex), emptyFunction, emptyFunction); - // }; + @action + onPointerDown = (e: React.PointerEvent) => { + setupMoveUpEvents(this, e, e => this.props.dragColumn(e, this.props.columnIndex), emptyFunction, emptyFunction); + }; render() { return ( -
+
{ + col && this.props.setColRef(this.props.columnIndex, col); + }}>
this.props.resizeColumn(e, this.props.columnIndex, true)}>
{this.fieldKey}
diff --git a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx index 43b7da544..91b292b28 100644 --- a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx +++ b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx @@ -48,13 +48,15 @@ export class SchemaTableCell extends React.Component { }; return ( -
- } - height={'auto'} - GetValue={() => Field.toKeyValueString(this.props.Document, this.props.fieldKey)} - SetValue={(value: string) => KeyValueBox.SetField(this.props.Document, this.props.fieldKey, value)} - /> +
+
+ } + GetValue={() => Field.toKeyValueString(this.props.Document, this.props.fieldKey)} + SetValue={(value: string) => KeyValueBox.SetField(this.props.Document, this.props.fieldKey, value)} + editing={this.props.isRowActive() ? undefined : false} + /> +
); } -- cgit v1.2.3-70-g09d2