From bda49fcaa209f9136659814d6900b3d156c2adca Mon Sep 17 00:00:00 2001 From: David Date: Fri, 3 Aug 2018 10:20:13 +0200 Subject: [PATCH] Add click on explore table cell to add filter to query (#12729) * Add click on explore table cell to add filter to query - move query state from query row to explore container to be able to set modified queries - added TS interface for columns in table model - plumbing from table cell click to datasource - add modifyQuery to prometheus datasource - implement addFilter as addLabelToQuery with tests * Review feedback - using airbnb style for Cell declaration - fixed addLabelToQuery for complex label values --- public/app/containers/Explore/Explore.tsx | 31 ++++++-- public/app/containers/Explore/QueryRows.tsx | 18 +---- public/app/containers/Explore/Table.tsx | 52 +++++++++++-- public/app/core/table_model.ts | 12 ++- .../datasource/prometheus/datasource.ts | 74 +++++++++++++++++++ .../prometheus/result_transformer.ts | 2 +- .../prometheus/specs/datasource.jest.ts | 27 ++++++- .../specs/result_transformer.jest.ts | 6 +- public/sass/pages/_explore.scss | 4 + 9 files changed, 190 insertions(+), 36 deletions(-) diff --git a/public/app/containers/Explore/Explore.tsx b/public/app/containers/Explore/Explore.tsx index 178e53198d4..a0bb38a13f1 100644 --- a/public/app/containers/Explore/Explore.tsx +++ b/public/app/containers/Explore/Explore.tsx @@ -187,11 +187,14 @@ export class Explore extends React.Component { this.setDatasource(datasource); }; - handleChangeQuery = (query, index) => { + handleChangeQuery = (value, index) => { const { queries } = this.state; + const prevQuery = queries[index]; + const edited = prevQuery.query !== value; const nextQuery = { ...queries[index], - query, + edited, + query: value, }; const nextQueries = [...queries]; nextQueries[index] = nextQuery; @@ -254,6 +257,18 @@ export class Explore extends React.Component { } }; + onClickTableCell = (columnKey: string, rowValue: string) => { + const { datasource, queries } = this.state; + if (datasource && datasource.modifyQuery) { + const nextQueries = queries.map(q => ({ + ...q, + edited: false, + query: datasource.modifyQuery(q.query, { addFilter: { key: columnKey, value: rowValue } }), + })); + this.setState({ queries: nextQueries }, () => this.handleSubmit()); + } + }; + buildQueryOptions(targetOptions: { format: string; instant?: boolean }) { const { datasource, queries, range } = this.state; const resolution = this.el.offsetWidth; @@ -390,12 +405,12 @@ export class Explore extends React.Component { ) : ( -
- -
- )} + + )} {!datasourceMissing ? (