aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/collections/collectionSchema/SchemaRowBox.tsx3
-rw-r--r--src/client/views/collections/collectionSchema/SchemaTableCell.tsx156
-rw-r--r--src/client/views/nodes/KeyValueBox.tsx2
3 files changed, 89 insertions, 72 deletions
diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
index 9772ce118..ca9e0bda0 100644
--- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
@@ -90,6 +90,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<FieldViewProps>() {
deselectCell = () => this.schemaView?.deselectCell();
selectedCell = () => this.schemaView?._selectedCell;
setColumnValues = (field: any, value: any) => this.schemaView?.setColumnValues(field, value) ?? false;
+ columnWidth = computedFn((index: number) => () => this.schemaView?.displayColumnWidths[index] ?? CollectionSchemaView._minColWidth);
render() {
return (
<div
@@ -131,7 +132,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<FieldViewProps>() {
Document={this.rootDoc}
col={index}
fieldKey={key}
- columnWidth={this.schemaView?.displayColumnWidths[index] ?? CollectionSchemaView._minColWidth}
+ columnWidth={this.columnWidth(index)}
isRowActive={this.props.isContentActive}
getFinfo={this.getFinfo}
selectCell={this.selectCell}
diff --git a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
index 4f4986b90..1fa4312e1 100644
--- a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
@@ -5,10 +5,13 @@ import { extname } from 'path';
import DatePicker from 'react-datepicker';
import { DateField } from '../../../../fields/DateField';
import { Doc, DocListCast, Field } from '../../../../fields/Doc';
-import { Cast, DateCast } from '../../../../fields/Types';
+import { BoolCast, Cast, DateCast } from '../../../../fields/Types';
import { ImageField } from '../../../../fields/URLField';
import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnZero, Utils } from '../../../../Utils';
+import { FInfo } from '../../../documents/Documents';
+import { dropActionType } from '../../../util/DragManager';
import { Transform } from '../../../util/Transform';
+import { undoBatch } from '../../../util/UndoManager';
import { EditableView } from '../../EditableView';
import { Colors } from '../../global/globalEnums';
import { FieldView, FieldViewProps } from '../../nodes/FieldView';
@@ -16,7 +19,6 @@ import { KeyValueBox } from '../../nodes/KeyValueBox';
import { DefaultStyleProvider } from '../../StyleProvider';
import { CollectionSchemaView, ColumnType, FInfotoColType } from './CollectionSchemaView';
import './CollectionSchemaView.scss';
-import { FInfo } from '../../../documents/Documents';
export interface SchemaTableCellProps {
Document: Doc;
@@ -25,7 +27,7 @@ export interface SchemaTableCellProps {
selectCell: (doc: Doc, col: number) => void;
selectedCell: () => [Doc, number] | undefined;
fieldKey: string;
- columnWidth: number;
+ columnWidth: () => number;
isRowActive: () => boolean | undefined;
getFinfo: (fieldKey: string) => FInfo | undefined;
setColumnValues: (field: string, value: string) => boolean;
@@ -33,95 +35,78 @@ export interface SchemaTableCellProps {
@observer
export class SchemaTableCell extends React.Component<SchemaTableCellProps> {
- private _editorRef: EditableView | null = null;
-
- @computed get readOnly() {
- return this.props.getFinfo(this.props.fieldKey)?.readOnly ?? false;
- }
-
- @computed get selected() {
- const selected: [Doc, number] | undefined = this.props.selectedCell();
- return this.props.isRowActive() && selected && selected[0] == this.props.Document && selected[1] == this.props.col;
+ public static colRowHeightFunc() {
+ return CollectionSchemaView._rowHeight;
}
-
- componentDidUpdate() {
- if (!this.selected) {
- this._editorRef?.setIsFocused(false);
- document.removeEventListener('keydown', this.onKeyDown);
- } else if (!this.readOnly) {
- document.addEventListener('keydown', this.onKeyDown);
- }
- }
-
- @action
- onKeyDown = (e: KeyboardEvent) => {
- e.stopPropagation();
- if (e.key == 'Enter') {
- this._editorRef?.setIsFocused(true);
- }
- if (e.key == 'Escape') {
- this.props.deselectCell();
+ public static renderProps(props: SchemaTableCellProps) {
+ const { Document, fieldKey, getFinfo, columnWidth, isRowActive } = props;
+ let protoCount = 0;
+ let doc: Doc | undefined = Document;
+ while (doc) {
+ if (Object.keys(doc).includes(fieldKey.replace(/^_/, ''))) {
+ break;
+ }
+ protoCount++;
+ doc = doc.proto;
}
- };
- colWidthFunc = () => this.props.columnWidth;
- colRowHeightFunc = () => CollectionSchemaView._rowHeight;
- @computed get defaultCellContent() {
- const props: FieldViewProps = {
- Document: this.props.Document,
+ const parenCount = Math.max(0, protoCount - 1);
+ const color = protoCount === 0 || (fieldKey.startsWith('_') && Document[fieldKey] === undefined) ? 'black' : 'blue';
+ const textDecoration = color !== 'black' && parenCount ? 'underline' : '';
+ const fieldProps: FieldViewProps = {
docFilters: returnEmptyFilter,
docRangeFilters: returnEmptyFilter,
searchFilterDocs: returnEmptyDoclist,
styleProvider: DefaultStyleProvider,
docViewPath: returnEmptyDoclist,
- fieldKey: this.props.fieldKey,
rootSelected: returnFalse,
isSelected: returnFalse,
setHeight: returnFalse,
select: emptyFunction,
- dropAction: 'alias',
+ dropAction: 'alias' as dropActionType,
bringToFront: emptyFunction,
renderDepth: 1,
isContentActive: returnFalse,
whenChildContentsActiveChanged: emptyFunction,
ScreenToLocalTransform: Transform.Identity,
focus: emptyFunction,
- PanelWidth: this.colWidthFunc,
- PanelHeight: this.colRowHeightFunc,
addDocTab: returnFalse,
pinToPres: returnZero,
+ Document,
+ fieldKey,
+ PanelWidth: columnWidth,
+ PanelHeight: SchemaTableCell.colRowHeightFunc,
};
- let protoCount = 0;
- let doc: Doc | undefined = this.props.Document;
- while (doc) {
- if (Object.keys(doc).includes(this.props.fieldKey.replace(/^_/, ''))) {
- break;
- }
- protoCount++;
- doc = doc.proto;
- }
- const parenCount = Math.max(0, protoCount - 1);
- const color = protoCount === 0 ? 'black' : 'blue';
+ const readOnly = getFinfo(fieldKey)?.readOnly ?? false;
+ const cursor = !readOnly ? 'text' : 'default';
+ const pointerEvents: 'all' | 'none' = !readOnly && isRowActive() ? 'all' : 'none';
+ return { color, textDecoration, fieldProps, cursor, pointerEvents };
+ }
+
+ @computed get selected() {
+ const selected: [Doc, number] | undefined = this.props.selectedCell();
+ return this.props.isRowActive() && selected?.[0] === this.props.Document && selected[1] === this.props.col;
+ }
+
+ @computed get defaultCellContent() {
+ const { color, textDecoration, fieldProps } = SchemaTableCell.renderProps(this.props);
return (
<div
className="schemacell-edit-wrapper"
style={{
color,
- textDecoration: parenCount ? 'underline' : undefined,
- cursor: !this.readOnly ? 'text' : 'default',
- pointerEvents: !this.readOnly && this.props.isRowActive() ? 'all' : 'none',
+ textDecoration,
}}>
<EditableView
- ref={ref => (this._editorRef = ref)}
- contents={<FieldView {...props} />}
+ contents={<FieldView {...fieldProps} />}
+ editing={this.selected ? undefined : false}
GetValue={() => Field.toKeyValueString(this.props.Document, this.props.fieldKey)}
- SetValue={(value: string, shiftDown?: boolean, enterKey?: boolean) => {
+ SetValue={undoBatch((value: string, shiftDown?: boolean, enterKey?: boolean) => {
if (shiftDown && enterKey) {
this.props.setColumnValues(this.props.fieldKey, value);
}
return KeyValueBox.SetField(this.props.Document, this.props.fieldKey, value);
- }}
- editing={this.selected ? undefined : false}
+ })}
/>
</div>
);
@@ -146,13 +131,12 @@ export class SchemaTableCell extends React.Component<SchemaTableCellProps> {
get content() {
const cellType: ColumnType = this.getCellType;
+ // prettier-ignore
switch (cellType) {
- case ColumnType.Image:
- return <SchemaImageCell {...this.props} />;
- case ColumnType.Date:
- // return <SchemaDateCell {...this.props} />;
- default:
- return this.defaultCellContent;
+ case ColumnType.Image: return <SchemaImageCell {...this.props} />;
+ case ColumnType.Boolean: return <SchemaBoolCell {...this.props} />;
+ case ColumnType.Date: // return <SchemaDateCell {...this.props} />;
+ default: return this.defaultCellContent;
}
}
@@ -160,10 +144,8 @@ export class SchemaTableCell extends React.Component<SchemaTableCellProps> {
return (
<div
className="schema-table-cell"
- onPointerDown={action(e => {
- if (!this.selected) this.props.selectCell(this.props.Document, this.props.col);
- })}
- style={{ width: this.props.columnWidth, border: this.selected ? `solid 2px ${Colors.MEDIUM_BLUE}` : undefined }}>
+ onPointerDown={action(e => !this.selected && this.props.selectCell(this.props.Document, this.props.col))}
+ style={{ width: this.props.columnWidth(), border: this.selected ? `solid 2px ${Colors.MEDIUM_BLUE}` : undefined }}>
{this.content}
</div>
);
@@ -257,3 +239,39 @@ export class SchemaDateCell extends React.Component<SchemaTableCellProps> {
return <DatePicker dateFormat={'Pp'} selected={this.date.date} onChange={(date: any) => this.handleChange(date)} />;
}
}
+@observer
+export class SchemaBoolCell extends React.Component<SchemaTableCellProps> {
+ @computed get selected() {
+ const selected: [Doc, number] | undefined = this.props.selectedCell();
+ return this.props.isRowActive() && selected?.[0] === this.props.Document && selected[1] === this.props.col;
+ }
+ render() {
+ const { color, textDecoration, fieldProps, cursor, pointerEvents } = SchemaTableCell.renderProps(this.props);
+ return (
+ <div className="schemaBoolCell" style={{ display: 'flex', color, textDecoration, cursor, pointerEvents }}>
+ <input
+ style={{ marginRight: 4 }}
+ type="checkbox"
+ checked={BoolCast(this.props.Document[this.props.fieldKey])}
+ onChange={undoBatch((value: React.ChangeEvent<HTMLInputElement> | undefined) => {
+ if ((value?.nativeEvent as any).shiftKey) {
+ this.props.setColumnValues(this.props.fieldKey, (color === 'black' ? '=' : '') + value?.target?.checked.toString());
+ }
+ KeyValueBox.SetField(this.props.Document, this.props.fieldKey.replace(/^_/, ''), (color === 'black' ? '=' : '') + value?.target?.checked.toString());
+ })}
+ />
+ <EditableView
+ contents={<FieldView {...fieldProps} />}
+ editing={this.selected ? undefined : false}
+ GetValue={() => (color === 'black' ? '=' : '') + Field.toKeyValueString(this.props.Document, this.props.fieldKey)}
+ SetValue={undoBatch((value: string, shiftDown?: boolean, enterKey?: boolean) => {
+ if (shiftDown && enterKey) {
+ this.props.setColumnValues(this.props.fieldKey, value);
+ }
+ return KeyValueBox.SetField(this.props.Document, this.props.fieldKey.replace(/^_/, ''), value);
+ })}
+ />
+ </div>
+ );
+ }
+}
diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx
index 57018fb93..11220c300 100644
--- a/src/client/views/nodes/KeyValueBox.tsx
+++ b/src/client/views/nodes/KeyValueBox.tsx
@@ -20,14 +20,12 @@ import { ImageBox } from './ImageBox';
import './KeyValueBox.scss';
import { KeyValuePair } from './KeyValuePair';
import React = require('react');
-import e = require('express');
export type KVPScript = {
script: CompiledScript;
type: 'computed' | 'script' | false;
onDelegate: boolean;
};
-
@observer
export class KeyValueBox extends React.Component<FieldViewProps> {
public static LayoutString() {