diff --git a/package.json b/package.json index c0581c1de43..200285d7a1e 100644 --- a/package.json +++ b/package.json @@ -166,6 +166,7 @@ "mousetrap-global-bind": "^1.1.0", "prismjs": "^1.6.0", "prop-types": "^15.6.0", + "rc-cascader": "^0.14.0", "react": "^16.2.0", "react-dom": "^16.2.0", "react-grid-layout": "0.16.6", @@ -187,4 +188,4 @@ "resolutions": { "caniuse-db": "1.0.30000772" } -} \ No newline at end of file +} diff --git a/public/app/containers/Explore/Explore.tsx b/public/app/containers/Explore/Explore.tsx index 53c43782ad6..3ee5bceae8b 100644 --- a/public/app/containers/Explore/Explore.tsx +++ b/public/app/containers/Explore/Explore.tsx @@ -166,7 +166,7 @@ export class Explore extends React.Component { supportsTable, datasourceLoading: false, }, - () => datasourceError === null && this.handleSubmit() + () => datasourceError === null && this.onSubmit() ); } @@ -174,7 +174,7 @@ export class Explore extends React.Component { this.el = el; }; - handleAddQueryRow = index => { + onAddQueryRow = index => { const { queries } = this.state; const nextQueries = [ ...queries.slice(0, index + 1), @@ -184,7 +184,7 @@ export class Explore extends React.Component { this.setState({ queries: nextQueries }); }; - handleChangeDatasource = async option => { + onChangeDatasource = async option => { this.setState({ datasource: null, datasourceError: null, @@ -197,10 +197,10 @@ export class Explore extends React.Component { this.setDatasource(datasource); }; - handleChangeQuery = (value, index) => { + onChangeQuery = (value: string, index: number, override?: boolean) => { const { queries } = this.state; const prevQuery = queries[index]; - const edited = prevQuery.query !== value; + const edited = override ? false : prevQuery.query !== value; const nextQuery = { ...queries[index], edited, @@ -208,65 +208,52 @@ export class Explore extends React.Component { }; const nextQueries = [...queries]; nextQueries[index] = nextQuery; - this.setState({ queries: nextQueries }); + this.setState({ queries: nextQueries }, override ? () => this.onSubmit() : undefined); }; - handleChangeTime = nextRange => { + onChangeTime = nextRange => { const range = { from: nextRange.from, to: nextRange.to, }; - this.setState({ range }, () => this.handleSubmit()); + this.setState({ range }, () => this.onSubmit()); }; - handleClickCloseSplit = () => { + onClickClear = () => { + this.setState({ + graphResult: null, + logsResult: null, + queries: ensureQueries(), + tableResult: null, + }); + }; + + onClickCloseSplit = () => { const { onChangeSplit } = this.props; if (onChangeSplit) { onChangeSplit(false); } }; - handleClickGraphButton = () => { + onClickGraphButton = () => { this.setState(state => ({ showingGraph: !state.showingGraph })); }; - handleClickLogsButton = () => { + onClickLogsButton = () => { this.setState(state => ({ showingLogs: !state.showingLogs })); }; - handleClickSplit = () => { + onClickSplit = () => { const { onChangeSplit } = this.props; if (onChangeSplit) { onChangeSplit(true, this.state); } }; - handleClickTableButton = () => { + onClickTableButton = () => { this.setState(state => ({ showingTable: !state.showingTable })); }; - handleRemoveQueryRow = index => { - const { queries } = this.state; - if (queries.length <= 1) { - return; - } - const nextQueries = [...queries.slice(0, index), ...queries.slice(index + 1)]; - this.setState({ queries: nextQueries }, () => this.handleSubmit()); - }; - - handleSubmit = () => { - const { showingLogs, showingGraph, showingTable, supportsGraph, supportsLogs, supportsTable } = this.state; - if (showingTable && supportsTable) { - this.runTableQuery(); - } - if (showingGraph && supportsGraph) { - this.runGraphQuery(); - } - if (showingLogs && supportsLogs) { - this.runLogsQuery(); - } - }; - onClickTableCell = (columnKey: string, rowValue: string) => { const { datasource, queries } = this.state; if (datasource && datasource.modifyQuery) { @@ -275,7 +262,29 @@ export class Explore extends React.Component { edited: false, query: datasource.modifyQuery(q.query, { addFilter: { key: columnKey, value: rowValue } }), })); - this.setState({ queries: nextQueries }, () => this.handleSubmit()); + this.setState({ queries: nextQueries }, () => this.onSubmit()); + } + }; + + onRemoveQueryRow = index => { + const { queries } = this.state; + if (queries.length <= 1) { + return; + } + const nextQueries = [...queries.slice(0, index), ...queries.slice(index + 1)]; + this.setState({ queries: nextQueries }, () => this.onSubmit()); + }; + + onSubmit = () => { + const { showingLogs, showingGraph, showingTable, supportsGraph, supportsLogs, supportsTable } = this.state; + if (showingTable && supportsTable) { + this.runTableQuery(); + } + if (showingGraph && supportsGraph) { + this.runGraphQuery(); + } + if (showingLogs && supportsLogs) { + this.runLogsQuery(); } }; @@ -441,7 +450,7 @@ export class Explore extends React.Component { ) : (
-
@@ -451,7 +460,7 @@ export class Explore extends React.Component {