aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index 6bea53355..8b0639b3b 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -4,7 +4,7 @@ import { Popup, PopupTrigger, Type } from 'browndash-components';
import { ObservableMap, action, computed, makeObservable, observable, observe, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-import { returnEmptyDoclist, returnEmptyString, returnFalse, returnIgnore, returnNever, returnTrue, setupMoveUpEvents, smoothScroll } from '../../../../ClientUtils';
+import { returnEmptyString, returnFalse, returnIgnore, returnNever, returnTrue, setupMoveUpEvents, smoothScroll } from '../../../../ClientUtils';
import { emptyFunction } from '../../../../Utils';
import { Doc, DocListCast, Field, FieldType, NumListCast, Opt, StrListCast } from '../../../../fields/Doc';
import { DocData } from '../../../../fields/DocSymbols';
@@ -22,12 +22,12 @@ import { ContextMenu } from '../../ContextMenu';
import { EditableView } from '../../EditableView';
import { ObservableReactComponent } from '../../ObservableReactComponent';
import { StyleProp } from '../../StyleProp';
-import { DefaultStyleProvider } from '../../StyleProvider';
+import { DefaultStyleProvider, returnEmptyDocViewList } from '../../StyleProvider';
import { Colors } from '../../global/globalEnums';
import { DocumentView } from '../../nodes/DocumentView';
import { FieldViewProps } from '../../nodes/FieldView';
import { FocusViewOptions } from '../../nodes/FocusViewOptions';
-import { CollectionSubView } from '../CollectionSubView';
+import { CollectionSubView, SubCollectionViewProps } from '../CollectionSubView';
import './CollectionSchemaView.scss';
import { SchemaColumnHeader } from './SchemaColumnHeader';
import { SchemaRowBox } from './SchemaRowBox';
@@ -49,14 +49,14 @@ const defaultColumnKeys: string[] = ['title', 'type', 'author', 'author_date', '
@observer
export class CollectionSchemaView extends CollectionSubView() {
- private _keysDisposer: any;
+ private _keysDisposer?: () => void;
private _previewRef: HTMLDivElement | null = null;
private _makeNewColumn: boolean = false;
private _documentOptions: DocumentOptions = new DocumentOptions();
private _tableContentRef: HTMLDivElement | null = null;
private _menuTarget = React.createRef<HTMLDivElement>();
- constructor(props: any) {
+ constructor(props: SubCollectionViewProps) {
super(props);
makeObservable(this);
}
@@ -76,7 +76,7 @@ export class CollectionSchemaView extends CollectionSubView() {
@observable _columnMenuIndex: number | undefined = undefined;
@observable _newFieldWarning: string = '';
@observable _makeNewField: boolean = false;
- @observable _newFieldDefault: any = 0;
+ @observable _newFieldDefault: boolean | number | string | undefined = 0;
@observable _newFieldType: ColumnType = ColumnType.Number;
@observable _menuValue: string = '';
@observable _filterColumnIndex: number | undefined = undefined;
@@ -161,11 +161,11 @@ export class CollectionSchemaView extends CollectionSubView() {
Object.entries(this._documentOptions).forEach((pair: [string, FInfo]) => this.fieldInfos.set(pair[0], pair[1]));
this._keysDisposer = observe(
this.dataDoc[this.fieldKey ?? 'data'] as List<Doc>,
- (change: any) => {
+ change => {
switch (change.type) {
case 'splice':
// prettier-ignore
- (change as any).added.forEach((doc: Doc) => // for each document added
+ change.added.filter(doc => doc instanceof Doc).map(doc => doc as Doc).forEach((doc: Doc) => // for each document added
Doc.GetAllPrototypes(doc.value as Doc).forEach(proto => // for all of its prototypes (and itself)
Object.keys(proto).forEach(action(key => // check if any of its keys are new, and add them
!this.fieldInfos.get(key) && this.fieldInfos.set(key, new FInfo("-no description-", key === 'author'))))));
@@ -270,7 +270,7 @@ export class CollectionSchemaView extends CollectionSubView() {
addRow = (doc: Doc | Doc[]) => this.addDocument(doc);
@undoBatch
- changeColumnKey = (index: number, newKey: string, defaultVal?: any) => {
+ changeColumnKey = (index: number, newKey: string, defaultVal?: string | number | boolean) => {
if (!this.documentKeys.includes(newKey)) {
this.addNewKey(newKey, defaultVal);
}
@@ -281,7 +281,7 @@ export class CollectionSchemaView extends CollectionSubView() {
};
@undoBatch
- addColumn = (key: string, defaultVal?: any) => {
+ addColumn = (key: string, defaultVal?: string | number | boolean) => {
if (!this.documentKeys.includes(key)) {
this.addNewKey(key, defaultVal);
}
@@ -298,7 +298,7 @@ export class CollectionSchemaView extends CollectionSubView() {
};
@action
- addNewKey = (key: string, defaultVal: any) =>
+ addNewKey = (key: string, defaultVal?: string | number | boolean) =>
this.childDocs.forEach(doc => {
doc[DocData][key] = defaultVal;
});
@@ -317,7 +317,7 @@ export class CollectionSchemaView extends CollectionSubView() {
};
@action
- startResize = (e: any, index: number) => {
+ startResize = (e: React.PointerEvent, index: number) => {
this._displayColumnWidths = this.storedColumnWidths;
setupMoveUpEvents(this, e, moveEv => this.resizeColumn(moveEv, index), this.finishResize, emptyFunction);
};
@@ -604,7 +604,7 @@ export class CollectionSchemaView extends CollectionSubView() {
};
scrollToDoc = (doc: Doc, options: FocusViewOptions) => {
- const found = this._tableContentRef && Array.from(this._tableContentRef.getElementsByClassName('documentView-node')).find((node: any) => node.id === doc[Id]);
+ const found = this._tableContentRef && Array.from(this._tableContentRef.getElementsByClassName('documentView-node')).find(node => node.id === doc[Id]);
if (found) {
const rect = found.getBoundingClientRect();
const localRect = this.ScreenToLocalBoxXf().transformBounds(rect.left, rect.top, rect.width, rect.height);
@@ -625,9 +625,9 @@ export class CollectionSchemaView extends CollectionSubView() {
type="number"
name=""
id=""
- value={this._newFieldDefault ?? 0}
+ value={Number(this._newFieldDefault ?? 0)}
onPointerDown={e => e.stopPropagation()}
- onChange={action((e: any) => {
+ onChange={action(e => {
this._newFieldDefault = e.target.value;
})}
/>
@@ -637,11 +637,9 @@ export class CollectionSchemaView extends CollectionSubView() {
<>
<input
type="checkbox"
- name=""
- id=""
- value={this._newFieldDefault}
+ value={this._newFieldDefault?.toString()}
onPointerDown={e => e.stopPropagation()}
- onChange={action((e: any) => {
+ onChange={action(e => {
this._newFieldDefault = e.target.checked;
})}
/>
@@ -654,9 +652,9 @@ export class CollectionSchemaView extends CollectionSubView() {
type="text"
name=""
id=""
- value={this._newFieldDefault ?? ''}
+ value={this._newFieldDefault?.toString() ?? ''}
onPointerDown={e => e.stopPropagation()}
- onChange={action((e: any) => {
+ onChange={action(e => {
this._newFieldDefault = e.target.value;
})}
/>
@@ -683,7 +681,7 @@ export class CollectionSchemaView extends CollectionSubView() {
};
@action
- setKey = (key: string, defaultVal?: any) => {
+ setKey = (key: string, defaultVal?: string | number | boolean) => {
if (this._makeNewColumn) {
this.addColumn(key, defaultVal);
} else {
@@ -856,16 +854,16 @@ export class CollectionSchemaView extends CollectionSubView() {
onKeysPassiveWheel = (e: WheelEvent) => {
// if scrollTop is 0, then don't let wheel trigger scroll on any container (which it would since onScroll won't be triggered on this)
- if (!this._oldKeysWheel.scrollTop && e.deltaY <= 0) e.preventDefault();
+ if (!this._oldKeysWheel?.scrollTop && e.deltaY <= 0) e.preventDefault();
e.stopPropagation();
};
- _oldKeysWheel: any;
+ _oldKeysWheel: HTMLDivElement | null = null;
@computed get keysDropdown() {
return (
<div className="schema-key-search">
<div
className="schema-column-menu-button"
- onPointerDown={action((e: any) => {
+ onPointerDown={action(e => {
e.stopPropagation();
this._makeNewField = true;
})}>
@@ -880,6 +878,7 @@ export class CollectionSchemaView extends CollectionSubView() {
}}>
{this._menuKeys.map(key => (
<div
+ key={key}
className="schema-search-result"
onPointerDown={e => {
e.stopPropagation();
@@ -962,7 +961,7 @@ export class CollectionSchemaView extends CollectionSubView() {
{this.renderFilterOptions}
<div
className="schema-column-menu-button"
- onPointerDown={action((e: any) => {
+ onPointerDown={action(e => {
e.stopPropagation();
this.closeFilterMenu();
})}>
@@ -1013,7 +1012,7 @@ export class CollectionSchemaView extends CollectionSubView() {
screenToLocal = () => this.ScreenToLocalBoxXf().translate(-this.tableWidth, 0);
previewWidthFunc = () => this.previewWidth;
onPassiveWheel = (e: WheelEvent) => e.stopPropagation();
- _oldWheel: any;
+ _oldWheel: HTMLDivElement | null = null;
render() {
return (
<div className="collectionSchemaView" ref={(ele: HTMLDivElement | null) => this.createDashEventsTarget(ele)} onDrop={this.onExternalDrop.bind(this)} onPointerMove={e => this.onPointerMove(e)}>
@@ -1112,7 +1111,7 @@ export class CollectionSchemaView extends CollectionSubView() {
childFiltersByRanges={this.childDocRangeFilters}
searchFilterDocs={this.searchFilterDocs}
styleProvider={DefaultStyleProvider}
- containerViewPath={returnEmptyDoclist}
+ containerViewPath={returnEmptyDocViewList}
moveDocument={this._props.moveDocument}
addDocument={this.addRow}
removeDocument={this._props.removeDocument}
@@ -1137,7 +1136,7 @@ interface CollectionSchemaViewDocProps {
@observer
class CollectionSchemaViewDoc extends ObservableReactComponent<CollectionSchemaViewDocProps> {
- constructor(props: any) {
+ constructor(props: CollectionSchemaViewDocProps) {
super(props);
makeObservable(this);
}