feat(ui): allow editing filters in place

This commit is contained in:
Łukasz Mierzwa
2018-07-19 23:38:11 +02:00
parent 299b6f436c
commit ad87e56bdd
4 changed files with 39 additions and 2 deletions
+9
View File
@@ -4,6 +4,15 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@attently/riek": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@attently/riek/-/riek-2.0.1.tgz",
"integrity": "sha1-AFJ4WlurHKepkjbxNWJNOeZhkCQ=",
"requires": {
"debug": "2.6.9",
"prop-types": "15.6.2"
}
},
"@fortawesome/fontawesome-common-types": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.1.tgz",
+1
View File
@@ -4,6 +4,7 @@
"license": "Apache-2.0",
"private": true,
"dependencies": {
"@attently/riek": "^2.0.1",
"@fortawesome/fontawesome-svg-core": "^1.2.0",
"@fortawesome/free-regular-svg-icons": "^5.1.0",
"@fortawesome/free-solid-svg-icons": "^5.1.0",
@@ -3,6 +3,8 @@ import PropTypes from "prop-types";
import { observer } from "mobx-react";
import { RIEInput } from "@attently/riek";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons/faExclamationCircle";
import { faSpinner } from "@fortawesome/free-solid-svg-icons/faSpinner";
@@ -28,6 +30,18 @@ const FilterInputLabel = observer(
})
};
onChange = update => {
const { alertStore, filter } = this.props;
// if filter is empty string then remove it
if (update.raw === "") {
alertStore.filters.removeFilter(filter.raw);
}
// if not empty replace it
alertStore.filters.replaceFilter(filter.raw, update.raw);
};
render() {
const { filter, alertStore } = this.props;
@@ -79,8 +93,13 @@ const FilterInputLabel = observer(
<FontAwesomeIcon icon={faExclamationCircle} />
</span>
)}
{filter.raw}
<RIEInput
defaultValue=""
value={filter.raw}
propName="raw"
change={this.onChange}
classEditing="py-0 border-0 bg-light"
/>
</span>
);
}
+8
View File
@@ -94,6 +94,13 @@ class AlertStore {
UpdateLocationSearch({ q: this.values.map(f => f.raw) });
}
},
replaceFilter(oldRaw, newRaw) {
const index = this.values.findIndex(e => e.raw === oldRaw);
if (index >= 0) {
this.values[index] = newUnappliedFilter(newRaw);
UpdateLocationSearch({ q: this.values.map(f => f.raw) });
}
},
setFilters(raws) {
this.values = raws.map(raw => newUnappliedFilter(raw));
UpdateLocationSearch({ q: this.values.map(f => f.raw) });
@@ -102,6 +109,7 @@ class AlertStore {
{
addFilter: action.bound,
removeFilter: action.bound,
replaceFilter: action.bound,
setFilters: action.bound
},
{ name: "API Filters" }