diff --git a/public/app/features/dashboard/panel_editor/QueryEditorRow.tsx b/public/app/features/dashboard/panel_editor/QueryEditorRow.tsx index def0e85f07b..a7724eed814 100644 --- a/public/app/features/dashboard/panel_editor/QueryEditorRow.tsx +++ b/public/app/features/dashboard/panel_editor/QueryEditorRow.tsx @@ -23,6 +23,7 @@ interface Props { interface State { datasource: DataSourceApi | null; isCollapsed: boolean; + angularScope: AngularQueryComponentScope | null; } export class QueryEditorRow extends PureComponent { @@ -32,6 +33,7 @@ export class QueryEditorRow extends PureComponent { state: State = { datasource: null, isCollapsed: false, + angularScope: null, }; componentDidMount() { @@ -85,6 +87,11 @@ export class QueryEditorRow extends PureComponent { const scopeProps = { ctrl: this.getAngularQueryComponentScope() }; this.angularQueryEditor = loader.load(this.element, scopeProps, template); + + // give angular time to compile + setTimeout(() => { + this.setState({ angularScope: scopeProps.ctrl }); + }, 10); } componentWillUnmount() { @@ -97,54 +104,84 @@ export class QueryEditorRow extends PureComponent { this.setState({ isCollapsed: !this.state.isCollapsed }); }; - render() { - const { query } = this.props; - const { datasource, isCollapsed } = this.state; - const bodyClasses = classNames('query-editor-box__body gf-form-query', {hide: isCollapsed}); - - if (!datasource) { - return null; - } + renderPluginEditor() { + const { datasource } = this.state; if (datasource.pluginExports.QueryCtrl) { - return ( -
-
-
- {isCollapsed && } - {!isCollapsed && } - {query.refId} -
-
- - - - - -
-
-
-
(this.element = element)} /> -
-
- ); - } else if (datasource.pluginExports.QueryEditor) { + } + return
(this.element = element)} />; + + if (datasource.pluginExports.QueryEditor) { const QueryEditor = datasource.pluginExports.QueryEditor; return ; } return
Data source plugin does not export any Query Editor component
; } + + onToggleEditMode = () => { + const { angularScope } = this.state; + + if (angularScope && angularScope.toggleEditorMode) { + angularScope.toggleEditorMode(); + this.angularQueryEditor.digest(); + } + } + + get hasTextEditMode() { + const { angularScope } = this.state; + return angularScope && angularScope.toggleEditorMode; + } + + render() { + const { query } = this.props; + const { datasource, isCollapsed, angularScope } = this.state; + const bodyClasses = classNames('query-editor-box__body gf-form-query', { hide: isCollapsed }); + + if (!datasource) { + return null; + } + + console.log('Query render'); + if (angularScope !== null && angularScope.toggleEditorMode) { + console.log('Query editor has text edit mode'); + } + + return ( +
+
+
+ {isCollapsed && } + {!isCollapsed && } + {query.refId} +
+
+ {this.hasTextEditMode && ( + + )} + + + + + +
+
+
{this.renderPluginEditor()}
+
+ ); + } } export interface AngularQueryComponentScope { @@ -157,4 +194,5 @@ export interface AngularQueryComponentScope { addQuery: (query?: DataQuery) => void; moveQuery: (query: DataQuery, direction: number) => void; datasource: DataSourceApi; + toggleEditorMode?: () => void; } diff --git a/public/app/features/panel/query_editor_row.ts b/public/app/features/panel/query_editor_row.ts index a44c1e8be6d..82d93ca5cae 100644 --- a/public/app/features/panel/query_editor_row.ts +++ b/public/app/features/panel/query_editor_row.ts @@ -12,6 +12,7 @@ export class QueryRowCtrl { panel: any; collapsed: any; hideEditorRowActions: boolean; + hasTextEditMode: boolean; constructor() { this.panelCtrl = this.queryCtrl.panelCtrl; @@ -19,6 +20,10 @@ export class QueryRowCtrl { this.panel = this.panelCtrl.panel; this.hideEditorRowActions = this.panelCtrl.hideEditorRowActions; + if (this.hasTextEditMode) { + this.panelCtrl.toggleEditorMode = this.toggleEditorMode.bind(this); + } + if (!this.target.refId) { this.target.refId = this.panel.getNextQueryLetter(); } diff --git a/public/sass/components/_query_editor.scss b/public/sass/components/_query_editor.scss index fe455df1bff..7e8eddea414 100644 --- a/public/sass/components/_query_editor.scss +++ b/public/sass/components/_query_editor.scss @@ -184,7 +184,6 @@ input[type='text'].tight-form-func-param { } .query-editor-box { - background: $page-bg; margin-bottom: 2px; &:hover { @@ -199,13 +198,13 @@ input[type='text'].tight-form-func-param { padding: 4px 0px 4px 8px; position: relative; height: 35px; + background: $page-bg; } .query-editor-box__ref-id { font-weight: $font-weight-semi-bold; color: $blue; font-size: $font-size-md; - flex-grow: 1; cursor: pointer; display: flex; align-items: center; @@ -218,17 +217,24 @@ input[type='text'].tight-form-func-param { } .query-editor-box__actions { + flex-grow: 1; display: flex; justify-content: flex-end; - display: none; + color: $text-muted; } .query-editor-box__action { - @include buttonBackground($btn-inverse-bg, $btn-inverse-bg-hl, $btn-inverse-text-color, $btn-inverse-text-shadow); - border: 1px solid $navbar-button-border; - margin-right: 3px; + margin-left: 3px; + background: transparent; + border: none; + box-shadow: none; + + &:hover { + color: $text-color; + } } .query-editor-box__body { - padding: 10px 20px; + margin: 0 0 10px 40px; + background: $page-bg; }