diff --git a/packages/my-joy-instances/src/containers/instances/list.js b/packages/my-joy-instances/src/containers/instances/list.js index 961bc16c..67f8f1be 100644 --- a/packages/my-joy-instances/src/containers/instances/list.js +++ b/packages/my-joy-instances/src/containers/instances/list.js @@ -197,7 +197,7 @@ export default compose( })); const index = new Fuse(instances, { - keys: instances.length ? Object.keys(instances[0]) : ['name'] + keys: ['id', 'name', 'status', 'created'] }); return { diff --git a/packages/my-joy-instances/src/containers/instances/metadata.js b/packages/my-joy-instances/src/containers/instances/metadata.js index a665eedd..41f9102f 100644 --- a/packages/my-joy-instances/src/containers/instances/metadata.js +++ b/packages/my-joy-instances/src/containers/instances/metadata.js @@ -10,6 +10,7 @@ import find from 'lodash.find'; import get from 'lodash.get'; import intercept from 'apr-intercept'; import remcalc from 'remcalc'; +import Fuse from 'fuse.js'; import { ViewContainer, @@ -170,7 +171,8 @@ export default compose( ({ name = '' }) => name !== 'user-script' ); - const metadata = values.map(({ name, value }) => ({ + const metadata = values.map(({ id, name, value }) => ({ + id, form: METADATA_FORM_KEY(name), initialValues: { name, @@ -178,7 +180,12 @@ export default compose( } })); + const index = new Fuse(values, { + keys: ['name', 'value'] + }); + return { + index, metadata, instance, loading, @@ -188,16 +195,25 @@ export default compose( } }), connect( - ({ values }, { metadata, ownProps }) => ({ - ...ownProps, - addOpen: get(values, 'add-metadata-open', false), - metadata: metadata.map(({ form, ...metadata }) => ({ - ...metadata, - form, - expanded: get(values, `${form}-expanded`, false), - removing: get(values, `${form}-removing`, false) - })) - }), + ({ 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, + addOpen: get(values, 'add-metadata-open', false), + metadata: filtered.map(({ form, ...metadata }) => ({ + ...metadata, + form, + expanded: get(values, `${form}-expanded`, false), + removing: get(values, `${form}-removing`, false) + })) + }; + }, (dispatch, ownProps) => { const { instance, diff --git a/packages/my-joy-instances/src/containers/instances/snapshots.js b/packages/my-joy-instances/src/containers/instances/snapshots.js index 57674833..d70dee2b 100644 --- a/packages/my-joy-instances/src/containers/instances/snapshots.js +++ b/packages/my-joy-instances/src/containers/instances/snapshots.js @@ -182,7 +182,7 @@ export default compose( const snapshots = get(instance, 'snapshots', []); const index = new Fuse(snapshots, { - keys: snapshots.length ? Object.keys(snapshots[0]) : ['name'] + keys: ['name', 'status', 'created'] }); return { diff --git a/packages/my-joy-instances/src/containers/instances/tags.js b/packages/my-joy-instances/src/containers/instances/tags.js index ee79284c..2550dcfe 100644 --- a/packages/my-joy-instances/src/containers/instances/tags.js +++ b/packages/my-joy-instances/src/containers/instances/tags.js @@ -164,7 +164,7 @@ export default compose( ); const index = new Fuse(tags, { - keys: tags.length ? Object.keys(tags[0]) : ['name'] + keys: ['name', 'value'] }); return {