Skip to content

Commit eb66aee

Browse files
Merge pull request #1155 from OskarDamkjaer/card_view
Card view
2 parents 9c1b7a5 + 94a0887 commit eb66aee

File tree

12 files changed

+256
-164
lines changed

12 files changed

+256
-164
lines changed

e2e_tests/integration/0.index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import { isAura, isEnterpriseEdition } from '../support/utils'
2424

2525
const Editor = '.ReactCodeMirror textarea'
2626
const Carousel = '[data-testid="carousel"]'
27-
const SubmitQueryButton = '[data-testid="submitQuery"]'
28-
const ClearEditorButton = '[data-testid="clearEditorContent"]'
27+
const SubmitQueryButton = '[data-testid="editorPlay"]'
28+
const ClearEditorButton = '[data-testid="editorClear"]'
2929

3030
describe('Neo4j Browser', () => {
3131
before(function() {

e2e_tests/support/commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { executeCommand } from '../../src/shared/modules/commands/commandsDuck'
22

3-
const SubmitQueryButton = '[data-testid="submitQuery"]'
4-
const ClearEditorButton = '[data-testid="clearEditorContent"]'
3+
const SubmitQueryButton = '[data-testid="editorPlay"]'
4+
const ClearEditorButton = '[data-testid="editorClear"]'
55
const Editor = '.ReactCodeMirror textarea'
66
const VisibleEditor = '[data-testid="editor-wrapper"]'
77

src/browser/components/buttons/index.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ export const CloseButton = props => {
3333
}
3434

3535
export const EditorButton = props => {
36-
const { icon, title, ...rest } = props
36+
const { icon, title, color, ...rest } = props
37+
const overrideColor = { ...(color ? { color } : {}) }
3738
return (
38-
<BaseButton title={title}>
39+
<BaseButton title={title} style={overrideColor}>
3940
<SVGInline svg={icon} accessibilityLabel={title} {...rest} width="24px" />
4041
</BaseButton>
4142
)
@@ -63,10 +64,6 @@ const BaseButton = styled.span`
6364
display: inline-block;
6465
`
6566

66-
export const EditModeEditorButton = styled(EditorButton)`
67-
color: ${props => props.theme.editModeButtonText};
68-
`
69-
7067
export const StyledNavigationButton = styled.button`
7168
background: transparent;
7269
border: 0;

src/browser/custom.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.svg' {
2+
const content: string
3+
export default content
4+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2002-2020 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
import React from 'react'
22+
import { ActionButtonSection } from './styled'
23+
import { EditorButton } from 'browser-components/buttons'
24+
interface ActionButtonProps {
25+
buttons: ActionButton[]
26+
}
27+
28+
interface ActionButton {
29+
onClick: () => void
30+
disabled: boolean
31+
title: string
32+
icon: string
33+
iconColor?: string
34+
}
35+
36+
const ActionButtons: React.FC<ActionButtonProps> = ({ buttons }) => (
37+
<ActionButtonSection containerWidth={buttons.length * 33}>
38+
{buttons.map((btn: ActionButton) => (
39+
<EditorButton
40+
data-testid={`editor${btn.title}`}
41+
onClick={btn.onClick}
42+
disabled={btn.disabled}
43+
title={btn.title}
44+
icon={btn.icon}
45+
key={`editor${btn.title}`}
46+
color={btn.iconColor}
47+
/>
48+
))}
49+
</ActionButtonSection>
50+
)
51+
52+
export default ActionButtons

src/browser/modules/Editor/Editor.jsx

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import React, { Component } from 'react'
2222
import { connect } from 'react-redux'
2323
import { withBus } from 'react-suber'
24+
import { withTheme } from 'styled-components'
2425
import uuid from 'uuid'
2526
import {
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'
4445
import { EditorButton, EditModeEditorButton } from 'browser-components/buttons'
4546
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
4647
import { deepEquals, shallowEquals } from 'services/utils'
@@ -55,6 +56,7 @@ import eraser2 from 'icons/eraser-2.svg'
5556
import pencil from 'icons/pencil.svg'
5657
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
5758
import { getUseDb } from 'shared/modules/connections/connectionsDuck'
59+
import ActionButtons from './ActionButtons'
5860

5961
const 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+
)

src/browser/modules/Editor/Editor.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ describe('<Editor /> ', () => {
4545
it('should setup on mount', async () => {
4646
// Given bus is provided
4747
const bus = createBus()
48-
const { findByText } = render(<Editor {...props} bus={bus} />)
48+
const mockTheme = { editModeButtonText: 'red' }
49+
const { findByText } = render(
50+
<Editor {...props} bus={bus} theme={mockTheme} />
51+
)
4952

5053
// The SET_CONTENT action
5154
// When

src/browser/modules/Editor/styled.jsx

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)