Skip to content

Commit 6e1e21c

Browse files
Merge pull request #1159 from OskarDamkjaer/frame_header
Frame header
2 parents 4d9a33d + 2225823 commit 6e1e21c

File tree

19 files changed

+466
-242
lines changed

19 files changed

+466
-242
lines changed

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"prettier/@typescript-eslint"
4848
],
4949
"plugins": ["@typescript-eslint/eslint-plugin"],
50-
"rules": {}
50+
"rules": {
51+
"@typescript-eslint/explicit-function-return-type": "off"
52+
}
5153
}
5254
]
5355
}

e2e_tests/integration/0.index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { isAura, isEnterpriseEdition } from '../support/utils'
2525
const Editor = '.ReactCodeMirror textarea'
2626
const Carousel = '[data-testid="carousel"]'
2727
const SubmitQueryButton = '[data-testid="editorPlay"]'
28-
const ClearEditorButton = '[data-testid="editorClear"]'
28+
const ClearEditorButton = '[data-testid="editor-discard"]'
2929

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

e2e_tests/integration/editor.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020

2121
/* global Cypress, cy, before */
22+
const fullscreenButton = '[data-testid="editor-fullscreen"]'
23+
const cardSizeButton = '[data-testid="editor-cardSize"]'
24+
const discardButton = '[data-testid="editor-discard"]'
2225

