From 9914071cc02cb10927e0c5b2398aed4c3a1a6a2f Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 1 Oct 2018 15:09:10 +0200 Subject: [PATCH 1/4] Dont rebuild datasource options on each render --- public/app/core/utils/explore.test.ts | 1 + public/app/features/explore/Explore.tsx | 27 ++++++++++++++----------- public/app/types/explore.ts | 6 ++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/public/app/core/utils/explore.test.ts b/public/app/core/utils/explore.test.ts index 8b303ffafa3..c47321225fe 100644 --- a/public/app/core/utils/explore.test.ts +++ b/public/app/core/utils/explore.test.ts @@ -7,6 +7,7 @@ const DEFAULT_EXPLORE_STATE: ExploreState = { datasourceLoading: null, datasourceMissing: false, datasourceName: '', + exploreDatasources: [], graphResult: null, history: [], latency: 0, diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 502ad65b353..49fbb3bd476 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -73,6 +73,7 @@ export class Explore extends React.PureComponent { datasourceLoading: null, datasourceMissing: false, datasourceName: datasource, + exploreDatasources: [], graphResult: null, history: [], latency: 0, @@ -101,8 +102,13 @@ export class Explore extends React.PureComponent { throw new Error('No datasource service passed as props.'); } const datasources = datasourceSrv.getExploreSources(); + const exploreDatasources = datasources.map(ds => ({ + value: ds.name, + label: ds.name, + })); + if (datasources.length > 0) { - this.setState({ datasourceLoading: true }); + this.setState({ datasourceLoading: true, exploreDatasources }); // Priority: datasource in url, default datasource, first explore datasource let datasource; if (datasourceName) { @@ -461,12 +467,13 @@ export class Explore extends React.PureComponent { }; render() { - const { datasourceSrv, position, split } = this.props; + const { position, split } = this.props; const { datasource, datasourceError, datasourceLoading, datasourceMissing, + exploreDatasources, graphResult, history, latency, @@ -491,10 +498,6 @@ export class Explore extends React.PureComponent { const logsButtonActive = showingLogs ? 'active' : ''; const tableButtonActive = showingBoth || showingTable ? 'active' : ''; const exploreClass = split ? 'explore explore-split' : 'explore'; - const datasources = datasourceSrv.getExploreSources().map(ds => ({ - value: ds.name, - label: ds.name, - })); const selectedDatasource = datasource ? datasource.name : undefined; return ( @@ -508,19 +511,19 @@ export class Explore extends React.PureComponent { ) : ( -
- -
- )} + + )} {!datasourceMissing ? (