From 034ef2ad994a95786e37b9c9d28bdc7f8078ff8a Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 6 Sep 2018 20:59:49 -0400 Subject: [PATCH] Fixed: Various UI fixes Co-Authored-By: Mark McDowall --- .../Components/Form/TextTagInputConnector.js | 28 +++++++++++-------- frontend/src/Components/keyboardShortcuts.js | 4 ++- .../src/Utilities/Date/getRelativeDate.js | 12 ++++---- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/frontend/src/Components/Form/TextTagInputConnector.js b/frontend/src/Components/Form/TextTagInputConnector.js index 1019dff0b..a5e4fe3d9 100644 --- a/frontend/src/Components/Form/TextTagInputConnector.js +++ b/frontend/src/Components/Form/TextTagInputConnector.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; -import isString from 'Utilities/String/isString'; import split from 'Utilities/String/split'; import TagInput from './TagInput'; @@ -11,8 +10,7 @@ function createMapStateToProps() { return createSelector( (state, { value }) => value, (tags) => { - const isArray = !isString(tags); - const tagsArray = isArray ? tags :split(tags); + const tagsArray = Array.isArray(tags) ? tags : split(tags); return { tags: tagsArray.reduce((result, tag) => { @@ -25,7 +23,7 @@ function createMapStateToProps() { return result; }, []), - isArray + valueArray: tagsArray }; } ); @@ -39,13 +37,20 @@ class TextTagInputConnector extends Component { onTagAdd = (tag) => { const { name, - value, - isArray, + valueArray, onChange } = this.props; - const newValue = isArray ? [...value] : split(value); - newValue.push(tag.name); + // Split and trim tags before adding them to the list, this will + // cleanse tags pasted in that had commas and spaces which leads + // to oddities with restrictions (as an example). + + const newValue = [...valueArray]; + const newTags = split(tag.name); + + newTags.forEach((newTag) => { + newValue.push(newTag.trim()); + }); onChange({ name, value: newValue.join(',') }); } @@ -53,12 +58,11 @@ class TextTagInputConnector extends Component { onTagDelete = ({ index }) => { const { name, - value, - isArray, + valueArray, onChange } = this.props; - const newValue = isArray ? [...value] : split(value); + const newValue = [...valueArray]; newValue.splice(index, 1); onChange({ @@ -84,7 +88,7 @@ class TextTagInputConnector extends Component { TextTagInputConnector.propTypes = { name: PropTypes.string.isRequired, - value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), + valueArray: PropTypes.arrayOf(PropTypes.string).isRequired, isArray: PropTypes.bool.isRequired, onChange: PropTypes.func.isRequired }; diff --git a/frontend/src/Components/keyboardShortcuts.js b/frontend/src/Components/keyboardShortcuts.js index f9ef0c9e3..0e008e2ac 100644 --- a/frontend/src/Components/keyboardShortcuts.js +++ b/frontend/src/Components/keyboardShortcuts.js @@ -65,7 +65,9 @@ function keyboardShortcuts(WrappedComponent) { } stopCallback = (event, element, combo) => { - if (this._mousetrapBindings[combo].isGlobal) { + const binding = this._mousetrapBindings[combo]; + + if (!binding || binding.isGlobal) { return false; } diff --git a/frontend/src/Utilities/Date/getRelativeDate.js b/frontend/src/Utilities/Date/getRelativeDate.js index 0d5ab4f58..0a60135ce 100644 --- a/frontend/src/Utilities/Date/getRelativeDate.js +++ b/frontend/src/Utilities/Date/getRelativeDate.js @@ -10,6 +10,12 @@ function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, return null; } + const isTodayDate = isToday(date); + + if (isTodayDate && timeForToday && timeFormat) { + return formatTime(date, timeFormat, { includeMinuteZero: true, includeSeconds }); + } + if (!showRelativeDates) { return moment(date).format(shortDateFormat); } @@ -18,11 +24,7 @@ function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, return 'Yesterday'; } - if (isToday(date)) { - if (timeForToday && timeFormat) { - return formatTime(date, timeFormat, { includeMinuteZero: true, includeSeconds }); - } - + if (isTodayDate) { return 'Today'; }