add support for tags with special chars

This commit is contained in:
or-else
2019-03-26 21:50:44 +03:00
parent 194306ac4f
commit 60fa6d7806
9 changed files with 53 additions and 54 deletions
+5
View File
@@ -1779,6 +1779,11 @@ ul.tabbar li.active > a:after {
font-size: 90%; font-size: 90%;
} }
.chip.invalid {
color: #c66;
background-color: #fee;
}
.chip > a { .chip > a {
display: inline-block; display: inline-block;
color: #ccc; color: #ccc;
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -118,6 +118,7 @@ export default class ChipInput extends React.Component {
noAvatar={this.props.avatarDisabled} noAvatar={this.props.avatarDisabled}
topic={item.user} topic={item.user}
required={item.user === this.props.required} required={item.user === this.props.required}
invalid={item.invalid}
index={count} index={count}
key={item.user} /> key={item.user} />
); );
+2 -1
View File
@@ -15,8 +15,9 @@ export default class Chip extends React.PureComponent {
render() { render() {
const title = this.props.title || this.props.topic; const title = this.props.title || this.props.topic;
const className = this.props.invalid ? 'chip invalid' : 'chip';
return ( return (
<div className="chip"> <div className={className}>
{this.props.noAvatar ? {this.props.noAvatar ?
<span className="spacer" /> : <span className="spacer" /> :
<div className="avatar-box"> <div className="avatar-box">
+25 -26
View File
@@ -38,32 +38,36 @@ export default class TagManager extends React.Component {
handleTagInput(text) { handleTagInput(text) {
this.setState({tagInput: text}); this.setState({tagInput: text});
// Check if user entered ',', ' ' or ';'
if (text.length > 0) { if (text.length > 0) {
var last = text[text.length-1]; const last = text[text.length-1];
if (last == ',' || last == ' ' || last == ';') { if (text[0] == '"') {
var tag = text.substr(0, text.length-1).trim(); // This is a quoted string.
if (tag.length >= MIN_TAG_LENGTH) { if (text.length > 1 && last == '"') {
this.handleAddTag(tag); this.handleAddTag(text.substring(1, text.length-1));
} }
} else if (last == ',' || last == ' ' || last == ';' || last == '"') {
// User entered ',', ' ' or ';'
this.handleAddTag(text.substring(0, text.length-1).trim());
} }
} }
} }
handleAddTag(tag) { handleAddTag(tag) {
tag = tag.trim();
if (tag.length > 0) { if (tag.length > 0) {
let tags = this.state.tags.slice(0); const tags = this.state.tags.slice(0);
tags.push(tag); tags.push(tag);
this.setState({tags: tags, tagInput: ''}); this.setState({tags: tags, tagInput: ''});
if (this.props.onTagsChanged) { if (this.props.onTagsChanged) {
this.props.onTagsChanged(tags); this.props.onTagsChanged(tags);
} }
return tags;
} }
return this.state.tags;
} }
handleRemoveTag(tag, index) { handleRemoveTag(tag, index) {
var tags = this.state.tags.slice(0); const tags = this.state.tags.slice(0);
tags.splice(index, 1); tags.splice(index, 1);
this.setState({tags: tags}); this.setState({tags: tags});
if (this.props.onTagsChanged) { if (this.props.onTagsChanged) {
@@ -72,16 +76,9 @@ export default class TagManager extends React.Component {
} }
handleSubmit() { handleSubmit() {
let tags = this.state.tags.slice(0); // Add unprocessed input to tags, submit the list.
let inp = this.state.tagInput.trim(); this.props.onSubmit(this.handleAddTag(this.state.tagInput.trim()));
if (inp.length > 0) { this.setState({activated: false, tags: this.props.tags});
tags.push(inp);
if (this.props.onTagsChanged) {
this.props.onTagsChanged(tags);
}
}
this.props.onSubmit(tags);
this.setState({activated: false, tagInput: '', tags: this.props.tags});
} }
handleCancel() { handleCancel() {
@@ -92,19 +89,21 @@ export default class TagManager extends React.Component {
} }
render() { render() {
var tags = []; let tags = [];
if (this.state.activated) { if (this.state.activated) {
this.state.tags.map(function(tag) { this.state.tags.map((tag) => {
tags.push({user: tag}); tags.push({user: tag, invalid: (tag.length < MIN_TAG_LENGTH)});
}); });
} else { } else {
this.state.tags.map(function(tag) { this.state.tags.map((tag) => {
tags.push(<span className="badge" key={tags.length}>{tag}</span>); tags.push(<span className="badge" key={tags.length}>{tag}</span>);
}); });
if (tags.length == 0) { if (tags.length == 0) {
tags = (<i> tags = (
<FormattedMessage id="tags_not_found" defaultMessage="No tags defined. Add some." description="" /> <i>
</i>); <FormattedMessage id="tags_not_found" defaultMessage="No tags defined. Add some." description="" />
</i>
);
} }
} }
return ( return (
+16 -23
View File
@@ -2029,7 +2029,7 @@ var InfoView = function (_React$Component) {
}, { }, {
key: "handleTagsUpdated", key: "handleTagsUpdated",
value: function handleTagsUpdated(tags) { value: function handleTagsUpdated(tags) {
if (!arrayEqual(this.state.tags.slice(0), tags.slice(0))) { if (!Object(_lib_utils_js__WEBPACK_IMPORTED_MODULE_15__["arrayEqual"])(this.state.tags.slice(0), tags.slice(0))) {
this.props.onTopicTagsUpdate(this.props.topic, tags); this.props.onTopicTagsUpdate(this.props.topic, tags);
} }
} }
@@ -6627,6 +6627,7 @@ var ChipInput = function (_React$Component) {
noAvatar: _this2.props.avatarDisabled, noAvatar: _this2.props.avatarDisabled,
topic: item.user, topic: item.user,
required: item.user === _this2.props.required, required: item.user === _this2.props.required,
invalid: item.invalid,
index: count, index: count,
key: item.user key: item.user
})); }));
@@ -6753,8 +6754,9 @@ var Chip = function (_React$PureComponent) {
key: "render", key: "render",
value: function render() { value: function render() {
var title = this.props.title || this.props.topic; var title = this.props.title || this.props.topic;
var className = this.props.invalid ? 'chip invalid' : 'chip';
return react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", { return react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", {
className: "chip" className: className
}, this.props.noAvatar ? react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("span", { }, this.props.noAvatar ? react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("span", {
className: "spacer" className: "spacer"
}) : react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", { }) : react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", {
@@ -10264,20 +10266,18 @@ var TagManager = function (_React$Component) {
if (text.length > 0) { if (text.length > 0) {
var last = text[text.length - 1]; var last = text[text.length - 1];
if (last == ',' || last == ' ' || last == ';') { if (text[0] == '"') {
var tag = text.substr(0, text.length - 1).trim(); if (text.length > 1 && last == '"') {
this.handleAddTag(text.substring(1, text.length - 1));
if (tag.length >= _config_js__WEBPACK_IMPORTED_MODULE_3__["MIN_TAG_LENGTH"]) {
this.handleAddTag(tag);
} }
} else if (last == ',' || last == ' ' || last == ';' || last == '"') {
this.handleAddTag(text.substring(0, text.length - 1).trim());
} }
} }
} }
}, { }, {
key: "handleAddTag", key: "handleAddTag",
value: function handleAddTag(tag) { value: function handleAddTag(tag) {
tag = tag.trim();
if (tag.length > 0) { if (tag.length > 0) {
var tags = this.state.tags.slice(0); var tags = this.state.tags.slice(0);
tags.push(tag); tags.push(tag);
@@ -10289,7 +10289,11 @@ var TagManager = function (_React$Component) {
if (this.props.onTagsChanged) { if (this.props.onTagsChanged) {
this.props.onTagsChanged(tags); this.props.onTagsChanged(tags);
} }
return tags;
} }
return this.state.tags;
} }
}, { }, {
key: "handleRemoveTag", key: "handleRemoveTag",
@@ -10307,21 +10311,9 @@ var TagManager = function (_React$Component) {
}, { }, {
key: "handleSubmit", key: "handleSubmit",
value: function handleSubmit() { value: function handleSubmit() {
var tags = this.state.tags.slice(0); this.props.onSubmit(this.handleAddTag(this.state.tagInput.trim()));
var inp = this.state.tagInput.trim();
if (inp.length > 0) {
tags.push(inp);
if (this.props.onTagsChanged) {
this.props.onTagsChanged(tags);
}
}
this.props.onSubmit(tags);
this.setState({ this.setState({
activated: false, activated: false,
tagInput: '',
tags: this.props.tags tags: this.props.tags
}); });
} }
@@ -10348,7 +10340,8 @@ var TagManager = function (_React$Component) {
if (this.state.activated) { if (this.state.activated) {
this.state.tags.map(function (tag) { this.state.tags.map(function (tag) {
tags.push({ tags.push({
user: tag user: tag,
invalid: tag.length < _config_js__WEBPACK_IMPORTED_MODULE_3__["MIN_TAG_LENGTH"]
}); });
}); });
} else { } else {
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long