From 6fd3cb1c766e47bd50b7b050f5d515006802d1a3 Mon Sep 17 00:00:00 2001 From: hensm Date: Tue, 23 Oct 2018 13:31:54 +0100 Subject: [PATCH] Whitelist editor localisation + formatting fixes --- ext/src/_locales/en/messages.json | 23 +++++++- ext/src/options/index.css | 8 ++- ext/src/options/index.jsx | 98 +++++++++++++++++-------------- 3 files changed, 84 insertions(+), 45 deletions(-) diff --git a/ext/src/_locales/en/messages.json b/ext/src/_locales/en/messages.json index c5dadf7..e2cb7d7 100755 --- a/ext/src/_locales/en/messages.json +++ b/ext/src/_locales/en/messages.json @@ -40,7 +40,28 @@ "message": "Enabled" } , "options_option_uaWhitelist": { - "message": "Match patterns (newline-separated)" + "message": "Match matterns (newline-separated)" + } + , "options_option_uaWhitelistBasicView": { + "message": "Basic View" + } + , "options_option_uaWhitelistRawView": { + "message": "Raw View" + } + , "options_option_uaWhitelistSaveRaw": { + "message": "Save Raw" + } + , "options_option_uaWhitelistAddItem": { + "message": "Add Item" + } + , "options_option_uaWhitelistItemEdit": { + "message": "Edit" + } + , "options_option_uaWhitelistItemRemove": { + "message": "Remove" + } + , "options_option_uaWhitelistInvalidMatchPattern": { + "message": "Invalid match pattern $1" } , "options_submit": { diff --git a/ext/src/options/index.css b/ext/src/options/index.css index 60464dc..10c9e03 100644 --- a/ext/src/options/index.css +++ b/ext/src/options/index.css @@ -45,6 +45,10 @@ .editable-list { justify-content: end; } +.editable-list__items { + display: flex; + flex-direction: column; +} .editable-list__item { align-items: center; display: flex; @@ -62,4 +66,6 @@ resize: vertical; width: 100%; } - +.editable-list__add-button { + align-self: end; +} diff --git a/ext/src/options/index.jsx b/ext/src/options/index.jsx index 8291a3e..39eb211 100644 --- a/ext/src/options/index.jsx +++ b/ext/src/options/index.jsx @@ -38,7 +38,7 @@ class EditableListItem extends React.Component { handleEditEnd (ev) { if (this.props.editing && !this.props.itemPattern.test(this.state.editValue)) { - ev.target.setCustomValidity(this.props.itemPatternError); + ev.target.setCustomValidity(this.props.itemPatternError()); } if (!ev.target.validity.valid) { @@ -58,7 +58,7 @@ class EditableListItem extends React.Component { }); if (!this.props.itemPattern.test(ev.target.value)) { - ev.target.setCustomValidity(this.props.itemPatternError); + ev.target.setCustomValidity(this.props.itemPatternError()); } else { ev.target.setCustomValidity(""); } @@ -74,22 +74,22 @@ class EditableListItem extends React.Component { return (
  • + onDoubleClick={ this.handleEditBegin }> { this.state.editing ? + value={ this.state.editValue } + onBlur={ this.handleEditEnd } + onChange={ this.handleInputChange } + onKeyPress={ this.handleInputKeyPress }/> : this.props.text }
    - -
  • ); @@ -155,6 +155,7 @@ class EditableList extends React.Component { handleSaveRaw () { this.setState(currentState => { + console.log(currentState.rawViewValue); const newItems = currentState.rawViewValue.split("\n") .filter(item => item !== ""); @@ -162,10 +163,12 @@ class EditableList extends React.Component { for (const item of newItems) { if (!this.props.itemPattern.test(item)) { this.rawViewTextArea.setCustomValidity( - `${this.props.itemPatternError}: ${item}`); + this.props.itemPatternError(item)); return; } - } + } + + this.rawViewTextArea.setCustomValidity(""); } return { @@ -213,42 +216,46 @@ class EditableList extends React.Component { return (
    { this.state.rawView && }
    { this.state.rawView ? ( ) : ( ) }
    @@ -269,6 +276,7 @@ class OptionsApp extends Component { this.handleFormChange = this.handleFormChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this); this.handleListChange = this.handleListChange.bind(this); + this.getItemPatternError = this.getItemPatternError.bind(this); } /** @@ -277,10 +285,10 @@ class OptionsApp extends Component { setStorage () { return browser.storage.sync.set({ options: { - option_localMediaEnabled : this.state.option_localMediaEnabled - , option_localMediaServerPort : this.state.option_localMediaServerPort - , option_uaWhitelistEnabled : this.state.option_uaWhitelistEnabled - , option_uaWhitelist : this.state.option_uaWhitelist + option_localMediaEnabled: this.state.option_localMediaEnabled + , option_localMediaServerPort: this.state.option_localMediaServerPort + , option_uaWhitelistEnabled: this.state.option_uaWhitelistEnabled + , option_uaWhitelist: this.state.option_uaWhitelist } }); } @@ -341,6 +349,10 @@ class OptionsApp extends Component { }); } + getItemPatternError (info) { + return _("options_option_uaWhitelistInvalidMatchPattern", info); + } + render () { return (
    { this.form = form; }} @@ -402,8 +414,8 @@ class OptionsApp extends Component { + itemPattern={ MATCH_PATTERN_REGEX } + itemPatternError={ this.getItemPatternError }/>