From d8feecd0542670233e6ea87006a89eb00d10a17e Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Thu, 18 Jun 2020 17:59:48 -0400 Subject: fixed keyvalue pane inputting new key values. made collection chromes shrink a little when window shrinks. --- src/client/views/nodes/KeyValueBox.tsx | 51 ++++++++++++++-------------------- 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'src/client/views/nodes/KeyValueBox.tsx') diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx index e983852ea..4442ee2eb 100644 --- a/src/client/views/nodes/KeyValueBox.tsx +++ b/src/client/views/nodes/KeyValueBox.tsx @@ -18,6 +18,7 @@ import { KeyValuePair } from "./KeyValuePair"; import React = require("react"); import { ContextMenu } from "../ContextMenu"; import { ContextMenuProps } from "../ContextMenuItem"; +import e = require("express"); export type KVPScript = { script: CompiledScript; @@ -31,10 +32,11 @@ export class KeyValueBox extends React.Component { private _mainCont = React.createRef(); private _keyHeader = React.createRef(); + private _keyInput = React.createRef(); + private _valInput = React.createRef(); @observable private rows: KeyValuePair[] = []; - @observable private _keyInput: string = ""; - @observable private _valueInput: string = ""; + @computed get splitPercentage() { return NumCast(this.props.Document.schemaSplitPercentage, 50); } get fieldDocToLayout() { return this.props.fieldKey ? Cast(this.props.Document[this.props.fieldKey], Doc, null) : this.props.Document; } @@ -42,10 +44,11 @@ export class KeyValueBox extends React.Component { onEnterKey = (e: React.KeyboardEvent): void => { if (e.key === 'Enter') { e.stopPropagation(); - if (this._keyInput && this._valueInput && this.fieldDocToLayout) { - if (KeyValueBox.SetField(this.fieldDocToLayout, this._keyInput, this._valueInput)) { - this._keyInput = ""; - this._valueInput = ""; + if (this._keyInput.current?.value && this._valInput.current?.value && this.fieldDocToLayout) { + if (KeyValueBox.SetField(this.fieldDocToLayout, this._keyInput.current.value, this._valInput.current.value)) { + this._keyInput.current.value = ""; + this._valInput.current.value = ""; + document.body.focus(); } } } @@ -103,7 +106,7 @@ export class KeyValueBox extends React.Component { rowHeight = () => 30; - createTable = () => { + @computed get createTable() { const doc = this.fieldDocToLayout; if (!doc) { return Loading...; @@ -136,29 +139,17 @@ export class KeyValueBox extends React.Component { } return rows; } - - @action - keyChanged = (e: React.ChangeEvent) => { - this._keyInput = e.currentTarget.value; + @computed get newKeyValue() { + return + { this._keyInput.current!.select(); e.stopPropagation(); }} style={{ width: `${100 - this.splitPercentage}%` }}> + + + { this._valInput.current!.select(); e.stopPropagation(); }} style={{ width: `${this.splitPercentage}%` }}> + + + } - @action - valueChanged = (e: React.ChangeEvent) => { - this._valueInput = e.currentTarget.value; - } - - newKeyValue = () => - ( - - - - - - - - - ) - @action onDividerMove = (e: PointerEvent): void => { const nativeWidth = this._mainCont.current!.getBoundingClientRect(); @@ -260,8 +251,8 @@ export class KeyValueBox extends React.Component { >Key Fields - {this.createTable()} - {this.newKeyValue()} + {this.createTable} + {this.newKeyValue} {dividerDragger} -- cgit v1.2.3-70-g09d2