aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionSchemaView.tsx
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-03-21 21:36:52 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-03-21 21:36:52 -0400
commitce4e7a03e82c71bd5c979b19308f4dba03be08a2 (patch)
tree3f1eb320790bd66cc128c8899c5ee9ed170d3382 /src/client/views/collections/CollectionSchemaView.tsx
parent27299e9666ec0aae6a4d1335fd30b2714ad67970 (diff)
parent1cf618563838f4ce7d8a98c8a0c8d94670bc4e18 (diff)
Merge branch 'master' of github-tsch-brown:browngraphicslab/Dash-Web into promises_and_user_document
Diffstat (limited to 'src/client/views/collections/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/CollectionSchemaView.tsx25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx
index b986f394c..34b019244 100644
--- a/src/client/views/collections/CollectionSchemaView.tsx
+++ b/src/client/views/collections/CollectionSchemaView.tsx
@@ -2,7 +2,7 @@ import React = require("react")
import { library } from '@fortawesome/fontawesome-svg-core';
import { faCog } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { action, computed, observable } from "mobx";
+import { action, computed, observable, trace, untracked } from "mobx";
import { observer } from "mobx-react";
import Measure from "react-measure";
import ReactTable, { CellInfo, ComponentPropsGetterR, ReactTableDefaults } from "react-table";
@@ -141,6 +141,7 @@ export class CollectionSchemaView extends CollectionViewBase {
};
}
+ @computed
get columns() {
return this.props.Document.GetList<Key>(KeyStore.ColumnsKey, []);
}
@@ -167,10 +168,19 @@ export class CollectionSchemaView extends CollectionViewBase {
this.props.Document.SetNumber(KeyStore.SchemaSplitPercentage, this.splitPercentage == 0 ? 33 : 0);
}
}
- findAllDocumentKeys = (): { [id: string]: boolean } => {
+
+ @computed
+ get findAllDocumentKeys(): { [id: string]: boolean } {
const docs = this.props.Document.GetList<Document>(this.props.fieldKey, []);
let keys: { [id: string]: boolean } = {}
- docs.map(doc => doc.GetAllPrototypes().map(proto => proto._proxies.forEach((val: any, key: string) => keys[key] = false)));
+ if (this._optionsActivated > -1) {
+ // bcz: ugh. this is untracked since otherwise a large collection of documents will blast the server for all their fields.
+ // then as each document's fields come back, we update the documents _proxies. Each time we do this, the whole schema will be
+ // invalidated and re-rendered. This workaround will inquire all of the document fields before the options button is clicked.
+ // then by the time the options button is clicked, all of the fields should be in place. If a new field is added while this menu
+ // is displayed (unlikely) it won't show up until something else changes.
+ untracked(() => docs.map(doc => doc.GetAllPrototypes().map(proto => proto._proxies.forEach((val: any, key: string) => keys[key] = false))));
+ }
this.columns.forEach(key => keys[key.Id] = true)
return keys;
}
@@ -228,13 +238,18 @@ export class CollectionSchemaView extends CollectionViewBase {
}
}
+ @observable _optionsActivated: number = 0;
+ @action
+ OptionsMenuDown = (e: React.PointerEvent) => {
+ this._optionsActivated++;
+ }
render() {
library.add(faCog);
const columns = this.columns;
const children = this.props.Document.GetList<Document>(this.props.fieldKey, []);
const selected = children.length > this._selectedIndex ? children[this._selectedIndex] : undefined;
//all the keys/columns that will be displayed in the schema
- const allKeys = this.findAllDocumentKeys();
+ const allKeys = this.findAllDocumentKeys;
let content = this._selectedIndex == -1 || !selected ? (null) : (
<Measure onResize={this.setScaling}>
{({ measureRef }) =>
@@ -274,7 +289,7 @@ export class CollectionSchemaView extends CollectionViewBase {
</div>
</div>
}>
- <button id="schemaOptionsMenuBtn"><FontAwesomeIcon style={{ color: "white" }} icon="cog" size="sm" /></button>
+ <button id="schemaOptionsMenuBtn" onPointerDown={this.OptionsMenuDown}><FontAwesomeIcon style={{ color: "white" }} icon="cog" size="sm" /></button>
</Flyout>);
return (