diff options
Diffstat (limited to 'src/client/views/MetadataEntryMenu.tsx')
-rw-r--r-- | src/client/views/MetadataEntryMenu.tsx | 119 |
1 files changed, 68 insertions, 51 deletions
diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx index 82ec5a5b3..bcbdd3ccb 100644 --- a/src/client/views/MetadataEntryMenu.tsx +++ b/src/client/views/MetadataEntryMenu.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import "./MetadataEntryMenu.scss"; +import './MetadataEntryMenu.scss'; import { observer } from 'mobx-react'; import { observable, action, runInAction, trace, computed, IReactionDisposer, reaction } from 'mobx'; import { KeyValueBox } from './nodes/KeyValueBox'; @@ -16,9 +16,9 @@ export interface MetadataEntryProps { } @observer -export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ - @observable private _currentKey: string = ""; - @observable private _currentValue: string = ""; +export class MetadataEntryMenu extends React.Component<MetadataEntryProps> { + @observable private _currentKey: string = ''; + @observable private _currentValue: string = ''; private _addChildren: boolean = false; @observable _allSuggestions: string[] = []; _suggestionDispser: IReactionDisposer | undefined; @@ -32,7 +32,7 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ if (!this.userModified) { this.previewValue(); } - } + }; previewValue = async () => { let field: Field | undefined | null = null; @@ -45,30 +45,30 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ if (field === null) { field = v; } else if (v !== field) { - value = "multiple values"; + value = 'multiple values'; } } if (value === undefined) { if (field !== null && field !== undefined) { - value = (onProto ? "" : "= ") + Field.toScriptString(field); + value = (onProto ? '' : '= ') + Field.toScriptString(field); } else { - value = ""; + value = ''; } } const s = value; - runInAction(() => this._currentValue = s); - } + runInAction(() => (this._currentValue = s)); + }; @action onValueChange = (e: React.ChangeEvent<HTMLInputElement>) => { this._currentValue = e.target.value; - this.userModified = e.target.value.trim() !== ""; - } + this.userModified = e.target.value.trim() !== ''; + }; @undoBatch @action onValueKeyDown = async (e: React.KeyboardEvent) => { - if (e.key === "Enter") { + if (e.key === 'Enter') { e.stopPropagation(); const script = KeyValueBox.CompileKVPScript(this._currentValue); if (!script) return; @@ -95,18 +95,18 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ this.clearInputs(); } } - } + }; @action clearInputs = () => { - this._currentKey = ""; - this._currentValue = ""; + this._currentKey = ''; + this._currentValue = ''; this.userModified = false; if (this.autosuggestRef.current) { const input: HTMLInputElement = (this.autosuggestRef.current as any).input; input && input.focus(); } - } + }; getKeySuggestions = (value: string) => { value = value.toLowerCase(); @@ -114,16 +114,18 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ const keys = new Set<string>(); docs.forEach(doc => Doc.allKeys(doc).forEach(key => keys.add(key))); return Array.from(keys).filter(key => key.toLowerCase().startsWith(value)); - } + }; getSuggestionValue = (suggestion: string) => suggestion; renderSuggestion = (suggestion: string) => { - return (null); - } + return null; + }; componentDidMount() { - this._suggestionDispser = reaction(() => this._currentKey, - () => this._allSuggestions = this.getKeySuggestions(this._currentKey), - { fireImmediately: true }); + this._suggestionDispser = reaction( + () => this._currentKey, + () => (this._allSuggestions = this.getKeySuggestions(this._currentKey)), + { fireImmediately: true } + ); } componentWillUnmount() { this._suggestionDispser && this._suggestionDispser(); @@ -131,49 +133,64 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ onClick = (e: React.ChangeEvent<HTMLInputElement>) => { this._addChildren = !this._addChildren; - } + }; private get considerChildOptions() { - if (!this.props.docs.every(doc => doc._viewType !== undefined)) { + if (!this.props.docs.every(doc => doc._type_collection !== undefined)) { return null; } return ( - <div style={{ display: "flex" }}> + <div style={{ display: 'flex' }}> Children: - <input type="checkbox" onChange={this.onClick} ></input> + <input type="checkbox" onChange={this.onClick}></input> </div> ); } _ref = React.createRef<HTMLInputElement>(); render() { - return (<div className="metadataEntry-outerDiv" id="metadataEntry-outer" onPointerDown={e => e.stopPropagation()}> - <div className="metadataEntry-inputArea"> - <div style={{ display: "flex", flexDirection: "row" }}> - <span>Key:</span> - <div className="metadataEntry-autoSuggester" onClick={e => this.autosuggestRef.current!.input?.focus()} > - <Autosuggest inputProps={{ value: this._currentKey, onChange: this.onKeyChange }} - getSuggestionValue={this.getSuggestionValue} - suggestions={emptyPath} - alwaysRenderSuggestions={false} - renderSuggestion={this.renderSuggestion} - onSuggestionsFetchRequested={emptyFunction} - onSuggestionsClearRequested={emptyFunction} - ref={this.autosuggestRef} /> + return ( + <div className="metadataEntry-outerDiv" id="metadataEntry-outer" onPointerDown={e => e.stopPropagation()}> + <div className="metadataEntry-inputArea"> + <div style={{ display: 'flex', flexDirection: 'row' }}> + <span>Key:</span> + <div className="metadataEntry-autoSuggester" onClick={e => this.autosuggestRef.current!.input?.focus()}> + <Autosuggest + inputProps={{ value: this._currentKey, onChange: this.onKeyChange }} + getSuggestionValue={this.getSuggestionValue} + suggestions={emptyPath} + alwaysRenderSuggestions={false} + renderSuggestion={this.renderSuggestion} + onSuggestionsFetchRequested={emptyFunction} + onSuggestionsClearRequested={emptyFunction} + ref={this.autosuggestRef} + /> + </div> </div> + <div style={{ display: 'flex', flexDirection: 'row' }}> + <span>Value:</span> + <input className="metadataEntry-input" ref={this._ref} value={this._currentValue} onClick={e => this._ref.current!.focus()} onChange={this.onValueChange} onKeyDown={this.onValueKeyDown} /> + </div> + {this.considerChildOptions} </div> - <div style={{ display: "flex", flexDirection: "row" }}> - <span>Value:</span> - <input className="metadataEntry-input" ref={this._ref} value={this._currentValue} onClick={e => this._ref.current!.focus()} onChange={this.onValueChange} onKeyDown={this.onValueKeyDown} /> + <div className="metadataEntry-keys"> + <ul> + {this._allSuggestions + .slice() + .sort() + .map(s => ( + <li + key={s} + onClick={action(() => { + this._currentKey = s; + this.previewValue(); + })}> + {s} + </li> + ))} + </ul> </div> - {this.considerChildOptions} - </div> - <div className="metadataEntry-keys" > - <ul> - {this._allSuggestions.slice().sort().map(s => <li key={s} onClick={action(() => { this._currentKey = s; this.previewValue(); })} >{s}</li>)} - </ul> </div> - </div> ); } -}
\ No newline at end of file +} |