aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-11-15 10:30:43 -0500
committerbobzel <zzzman@gmail.com>2023-11-15 10:30:43 -0500
commit570e96292219a7c7c9fe496ba0606cc6b9f72abf (patch)
tree4231c09622b38ef4c39ce54bff7bbce448d7412e /src
parent20dba0dcdea12b6a6246973cb578ab5639316bfa (diff)
schema code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx119
-rw-r--r--src/client/views/collections/collectionSchema/SchemaRowBox.tsx11
2 files changed, 68 insertions, 62 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index 6b39b44f6..190e4ff2a 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -1,8 +1,7 @@
import React = require('react');
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { action, computed, observable, ObservableMap, observe, trace } from 'mobx';
+import { action, computed, observable, ObservableMap, observe } from 'mobx';
import { observer } from 'mobx-react';
-import { computedFn } from 'mobx-utils';
import { Doc, DocListCast, Field, NumListCast, Opt, StrListCast } from '../../../../fields/Doc';
import { Id } from '../../../../fields/FieldSymbols';
import { List } from '../../../../fields/List';
@@ -246,10 +245,7 @@ export class CollectionSchemaView extends CollectionSubView() {
this.layoutDoc.sortDesc = desc;
};
- addRow = (doc: Doc | Doc[]) => {
- const result: boolean = this.addDocument(doc);
- return result;
- };
+ addRow = (doc: Doc | Doc[]) => this.addDocument(doc);
@undoBatch
@action
@@ -560,9 +556,8 @@ export class CollectionSchemaView extends CollectionSubView() {
};
setColumnValues = (key: string, value: string) => {
- let success: boolean = true;
- this.childDocs.forEach(doc => success && KeyValueBox.SetField(doc, key, value));
- return success;
+ this.childDocs.forEach(doc => KeyValueBox.SetField(doc, key, value));
+ return true;
};
@action
@@ -587,9 +582,7 @@ export class CollectionSchemaView extends CollectionSubView() {
};
@action
- closeFilterMenu = () => {
- this._filterColumnIndex = undefined;
- };
+ closeFilterMenu = () => (this._filterColumnIndex = undefined);
openContextMenu = (x: number, y: number, index: number) => {
this.closeColumnMenu();
@@ -942,58 +935,68 @@ interface CollectionSchemaViewDocsProps {
@observer
class CollectionSchemaViewDocs extends React.Component<CollectionSchemaViewDocsProps> {
+ render() {
+ return (
+ <div className="schema-table-content" ref={this.props.setRef} style={{ height: `calc(100% - ${CollectionSchemaView._newNodeInputHeight + this.props.rowHeight()}px)` }}>
+ {this.props.childDocs().docs.map((doc: Doc, index: number) => (
+ <div className="schema-row-wrapper" style={{ height: this.props.rowHeight() }}>
+ <CollectionSchemaViewDoc doc={doc} schema={this.props.schema} index={index} rowHeight={this.props.rowHeight} />
+ </div>
+ ))}
+ </div>
+ );
+ }
+}
+
+interface CollectionSchemaViewDocProps {
+ schema: CollectionSchemaView;
+ index: number;
+ doc: Doc;
+ rowHeight: () => number;
+}
+
+@observer
+class CollectionSchemaViewDoc extends React.Component<CollectionSchemaViewDocProps> {
tableWidthFunc = () => this.props.schema.tableWidth;
+ screenToLocalXf = () => this.props.schema.props.ScreenToLocalTransform().translate(0, -this.props.rowHeight() - this.props.index * this.props.rowHeight());
noOpacityStyleProvider = (doc: Opt<Doc>, props: Opt<DocumentViewProps>, property: string) => {
- if (property === StyleProp.Opacity) {
- return 1;
- }
+ if (property === StyleProp.Opacity) return 1;
return DefaultStyleProvider(doc, props, property);
};
- childScreenToLocal = computedFn((index: number) => () => this.props.schema.props.ScreenToLocalTransform().translate(0, -this.props.rowHeight() - index * this.props.rowHeight()));
render() {
return (
- <div className="schema-table-content" ref={this.props.setRef} style={{ height: `calc(100% - ${CollectionSchemaView._newNodeInputHeight + this.props.rowHeight()}px)` }}>
- {this.props.childDocs().docs.map((doc: Doc, index: number) => {
- const dataDoc = !doc.isTemplateDoc && !doc.isTemplateForField ? undefined : this.props.schema.props.DataDoc;
- return (
- <div className="schema-row-wrapper" style={{ height: this.props.rowHeight() }}>
- <DocumentView
- key={doc[Id]}
- {...this.props.schema.props}
- LayoutTemplate={this.props.schema.props.childLayoutTemplate}
- LayoutTemplateString={SchemaRowBox.LayoutString(this.props.schema.props.fieldKey)}
- Document={doc}
- DataDoc={dataDoc}
- yPadding={index}
- renderDepth={this.props.schema.props.renderDepth + 1}
- PanelWidth={this.tableWidthFunc}
- PanelHeight={this.props.rowHeight}
- styleProvider={this.noOpacityStyleProvider}
- waitForDoubleClickToClick={returnNever}
- defaultDoubleClick={returnIgnore}
- dragAction="move"
- onClickScriptDisable="always"
- focus={this.props.schema.focusDocument}
- childFilters={this.props.schema.childDocFilters}
- childFiltersByRanges={this.props.schema.childDocRangeFilters}
- searchFilterDocs={this.props.schema.searchFilterDocs}
- rootSelected={this.props.schema.rootSelected}
- ScreenToLocalTransform={this.childScreenToLocal(index)}
- bringToFront={emptyFunction}
- dragWhenActive={true}
- isDocumentActive={this.props.schema.props.childDocumentsActive?.() ? this.props.schema.props.isDocumentActive : this.props.schema.isContentActive}
- isContentActive={emptyFunction}
- whenChildContentsActiveChanged={this.props.schema.props.whenChildContentsActiveChanged}
- hideDecorations={true}
- hideTitle={true}
- hideDocumentButtonBar={true}
- hideLinkAnchors={true}
- layout_fitWidth={returnTrue}
- />
- </div>
- );
- })}
- </div>
+ <DocumentView
+ key={this.props.doc[Id]}
+ {...this.props.schema.props}
+ LayoutTemplate={this.props.schema.props.childLayoutTemplate}
+ LayoutTemplateString={SchemaRowBox.LayoutString(this.props.schema.props.fieldKey, this.props.index)}
+ Document={this.props.doc}
+ DataDoc={undefined}
+ renderDepth={this.props.schema.props.renderDepth + 1}
+ PanelWidth={this.tableWidthFunc}
+ PanelHeight={this.props.rowHeight}
+ styleProvider={this.noOpacityStyleProvider}
+ waitForDoubleClickToClick={returnNever}
+ defaultDoubleClick={returnIgnore}
+ dragAction="move"
+ onClickScriptDisable="always"
+ focus={this.props.schema.focusDocument}
+ childFilters={this.props.schema.childDocFilters}
+ childFiltersByRanges={this.props.schema.childDocRangeFilters}
+ searchFilterDocs={this.props.schema.searchFilterDocs}
+ rootSelected={this.props.schema.rootSelected}
+ ScreenToLocalTransform={this.screenToLocalXf}
+ bringToFront={emptyFunction}
+ dragWhenActive={true}
+ isDocumentActive={this.props.schema.props.childDocumentsActive?.() ? this.props.schema.props.isDocumentActive : this.props.schema.isContentActive}
+ isContentActive={emptyFunction}
+ whenChildContentsActiveChanged={this.props.schema.props.whenChildContentsActiveChanged}
+ hideDecorations={true}
+ hideTitle={true}
+ hideDocumentButtonBar={true}
+ hideLinkAnchors={true}
+ layout_fitWidth={returnTrue}
+ />
);
}
}
diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
index ab27aac8f..7346c4f12 100644
--- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
@@ -20,10 +20,13 @@ import { CollectionSchemaView } from './CollectionSchemaView';
import './CollectionSchemaView.scss';
import { SchemaTableCell } from './SchemaTableCell';
+interface SchemaRowBoxProps {
+ rowIndex: number;
+}
@observer
-export class SchemaRowBox extends ViewBoxBaseComponent<FieldViewProps>() {
- public static LayoutString(fieldKey: string) {
- return FieldView.LayoutString(SchemaRowBox, fieldKey);
+export class SchemaRowBox extends ViewBoxBaseComponent<FieldViewProps & SchemaRowBoxProps>() {
+ public static LayoutString(fieldKey: string, rowIndex: number) {
+ return FieldView.LayoutString(SchemaRowBox, fieldKey).replace('fieldKey', `rowIndex={${rowIndex}} fieldKey`);
}
private _ref: HTMLDivElement | null = null;
@@ -169,7 +172,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<FieldViewProps>() {
transform={() => {
const ind = index === this.schemaView.columnKeys.length - 1 ? this.schemaView.columnKeys.length - 3 : index;
const x = this.schemaView?.displayColumnWidths.reduce((p, c, i) => (i <= ind ? p + c : p), 0);
- const y = (this.props.yPadding ?? 0) * this.props.PanelHeight();
+ const y = (this.props.rowIndex ?? 0) * this.props.PanelHeight();
return new Transform(x + CollectionSchemaView._rowMenuWidth, y, 1);
}}
/>