2121import React , { Component } from 'react'
2222import { connect } from 'react-redux'
2323import { withBus } from 'react-suber'
24+ import { withTheme } from 'styled-components'
2425import uuid from 'uuid'
2526import {
2627 executeCommand ,
@@ -40,7 +41,7 @@ import {
4041 shouldEditorAutocomplete ,
4142 shouldEditorLint
4243} from 'shared/modules/settings/settingsDuck'
43- import { Bar , ActionButtonSection , EditorWrapper } from './styled'
44+ import { Bar , ActionButtonSection , EditorWrapper , Header } from './styled'
4445import { EditorButton , EditModeEditorButton } from 'browser-components/buttons'
4546import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
4647import { deepEquals , shallowEquals } from 'services/utils'
@@ -55,6 +56,7 @@ import eraser2 from 'icons/eraser-2.svg'
5556import pencil from 'icons/pencil.svg'
5657import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
5758import { getUseDb } from 'shared/modules/connections/connectionsDuck'
59+ import ActionButtons from './ActionButtons'
5860
5961const shouldCheckForHints = code =>
6062 code . trim ( ) . length > 0 &&
@@ -403,12 +405,45 @@ export class Editor extends Component {
403405
404406 this . setGutterMarkers ( )
405407
408+ const editorIsEmpty = this . getEditorValue ( ) . length > 0
409+ const buttons = [
410+ {
411+ onClick : ( ) => this . setEditorValue ( '' ) ,
412+ icon : eraser2 ,
413+ title : 'Clear' ,
414+ disabled : editorIsEmpty
415+ } ,
416+ {
417+ onClick : this . state . contentId
418+ ? ( ) =>
419+ this . props . onFavoriteUpdateClick (
420+ this . state . contentId ,
421+ this . getEditorValue ( )
422+ )
423+ : ( ) => {
424+ this . props . onFavoriteClick ( this . getEditorValue ( ) )
425+ } ,
426+ icon : this . state . contentId ? pencil : ratingStar ,
427+ title : this . state . contentId ? 'Update favorite' : 'Favorite' ,
428+ iconColor : this . state . contentId && this . props . theme . editModeButtonText ,
429+ disabled : editorIsEmpty
430+ } ,
431+ {
432+ onClick : this . execCurrent ,
433+ icon : controlsPlay ,
434+ title : 'Play' ,
435+ disabled : editorIsEmpty
436+ }
437+ ]
438+
439+ const cardView = this . codeMirror && this . codeMirror . lineCount ( ) !== 1
440+
406441 return (
407- < Bar expanded = { this . state . expanded } minHeight = { this . state . editorHeight } >
408- < EditorWrapper
409- expanded = { this . state . expanded }
410- minHeight = { this . state . editorHeight }
411- >
442+ < Bar expanded = { this . state . expanded } card = { cardView } >
443+ < Header expanded = { this . state . expanded } card = { cardView } >
444+ < ActionButtons buttons = { buttons } />
445+ </ Header >
446+ < EditorWrapper expanded = { this . state . expanded } card = { cardView } >
412447 < Codemirror
413448 ref = { ref => {
414449 this . editor = ref
@@ -420,47 +455,6 @@ export class Editor extends Component {
420455 initialPosition = { this . state . lastPosition }
421456 />
422457 </ EditorWrapper >
423- < ActionButtonSection >
424- < Render if = { this . state . contentId } >
425- < EditModeEditorButton
426- onClick = { ( ) =>
427- this . props . onFavoriteUpdateClick (
428- this . state . contentId ,
429- this . getEditorValue ( )
430- )
431- }
432- disabled = { this . getEditorValue ( ) . length < 1 }
433- color = "#ffaf00"
434- title = "Favorite"
435- icon = { pencil }
436- />
437- </ Render >
438- < Render if = { ! this . state . contentId } >
439- < EditorButton
440- data-testid = "editorFavorite"
441- onClick = { ( ) => {
442- this . props . onFavoriteClick ( this . getEditorValue ( ) )
443- } }
444- disabled = { this . getEditorValue ( ) . length < 1 }
445- title = "Update favorite"
446- icon = { ratingStar }
447- />
448- </ Render >
449- < EditorButton
450- data-testid = "clearEditorContent"
451- onClick = { this . clearEditor }
452- disabled = { this . getEditorValue ( ) . length < 1 }
453- title = "Clear"
454- icon = { eraser2 }
455- />
456- < EditorButton
457- data-testid = "submitQuery"
458- onClick = { this . execCurrent }
459- disabled = { this . getEditorValue ( ) . length < 1 }
460- title = "Play"
461- icon = { controlsPlay }
462- />
463- </ ActionButtonSection >
464458 </ Bar >
465459 )
466460 }
@@ -511,4 +505,6 @@ const mapStateToProps = state => {
511505 }
512506}
513507
514- export default withBus ( connect ( mapStateToProps , mapDispatchToProps ) ( Editor ) )
508+ export default withTheme (
509+ withBus ( connect ( mapStateToProps , mapDispatchToProps ) ( Editor ) )
510+ )
0 commit comments