diff options
| author | mehekj <mehek.jethani@gmail.com> | 2022-11-21 12:38:37 -0500 |
|---|---|---|
| committer | mehekj <mehek.jethani@gmail.com> | 2022-11-21 12:38:37 -0500 |
| commit | 73d3c63658c4bdf3268ea81a02eb96566869b855 (patch) | |
| tree | d59e63d7e22a093f2cb3cc1b734bbb0aadd69ee9 /src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx | |
| parent | a58e71a9eea2717151e1a8c73e27068b02256390 (diff) | |
column deletion and new key menu fixes
Diffstat (limited to 'src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx')
| -rw-r--r-- | src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx index b9e25a473..a6a5f66ab 100644 --- a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx +++ b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx @@ -15,7 +15,7 @@ export interface SchemaColumnHeaderProps { addColumn: (index: number, key: string, defaultVal?: any) => void; removeColumn: (index: number) => void; resizeColumn: (e: any, index: number, left: boolean) => void; - dragColumn: (e: any, index: number) => boolean; + // dragColumn: (e: any, index: number) => boolean; } @observer @@ -24,6 +24,7 @@ export class SchemaColumnHeader extends React.Component<SchemaColumnHeaderProps> @observable _makeNewField: boolean = false; @observable _newFieldType: ColumnType = ColumnType.Number; @observable _newFieldDefault: any = 0; + @observable _newFieldWarning: string = ''; @observable _menuValue: string = ''; @observable _menuOptions: string[] = []; private _makeNewColumn = false; @@ -94,11 +95,17 @@ export class SchemaColumnHeader extends React.Component<SchemaColumnHeaderProps> string </div> <div className="schema-key-default-val">value: {this.fieldDefaultInput}</div> + <div className="schema-key-warning">{this._newFieldWarning}</div> <div className="schema-column-menu-button" onPointerDown={action(e => { - this.setKey(this._menuValue, this._newFieldDefault); - this._makeNewField = false; + if (this.props.possibleKeys.includes(this._menuValue)) { + this._newFieldWarning = 'Field already exists'; + } else if (this._menuValue.length === 0) { + this._newFieldWarning = 'Field cannot be an empty string'; + } else { + this.setKey(this._menuValue, this._newFieldDefault); + } })}> done </div> @@ -134,7 +141,7 @@ export class SchemaColumnHeader extends React.Component<SchemaColumnHeaderProps> onSearchKeyDown = (e: React.KeyboardEvent) => { switch (e.key) { case 'Enter': - this.setKey(this._menuOptions.length > 0 ? this._menuOptions[0] : this._menuValue); + this.setKey(this._menuOptions.length > 0 && this._menuValue.length > 0 ? this._menuOptions[0] : this._menuValue); break; case 'Escape': this.toggleColumnMenu(); @@ -158,12 +165,12 @@ export class SchemaColumnHeader extends React.Component<SchemaColumnHeaderProps> this._menuOptions = this.props.possibleKeys.filter(value => value.toLowerCase().includes(this._menuValue.toLowerCase())); }; - @action - onPointerDown = (e: React.PointerEvent) => { - e.stopPropagation(); + // @action + // onPointerDown = (e: React.PointerEvent) => { + // e.stopPropagation(); - setupMoveUpEvents(this, e, e => this.props.dragColumn(e, this.props.columnIndex), emptyFunction, emptyFunction); - }; + // setupMoveUpEvents(this, e, e => this.props.dragColumn(e, this.props.columnIndex), emptyFunction, emptyFunction); + // }; @action toggleColumnMenu = (newCol?: boolean) => { @@ -172,9 +179,11 @@ export class SchemaColumnHeader extends React.Component<SchemaColumnHeaderProps> this._menuVisible = false; } else { this._menuVisible = true; - this._menuValue = this.fieldKey; + this._menuValue = ''; this._menuOptions = this.props.possibleKeys; this._makeNewField = false; + this._newFieldWarning = ''; + this._makeNewField = false; if (newCol) { this._makeNewColumn = true; } @@ -183,7 +192,7 @@ export class SchemaColumnHeader extends React.Component<SchemaColumnHeaderProps> render() { return ( - <div className="schema-column-header" style={{ width: this.props.columnWidths[this.props.columnIndex] }} onPointerDown={this.onPointerDown}> + <div className="schema-column-header" style={{ width: this.props.columnWidths[this.props.columnIndex] }}> <div className="schema-column-resizer left" onPointerDown={e => this.props.resizeColumn(e, this.props.columnIndex, true)}></div> <div className="schema-column-title">{this.fieldKey}</div> |
