11import { css } from 'emotion' ;
22import React , { ChangeEvent , createRef , PureComponent , RefObject } from 'react' ;
3- import { DefaultScript } from 'redis-gears-panel/constants' ;
43import { Observable } from 'rxjs' ;
54import {
65 DataFrame ,
@@ -15,7 +14,8 @@ import {
1514 toDataFrame ,
1615} from '@grafana/data' ;
1716import { getDataSourceSrv , toDataQueryError } from '@grafana/runtime' ;
18- import { Alert , Button , InlineField , InlineFormLabel , Input , Switch , Table } from '@grafana/ui' ;
17+ import { Alert , Button , InlineField , InlineFormLabel , Input , RadioButtonGroup , Table } from '@grafana/ui' ;
18+ import { DefaultScript , ExecutionMode , ExecutionOptions } from '../../constants' ;
1919import { PanelOptions } from '../../types' ;
2020import { CodeEditor } from '../code-editor' ;
2121
@@ -141,7 +141,7 @@ export class RedisGearsPanel extends PureComponent<Props, State> {
141141 /**
142142 * Error
143143 */
144- if ( ! response || response . state === LoadingState . Error ) {
144+ if ( ! response || response . state === LoadingState . Error || ! response . data . length ) {
145145 this . setState ( {
146146 result : undefined ,
147147 isRunning : false ,
@@ -166,7 +166,6 @@ export class RedisGearsPanel extends PureComponent<Props, State> {
166166 }
167167
168168 let resultDataFrame : DataFrame = response . data [ 0 ] ;
169-
170169 if ( resultDataFrame . length === 0 ) {
171170 resultDataFrame = toDataFrame ( {
172171 fields : [
@@ -236,9 +235,9 @@ export class RedisGearsPanel extends PureComponent<Props, State> {
236235 *
237236 * @param event {HTMLInputElement}
238237 */
239- onChangeUnblocking = ( event : ChangeEvent < HTMLInputElement > ) => {
238+ onChangeUnblocking = ( event ?: ExecutionMode ) => {
240239 this . setState ( {
241- unblocking : event . target . checked ,
240+ unblocking : event ? true : false ,
242241 } ) ;
243242 } ;
244243
@@ -269,15 +268,6 @@ export class RedisGearsPanel extends PureComponent<Props, State> {
269268 const { height, width } = this . props ;
270269 const { script, result, unblocking, requirements, isRunning, footerHeight, error } = this . state ;
271270
272- let resultComponent = null ;
273-
274- /**
275- * Show result table If there is a result
276- */
277- if ( result ) {
278- resultComponent = < Table noHeader = { true } data = { result } width = { width } height = { 100 } /> ;
279- }
280-
281271 return (
282272 < div
283273 className = { css `
@@ -303,23 +293,31 @@ export class RedisGearsPanel extends PureComponent<Props, State> {
303293 < div ref = { this . footerRef } >
304294 { error && error . message && < Alert title = { error . message } onRemove = { this . onClearError } /> }
305295
306- < div className = "gf-form-inline " >
296+ < div className = "gf-form" >
307297 < InlineField label = { < InlineFormLabel width = { 6 } > Requirements</ InlineFormLabel > } >
308298 < Input css = "" value = { requirements } onChange = { this . onChangeRequirements } width = { 40 } />
309299 </ InlineField >
310300
311- < InlineField label = { < InlineFormLabel width = { 6 } > Unblocking</ InlineFormLabel > } >
312- < Switch css = "" value = { unblocking } onChange = { this . onChangeUnblocking } />
313- </ InlineField >
314-
315- < div className = "gf-form" >
316- < Button onClick = { this . onRunScript } disabled = { isRunning } >
317- { isRunning ? 'Running...' : 'Run script' }
318- </ Button >
319- </ div >
320-
321- { resultComponent }
301+ < RadioButtonGroup
302+ className = { css `
303+ margin-right : 4px ;
304+ ` }
305+ value = { unblocking ? ExecutionMode . Unblocking : ExecutionMode . Blocking }
306+ options = { ExecutionOptions }
307+ onChange = { this . onChangeUnblocking }
308+ />
309+
310+ < Button onClick = { this . onRunScript } disabled = { isRunning } >
311+ { isRunning ? 'Running...' : 'Run script' }
312+ </ Button >
322313 </ div >
314+
315+ { result && (
316+ < >
317+ < hr />
318+ < Table noHeader = { true } data = { result } width = { width } height = { 100 } />
319+ </ >
320+ ) }
323321 </ div >
324322 </ div >
325323 ) ;
0 commit comments