From 9f39b14b2e321e09d071ad1c5bf8e3978ff7f181 Mon Sep 17 00:00:00 2001
From: mehekj <mehek.jethani@gmail.com>
Date: Wed, 10 Aug 2022 19:33:19 -0400
Subject: basic selection complete

---
 .../collectionSchema/CollectionSchemaView.tsx      | 57 ++++++++++++++--------
 1 file changed, 36 insertions(+), 21 deletions(-)

(limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')

diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index 7e903ca92..20d809232 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -1,15 +1,14 @@
 import React = require('react');
+import { action, computed, observable, ObservableMap, ObservableSet } from 'mobx';
 import { observer } from 'mobx-react';
 import { Doc } from '../../../../fields/Doc';
+import { List } from '../../../../fields/List';
+import { listSpec } from '../../../../fields/Schema';
+import { Cast } from '../../../../fields/Types';
 import { CollectionSubView } from '../CollectionSubView';
 import './CollectionSchemaView.scss';
-import { SchemaRowBox } from './SchemaRowBox';
-import { action, computed, observable } from 'mobx';
-import { BoolCast, Cast, StrCast } from '../../../../fields/Types';
-import { listSpec } from '../../../../fields/Schema';
 import { SchemaColumnHeader } from './SchemaColumnHeader';
-import { List } from '../../../../fields/List';
-import { dropActionType } from '../../../util/DragManager';
+import { SchemaRowBox } from './SchemaRowBox';
 
 export enum ColumnType {
     Number,
@@ -23,11 +22,10 @@ const defaultColumnKeys: string[] = ['title', 'type', 'author', 'text', 'data',
 
 @observer
 export class CollectionSchemaView extends CollectionSubView() {
-    isChildContentActive = () => (this.props.isDocumentActive?.() && (this.props.childDocumentsActive?.() || BoolCast(this.rootDoc.childDocumentsActive)) ? true : undefined);
+    private _lastSelectedRow: number | undefined;
 
-    @computed get layoutDoc() {
-        return Doc.Layout(this.props.Document);
-    }
+    @observable _rowMenuWidth: number = 60;
+    @observable _selectedDocs: ObservableSet = new ObservableSet<Doc>();
 
     @computed get columnKeys() {
         return Cast(this.props.Document.columnKeys, listSpec('string'), defaultColumnKeys);
@@ -37,7 +35,7 @@ export class CollectionSchemaView extends CollectionSubView() {
         return Cast(
             this.props.Document.columnWidths,
             listSpec('number'),
-            this.columnKeys.map(() => (this.props.PanelWidth() - 100) / this.columnKeys.length)
+            this.columnKeys.map(() => (this.props.PanelWidth() - this._rowMenuWidth) / this.columnKeys.length)
         );
     }
 
@@ -49,6 +47,30 @@ export class CollectionSchemaView extends CollectionSubView() {
         return true;
     };
 
+    @action
+    selectRow = (doc: Doc, ctrl?: boolean, shift?: boolean) => {
+        if (shift && this._lastSelectedRow !== undefined) {
+            const currSelectedRow = this.childDocs.indexOf(doc);
+            const startRow = Math.min(this._lastSelectedRow, currSelectedRow);
+            const endRow = Math.max(this._lastSelectedRow, currSelectedRow);
+            for (let i = startRow; i <= endRow; i++) {
+                const currDoc = this.childDocs[i];
+                if (!this._selectedDocs.has(currDoc)) this._selectedDocs.add(currDoc);
+            }
+        } else if (ctrl) {
+            if (!this._selectedDocs.has(doc)) {
+                this._selectedDocs.add(doc);
+                this._lastSelectedRow = this.childDocs.indexOf(doc);
+            } else {
+                this._selectedDocs.delete(doc);
+            }
+        } else {
+            this._selectedDocs.clear();
+            this._selectedDocs.add(doc);
+            this._lastSelectedRow = this.childDocs.indexOf(doc);
+        }
+    };
+
     render() {
         return (
             <div className="collectionSchemaView">
@@ -63,17 +85,13 @@ export class CollectionSchemaView extends CollectionSubView() {
                             <SchemaRowBox
                                 {...this.props}
                                 Document={doc}
-                                renderDepth={this.props.renderDepth + 1}
-                                isContentActive={this.isChildContentActive}
-                                rootSelected={this.rootSelected}
-                                dropAction={StrCast(this.layoutDoc.childDropAction) as dropActionType}
-                                docFilters={this.childDocFilters}
-                                docRangeFilters={this.childDocRangeFilters}
-                                searchFilterDocs={this.searchFilterDocs}
                                 ContainingCollectionDoc={this.props.CollectionView?.props.Document}
                                 ContainingCollectionView={this.props.CollectionView}
                                 columnKeys={this.columnKeys}
                                 columnWidths={this.columnWidths}
+                                rowMenuWidth={this._rowMenuWidth}
+                                selectedRows={this._selectedDocs}
+                                selectRow={this.selectRow}
                             />
                         ))}
                     </div>
@@ -82,6 +100,3 @@ export class CollectionSchemaView extends CollectionSubView() {
         );
     }
 }
-function DocListCast(childDocs: Doc[]): any {
-    throw new Error('Function not implemented.');
-}
-- 
cgit v1.2.3-70-g09d2

