From ae76ddcc3b6ecc7373b567d39d4d10c221a944d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 14:05:47 +0100 Subject: [PATCH] explore using data source picker --- .../PermissionList/PermissionListItem.tsx | 1 + .../components/Select}/DataSourcePicker.tsx | 22 ++----- public/app/core/components/Select/Select.tsx | 60 +++++++++++++++++-- .../dashboard/dashgrid/QueriesTab.tsx | 12 +--- public/app/features/explore/Explore.tsx | 34 +++-------- public/app/types/explore.ts | 8 +-- public/sass/components/_form_select_box.scss | 4 +- 7 files changed, 77 insertions(+), 64 deletions(-) rename public/app/{features/dashboard/dashgrid => core/components/Select}/DataSourcePicker.tsx (64%) diff --git a/public/app/core/components/PermissionList/PermissionListItem.tsx b/public/app/core/components/PermissionList/PermissionListItem.tsx index 6b288bd9e6d..a97a57b965b 100644 --- a/public/app/core/components/PermissionList/PermissionListItem.tsx +++ b/public/app/core/components/PermissionList/PermissionListItem.tsx @@ -75,6 +75,7 @@ export default class PermissionsListItem extends PureComponent {
this.onChange(item)} + onChange={this.onChange} options={options} - styles={ResetStyles} autoFocus={autoFocus} onBlur={onBlur} openMenuOnFocus={true} maxMenuHeight={500} placeholder="Select datasource" - loadingMessage={() => 'Loading datasources...'} noOptionsMessage={() => 'No datasources found'} value={value} - components={{ - Option, - SingleValue, - IndicatorsContainer, - }} />
); diff --git a/public/app/core/components/Select/Select.tsx b/public/app/core/components/Select/Select.tsx index e4cbb4a66df..d43e47f52c3 100644 --- a/public/app/core/components/Select/Select.tsx +++ b/public/app/core/components/Select/Select.tsx @@ -29,7 +29,16 @@ interface CommonProps { className?: string; components: object; isDisabled?: boolean; - isSearchable: boolean; + isSearchable?: boolean; + isClearable?: boolean; + autoFocus?: boolean; + openMenuOnFocus?: boolean; + onBlur?: () => void; + maxMenuHeight?: number; + isLoading: boolean; + noOptionsMessage?: () => string; + isMulti?: boolean; + backspaceRemovesValue: boolean; } interface SelectProps { @@ -39,9 +48,7 @@ interface SelectProps { interface AsyncProps { defaultOptions: boolean; loadOptions: (query: string) => Promise; - isLoading: boolean; loadingMessage?: () => string; - noOptionsMessage?: () => string; } export class Select extends PureComponent { @@ -51,6 +58,13 @@ export class Select extends PureComponent { components: {}, isDisabled: false, isSearchable: true, + isClearable: false, + isMulti: false, + openMenuOnFocus: false, + autoFocus: false, + isLoading: false, + backspaceRemovesValue: true, + maxMenuHeight: 300, }; render() { @@ -65,7 +79,16 @@ export class Select extends PureComponent { value, className, isDisabled, - isSearchable + isLoading, + isSearchable, + isClearable, + backspaceRemovesValue, + isMulti, + autoFocus, + openMenuOnFocus, + onBlur, + maxMenuHeight, + noOptionsMessage, } = this.props; let widthClass = ''; @@ -95,6 +118,15 @@ export class Select extends PureComponent { placeholder={placeholder || 'Choose'} styles={ResetStyles} isDisabled={isDisabled} + isLoading={isLoading} + isClearable={isClearable} + autoFocus={autoFocus} + onBlur={onBlur} + openMenuOnFocus={openMenuOnFocus} + maxMenuHeight={maxMenuHeight} + noOptionsMessage={noOptionsMessage} + isMulti={isMulti} + backspaceRemovesValue={backspaceRemovesValue} /> ); } @@ -107,7 +139,13 @@ export class AsyncSelect extends PureComponent { components: {}, loadingMessage: () => 'Loading...', isDisabled: false, + isClearable: false, + isMulti: false, isSearchable: true, + backspaceRemovesValue: true, + autoFocus: false, + openMenuOnFocus: false, + maxMenuHeight: 300, }; render() { @@ -127,6 +165,13 @@ export class AsyncSelect extends PureComponent { noOptionsMessage, isDisabled, isSearchable, + isClearable, + backspaceRemovesValue, + autoFocus, + onBlur, + openMenuOnFocus, + maxMenuHeight, + isMulti, } = this.props; let widthClass = ''; @@ -161,6 +206,13 @@ export class AsyncSelect extends PureComponent { noOptionsMessage={noOptionsMessage} isDisabled={isDisabled} isSearchable={isSearchable} + isClearable={isClearable} + autoFocus={autoFocus} + onBlur={onBlur} + openMenuOnFocus={openMenuOnFocus} + maxMenuHeight={maxMenuHeight} + isMulti={isMulti} + backspaceRemovesValue={backspaceRemovesValue} /> ); } diff --git a/public/app/features/dashboard/dashgrid/QueriesTab.tsx b/public/app/features/dashboard/dashgrid/QueriesTab.tsx index cd26defbed3..0f449efdc35 100644 --- a/public/app/features/dashboard/dashgrid/QueriesTab.tsx +++ b/public/app/features/dashboard/dashgrid/QueriesTab.tsx @@ -6,7 +6,7 @@ import _ from 'lodash'; // Components import './../../panel/metrics_tab'; import { EditorTabBody } from './EditorTabBody'; -import { DataSourcePicker } from './DataSourcePicker'; +import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker'; import { QueryInspector } from './QueryInspector'; import { QueryOptions } from './QueryOptions'; import { AngularQueryComponentScope } from 'app/features/panel/metrics_tab'; @@ -205,20 +205,14 @@ export class QueriesTab extends PureComponent { renderToolbar = () => { const { currentDS } = this.state; - return ( - - ); + return ; }; renderMixedPicker = () => { return ( { if (!datasourceSrv) { throw new Error('No datasource service passed as props.'); } + const datasources = datasourceSrv.getExternal(); const exploreDatasources = datasources.map(ds => ({ value: ds.name, - label: ds.name, + name: ds.name, + meta: ds.meta, })); if (datasources.length > 0) { @@ -885,7 +883,7 @@ export class Explore extends React.PureComponent { } = this.state; const graphHeight = showingGraph && showingTable ? '200px' : '400px'; const exploreClass = split ? 'explore explore-split' : 'explore'; - const selectedDatasource = datasource ? exploreDatasources.find(d => d.label === datasource.name) : undefined; + const selectedDatasource = datasource ? exploreDatasources.find(d => d.name === datasource.name) : undefined; const graphLoading = queryTransactions.some(qt => qt.resultType === 'Graph' && !qt.done); const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done); const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done); @@ -910,26 +908,10 @@ export class Explore extends React.PureComponent { )} {!datasourceMissing ? (
-