From 085415aa7bd973c613008d39839c65beaa3fda39 Mon Sep 17 00:00:00 2001 From: Zachary Wasserman Date: Sun, 6 Jan 2019 17:21:15 -0800 Subject: [PATCH] Allow selection of query targets by UUID in URL params (#1972) Closes #1934 --- .../pages/queries/QueryPage/QueryPage.jsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/pages/queries/QueryPage/QueryPage.jsx b/frontend/pages/queries/QueryPage/QueryPage.jsx index 9321609435..d80e8d55a5 100644 --- a/frontend/pages/queries/QueryPage/QueryPage.jsx +++ b/frontend/pages/queries/QueryPage/QueryPage.jsx @@ -2,7 +2,7 @@ import React, { Component, PropTypes } from 'react'; import classnames from 'classnames'; import { connect } from 'react-redux'; import FileSaver from 'file-saver'; -import { clone, filter, includes, isArray, isEqual, merge } from 'lodash'; +import { clone, filter, includes, isEqual, merge } from 'lodash'; import moment from 'moment'; import { push } from 'react-router-redux'; @@ -48,6 +48,7 @@ export class QueryPage extends Component { base: PropTypes.string, }), hostIDs: PropTypes.oneOfType([PropTypes.array, PropTypes.string]), + hostUUIDs: PropTypes.oneOfType([PropTypes.array, PropTypes.string]), isSmallNav: PropTypes.bool.isRequired, loadingQueries: PropTypes.bool.isRequired, location: PropTypes.shape({ @@ -83,9 +84,9 @@ export class QueryPage extends Component { } componentWillMount () { - const { dispatch, hostIDs, selectedHosts, selectedTargets } = this.props; + const { dispatch, hostIDs, hostUUIDs, selectedHosts, selectedTargets } = this.props; - if (hostIDs) { + if (((hostIDs && hostIDs.length) || (hostUUIDs && hostUUIDs.length)) > 0) { dispatch(hostActions.loadAll()); } @@ -567,24 +568,25 @@ const mapStateToProps = (state, ownProps) => { const queryStub = { description: '', name: '', query: queryText }; const query = reduxQuery || queryStub; const { selectedTargets } = state.components.QueryPages; - const { host_ids: hostIDs } = ownProps.location.query; + const { host_ids: hostIDs, host_uuids: hostUUIDs } = ownProps.location.query; const { isSmallNav } = state.app; const title = queryID ? 'Edit Query' : 'New Query'; let selectedHosts = []; - // hostIDs are URL params so they are strings - if (hostIDs && !queryID) { - const hostFilter = isArray(hostIDs) - ? h => includes(hostIDs, String(h.id)) - : { id: Number(hostIDs) }; - + if (!queryID && ((hostIDs && hostIDs.length) || (hostUUIDs && hostUUIDs.length)) > 0) { + const hostIDsArr = Array.isArray(hostIDs) ? hostIDs : [hostIDs]; + const hostUUIDsArr = Array.isArray(hostUUIDs) ? hostUUIDs : [hostUUIDs]; const { entities: hosts } = stateEntities.get('hosts'); + // hostIDs are URL params so they are strings and comparison with ints may + // need conversion. + const hostFilter = h => includes(hostIDsArr, String(h.id)) || includes(hostUUIDsArr, String(h.uuid)); selectedHosts = filter(hosts, hostFilter); } return { errors, hostIDs, + hostUUIDs, isSmallNav, loadingQueries, query,