2326
describe('editor', () => {
2427
before(function() {
@@ -50,4 +53,29 @@ describe('editor', () => {
5053
cy.get('.CodeMirror-scroll').type(':history{control}{enter}')
5154
cy.get('.CodeMirror-linenumber').should('contain', '$')
5255
})
56+
57+
it('supports changing ui size from controls', () => {
58+
cy.get('.CodeMirror-linenumber').should('contain', '$')
59+
60+
// Toggle card view and back
61+
cy.get(cardSizeButton).click()
62+
cy.get('.CodeMirror-linenumber').should('contain', '1')
63+
cy.get(cardSizeButton).click()
64+
cy.get('.CodeMirror-linenumber').should('contain', '$')
65+
66+
// toggle full screen and nback
67+
cy.get(fullscreenButton).click()
68+
cy.get('.CodeMirror-linenumber').should('contain', '1')
69+
cy.get(fullscreenButton).click()
70+
cy.get('.CodeMirror-linenumber').should('contain', '$')
71+
72+
// discard resets size and clears editor
73+
cy.get(cardSizeButton).click()
74+
cy.get('.CodeMirror-linenumber').should('contain', '1')
75+
cy.get('body').type('/test')
76+
cy.get('.CodeMirror-line').contains('test')
77+
cy.get(discardButton).click()
78+
cy.get('.CodeMirror-linenumber').should('contain', '$')
79+
cy.get('.CodeMirror-line').should('not.contain.text', 'test')
80+
})
5381
})

e2e_tests/integration/play-command.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('Play command', () => {
109109
nextSlideBtn().click()
110110

111111
// Click link to new guide
112-
cy.contains('Procedures').click()
112+
cy.contains('Procedures').trigger('click')
113113

114114
// Assert
115115
cy.getFrames()

e2e_tests/support/commands.js

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

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"copy-webpack-plugin": "^5.1.1",
9191
"cross-env": "^6.0.3",
9292
"css-loader": "^1.0.0",
93-
"cypress": "4.11.0",
93+
"cypress": "4.12.1",
9494
"eslint": "^6.8.0",
9595
"eslint-config-prettier": "^6.7.0",
9696
"eslint-plugin-import": "^2.18.2",

src/browser/components/buttons/index.jsx

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

3535
export const EditorButton = props => {
36-
const { icon, title, color, ...rest } = props
36+
const { icon, title, color, width, ...rest } = props
3737
const overrideColor = { ...(color ? { color } : {}) }
3838
return (
39-
<BaseButton title={title} style={overrideColor}>
40-
<SVGInline svg={icon} accessibilityLabel={title} {...rest} width="24px" />
39+
<BaseButton title={title} style={overrideColor} width={width}>
40+
<SVGInline
41+
svg={icon}
42+
accessibilityLabel={title}
43+
{...rest}
44+
width={`${width}px`}
45+
/>
4146
</BaseButton>
4247
)
4348
}
@@ -53,8 +58,8 @@ const BaseButton = styled.span`
5358
color: ${props => props.theme.secondaryButtonText};
5459
background-color: ${props => props.theme.secondaryButtonBackground};
5560
border-radius: 50%;
56-
width: 28px;
57-
height: 28px;
61+
width: ${props => props.width + 10}px;
62+
height: ${props => props.width + 10}px;
5863
font-size: 28px;
5964
line-height: 28px;
6065
text-decoration: none;

src/browser/custom.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,37 @@ declare module '*.svg' {
22
const content: string
33
export default content
44
}
5+
6+
declare module 'react-suber' {
7+
interface BusProps {
8+
bus: Bus
9+
}
10+
const withBus: (comp: any) => React.ComponentType
11+
const BusProvider: React.ComponentType
12+
export { withBus, BusProvider, BusProps }
13+
}
14+
15+
declare module 'suber' {
16+
type UnsubscribeFn = () => void
17+
type FilterFn = (data: any) => boolean
18+
type MessageHandler = (message: any) => void
19+
20+
interface Bus {
21+
take: (
22+
channel: string,
23+
fn: MessageHandler,
24+
filterFn?: FilterFn
25+
) => UnsubscribeFn
26+
one: (
27+
channel: string,
28+
fn: MessageHandler,
29+
filterFn?: FilterFn
30+
) => UnsubscribeFn
31+
send: (channel: string, message: any, source?: string) => void
32+
self: (channel: string, message: any, fn: MessageHandler) => void
33+
reset: () => void
34+
}
35+
36+
const createBus: () => Bus
37+
export { Bus, createBus }
38+
}

src/browser/modules/Editor/ActionButtons.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ActionButtonSection } from './styled'
2323
import { EditorButton } from 'browser-components/buttons'
2424
interface ActionButtonProps {
2525
buttons: ActionButton[]
26+
width?: number
2627
}
2728

2829
interface ActionButton {
@@ -33,8 +34,8 @@ interface ActionButton {
3334
iconColor?: string
3435
}
3536

36-
const ActionButtons: React.FC<ActionButtonProps> = ({ buttons }) => (
37-
<ActionButtonSection containerWidth={buttons.length * 33}>
37+
const ActionButtons = ({ buttons, width = 24 }: ActionButtonProps) => (
38+
<ActionButtonSection>
3839
{buttons.map((btn: ActionButton) => (
3940
<EditorButton
4041
data-testid={`editor${btn.title}`}
@@ -44,6 +45,7 @@ const ActionButtons: React.FC<ActionButtonProps> = ({ buttons }) => (
4445
icon={btn.icon}
4546
key={`editor${btn.title}`}
4647
color={btn.iconColor}
48+
width={width}
4749
/>
4850
))}
4951
</ActionButtonSection>

src/browser/modules/Editor/Editor.jsx

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
} from 'shared/modules/settings/settingsDuck'
4545
import { add } from 'shared/modules/stream/streamDuck'
4646
import { Bar, ActionButtonSection, EditorWrapper, Header } from './styled'
47-
import { EditorButton, EditModeEditorButton } from 'browser-components/buttons'
4847
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
4948
import { deepEquals, shallowEquals } from 'services/utils'
5049
import * as viewTypes from 'shared/modules/stream/frameViewTypes'
@@ -80,7 +79,6 @@ export class Editor extends Component {
8079
buffer: '',
8180
mode: 'cypher',
8281
notifications: [],
83-
expanded: false,
8482
lastPosition: { line: 0, column: 0 },
8583
contentId: null,
8684
editorHeight: 0
@@ -95,17 +93,16 @@ export class Editor extends Component {
9593
this.setEditorValue(msg.message)
9694
})
9795
this.props.bus.take(FOCUS, this.focusEditor.bind(this))
98-
this.props.bus.take(EXPAND, this.expandEditorToggle.bind(this))
9996
}
10097
}
10198

10299
shouldComponentUpdate(nextProps, nextState) {
103100
return !(
104-
nextState.expanded === this.state.expanded &&
105101
nextState.contentId === this.state.contentId &&
106102
nextState.editorHeight === this.state.editorHeight &&
107103
shallowEquals(nextState.notifications, this.state.notifications) &&
108104
deepEquals(nextProps.schema, this.props.schema) &&
105+
nextProps.editorSize === this.props.editorSize &&
109106
nextProps.useDb === this.props.useDb &&
110107
nextProps.enableMultiStatementMode === this.props.enableMultiStatementMode
111108
)
@@ -116,17 +113,13 @@ export class Editor extends Component {
116113
this.codeMirror.setCursor(this.codeMirror.lineCount(), 0)
117114
}
118115

119-
expandEditorToggle() {
120-
this.setState({ expanded: !this.state.expanded })
121-
}
122-
123116
clearEditor = () => {
124117
this.setEditorValue('')
125118
this.setContentId(null)
126119
}
127120

128121
handleEnter(cm) {
129-
const multiline = cm.lineCount() !== 1 || this.state.expanded
122+
const multiline = this.props.editorSize !== 'LINE'
130123
if (multiline) {
131124
this.newlineAndIndent(cm)
132125
} else {
@@ -152,9 +145,9 @@ export class Editor extends Component {
152145
this.setState({
153146
notifications: [],
154147
historyIndex: -1,
155-
buffer: null,
156-
expanded: false
148+
buffer: null
157149
})
150+
this.props.setSize('LINE')
158151
}
159152
}
160153

@@ -255,6 +248,9 @@ export class Editor extends Component {
255248
console.log(e)
256249
}
257250
})
251+
if (this.props.editorRef) {
252+
this.props.editorRef.current = this.codeMirror
253+
}
258254
}
259255

260256
getEditorValue() {
@@ -400,8 +396,8 @@ export class Editor extends Component {
400396
}
401397

402398
lineNumberFormatter = line => {
403-
const multiLine = this.codeMirror && this.codeMirror.lineCount() > 1
404-
if (this.state.expanded || multiLine) {
399+
const multiline = this.props.editorSize !== 'LINE'
400+
if (multiline) {
405401
return line
406402
} else {
407403
return `${this.props.useDb || ''}$`
@@ -417,6 +413,13 @@ export class Editor extends Component {
417413
}
418414
}
419415

416+
goToCard(cm) {
417+
this.newlineAndIndent(cm)
418+
if (this.props.editorSize === 'LINE') {
419+
this.props.setSize('CARD')
420+
}
421+
}
422+
420423
render(cm) {
421424
const options = {
422425
lineNumbers: true,
@@ -431,7 +434,7 @@ export class Editor extends Component {
431434
extraKeys: {
432435
'Ctrl-Space': 'autocomplete',
433436
Enter: this.handleEnter.bind(this),
434-
'Shift-Enter': this.newlineAndIndent.bind(this),
437+
'Shift-Enter': this.goToCard.bind(this),
435438
'Cmd-Enter': this.execCurrent.bind(this),
436439
'Ctrl-Enter': this.execCurrent.bind(this),
437440
'Cmd-Up': this.historyPrev.bind(this),
@@ -461,12 +464,6 @@ export class Editor extends Component {
461464

462465
const editorIsEmpty = this.getEditorValue().length > 0
463466
const buttons = [
464-
{
465-
onClick: () => this.setEditorValue(''),
466-
icon: eraser2,
467-
title: 'Clear',
468-
disabled: editorIsEmpty
469-
},
470467
{
471468
onClick: this.state.contentId
472469
? () =>
@@ -486,18 +483,20 @@ export class Editor extends Component {
486483
onClick: this.execCurrent,
487484
icon: controlsPlay,
488485
title: 'Play',
489-
disabled: editorIsEmpty
486+
disabled: editorIsEmpty,
487+
iconColor: this.props.theme.linkHover
490488
}
491489
]
492490

493-
const cardView = this.codeMirror && this.codeMirror.lineCount() !== 1
491+
const isFullscreen = this.props.editorSize === 'FULLSCREEN'
492+
const isCardSize = this.props.editorSize === 'CARD'
494493

495494
return (
496-
<Bar expanded={this.state.expanded} card={cardView}>
497-
<Header expanded={this.state.expanded} card={cardView}>
498-
<ActionButtons buttons={buttons} />
495+
<Bar>
496+
<Header>
497+
<ActionButtons width={15} buttons={buttons} />
499498
</Header>
500-
<EditorWrapper expanded={this.state.expanded} card={cardView}>
499+
<EditorWrapper fullscreen={isFullscreen} cardSize={isCardSize}>
501500
<Codemirror
502501
ref={ref => {
503502
this.editor = ref

0 commit comments

Comments
 (0)