mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Allow selection of query targets by UUID in URL params (#1972)
Closes #1934
This commit is contained in:
parent
be85377326
commit
085415aa7b
1 changed files with 12 additions and 10 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue