fix(instances): search only by visible attrs

This commit is contained in:
Sérgio Ramos 2018-02-28 12:26:40 +00:00 committed by Sérgio Ramos
parent ce232b7d6a
commit 577df6d187
4 changed files with 30 additions and 14 deletions

View File

@ -197,7 +197,7 @@ export default compose(
})); }));
const index = new Fuse(instances, { const index = new Fuse(instances, {
keys: instances.length ? Object.keys(instances[0]) : ['name'] keys: ['id', 'name', 'status', 'created']
}); });
return { return {

View File

@ -10,6 +10,7 @@ import find from 'lodash.find';
import get from 'lodash.get'; import get from 'lodash.get';
import intercept from 'apr-intercept'; import intercept from 'apr-intercept';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
import Fuse from 'fuse.js';
import { import {
ViewContainer, ViewContainer,
@ -170,7 +171,8 @@ export default compose(
({ name = '' }) => name !== 'user-script' ({ name = '' }) => name !== 'user-script'
); );
const metadata = values.map(({ name, value }) => ({ const metadata = values.map(({ id, name, value }) => ({
id,
form: METADATA_FORM_KEY(name), form: METADATA_FORM_KEY(name),
initialValues: { initialValues: {
name, name,
@ -178,7 +180,12 @@ export default compose(
} }
})); }));
const index = new Fuse(values, {
keys: ['name', 'value']
});
return { return {
index,
metadata, metadata,
instance, instance,
loading, loading,
@ -188,16 +195,25 @@ export default compose(
} }
}), }),
connect( connect(
({ values }, { metadata, ownProps }) => ({ ({ values, form }, { metadata, index, ownProps }) => {
// get search value
const filter = get(form, `${MENU_FORM_NAME}.values.filter`, false);
// if user is searching something, get items that match that query
const filtered = filter
? index.search(filter).map(({ id }) => find(metadata, ['id', id]))
: metadata;
return {
...ownProps, ...ownProps,
addOpen: get(values, 'add-metadata-open', false), addOpen: get(values, 'add-metadata-open', false),
metadata: metadata.map(({ form, ...metadata }) => ({ metadata: filtered.map(({ form, ...metadata }) => ({
...metadata, ...metadata,
form, form,
expanded: get(values, `${form}-expanded`, false), expanded: get(values, `${form}-expanded`, false),
removing: get(values, `${form}-removing`, false) removing: get(values, `${form}-removing`, false)
})) }))
}), };
},
(dispatch, ownProps) => { (dispatch, ownProps) => {
const { const {
instance, instance,

View File

@ -182,7 +182,7 @@ export default compose(
const snapshots = get(instance, 'snapshots', []); const snapshots = get(instance, 'snapshots', []);
const index = new Fuse(snapshots, { const index = new Fuse(snapshots, {
keys: snapshots.length ? Object.keys(snapshots[0]) : ['name'] keys: ['name', 'status', 'created']
}); });
return { return {

View File

@ -164,7 +164,7 @@ export default compose(
); );
const index = new Fuse(tags, { const index = new Fuse(tags, {
keys: tags.length ? Object.keys(tags[0]) : ['name'] keys: ['name', 'value']
}); });
return { return {