-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frame header #1159
Frame header #1159
Changes from all commits
e67cdeb
5cbfffd
fcf4f90
91098cc
f5b66fe
884e4a0
ae4ecfe
dd7c977
2225823
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,11 +33,16 @@ export const CloseButton = props => { | |
} | ||
|
||
export const EditorButton = props => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the editorbuttons flexible in size |
||
const { icon, title, color, ...rest } = props | ||
const { icon, title, color, width, ...rest } = props | ||
const overrideColor = { ...(color ? { color } : {}) } | ||
return ( | ||
<BaseButton title={title} style={overrideColor}> | ||
<SVGInline svg={icon} accessibilityLabel={title} {...rest} width="24px" /> | ||
<BaseButton title={title} style={overrideColor} width={width}> | ||
<SVGInline | ||
svg={icon} | ||
accessibilityLabel={title} | ||
{...rest} | ||
width={`${width}px`} | ||
/> | ||
</BaseButton> | ||
) | ||
} | ||
|
@@ -53,8 +58,8 @@ const BaseButton = styled.span` | |
color: ${props => props.theme.secondaryButtonText}; | ||
background-color: ${props => props.theme.secondaryButtonBackground}; | ||
border-radius: 50%; | ||
width: 28px; | ||
height: 28px; | ||
width: ${props => props.width + 10}px; | ||
height: ${props => props.width + 10}px; | ||
font-size: 28px; | ||
line-height: 28px; | ||
text-decoration: none; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,37 @@ declare module '*.svg' { | |
const content: string | ||
export default content | ||
} | ||
|
||
declare module 'react-suber' { | ||
interface BusProps { | ||
bus: Bus | ||
} | ||
const withBus: (comp: any) => React.ComponentType | ||
const BusProvider: React.ComponentType | ||
export { withBus, BusProvider, BusProps } | ||
} | ||
|
||
declare module 'suber' { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a start for typing up suber and react-suber. Some of the |
||
type UnsubscribeFn = () => void | ||
type FilterFn = (data: any) => boolean | ||
type MessageHandler = (message: any) => void | ||
|
||
interface Bus { | ||
take: ( | ||
channel: string, | ||
fn: MessageHandler, | ||
filterFn?: FilterFn | ||
) => UnsubscribeFn | ||
one: ( | ||
channel: string, | ||
fn: MessageHandler, | ||
filterFn?: FilterFn | ||
) => UnsubscribeFn | ||
send: (channel: string, message: any, source?: string) => void | ||
self: (channel: string, message: any, fn: MessageHandler) => void | ||
reset: () => void | ||
} | ||
|
||
const createBus: () => Bus | ||
export { Bus, createBus } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import { ActionButtonSection } from './styled' | |
import { EditorButton } from 'browser-components/buttons' | ||
interface ActionButtonProps { | ||
buttons: ActionButton[] | ||
width?: number | ||
} | ||
|
||
interface ActionButton { | ||
|
@@ -33,8 +34,8 @@ interface ActionButton { | |
iconColor?: string | ||
} | ||
|
||
const ActionButtons: React.FC<ActionButtonProps> = ({ buttons }) => ( | ||
<ActionButtonSection containerWidth={buttons.length * 33}> | ||
const ActionButtons = ({ buttons, width = 24 }: ActionButtonProps) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved away from React.FC after reading this: facebook/create-react-app#8177 |
||
<ActionButtonSection> | ||
{buttons.map((btn: ActionButton) => ( | ||
<EditorButton | ||
data-testid={`editor${btn.title}`} | ||
|
@@ -44,6 +45,7 @@ const ActionButtons: React.FC<ActionButtonProps> = ({ buttons }) => ( | |
icon={btn.icon} | ||
key={`editor${btn.title}`} | ||
color={btn.iconColor} | ||
width={width} | ||
/> | ||
))} | ||
</ActionButtonSection> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ import { | |
} from 'shared/modules/settings/settingsDuck' | ||
import { add } from 'shared/modules/stream/streamDuck' | ||
import { Bar, ActionButtonSection, EditorWrapper, Header } from './styled' | ||
import { EditorButton, EditModeEditorButton } from 'browser-components/buttons' | ||
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck' | ||
import { deepEquals, shallowEquals } from 'services/utils' | ||
import * as viewTypes from 'shared/modules/stream/frameViewTypes' | ||
|
@@ -80,7 +79,6 @@ export class Editor extends Component { | |
buffer: '', | ||
mode: 'cypher', | ||
notifications: [], | ||
expanded: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. full screen state lifted to new component |
||
lastPosition: { line: 0, column: 0 }, | ||
contentId: null, | ||
editorHeight: 0 | ||
|
@@ -95,17 +93,16 @@ export class Editor extends Component { | |
this.setEditorValue(msg.message) | ||
}) | ||
this.props.bus.take(FOCUS, this.focusEditor.bind(this)) | ||
this.props.bus.take(EXPAND, this.expandEditorToggle.bind(this)) | ||
} | ||
} | ||
|
||
shouldComponentUpdate(nextProps, nextState) { | ||
return !( | ||
nextState.expanded === this.state.expanded && | ||
nextState.contentId === this.state.contentId && | ||
nextState.editorHeight === this.state.editorHeight && | ||
shallowEquals(nextState.notifications, this.state.notifications) && | ||
deepEquals(nextProps.schema, this.props.schema) && | ||
nextProps.editorSize === this.props.editorSize && | ||
nextProps.useDb === this.props.useDb && | ||
nextProps.enableMultiStatementMode === this.props.enableMultiStatementMode | ||
) | ||
|
@@ -116,17 +113,13 @@ export class Editor extends Component { | |
this.codeMirror.setCursor(this.codeMirror.lineCount(), 0) | ||
} | ||
|
||
expandEditorToggle() { | ||
this.setState({ expanded: !this.state.expanded }) | ||
} | ||
|
||
clearEditor = () => { | ||
this.setEditorValue('') | ||
this.setContentId(null) | ||
} | ||
|
||
handleEnter(cm) { | ||
const multiline = cm.lineCount() !== 1 || this.state.expanded | ||
const multiline = this.props.editorSize !== 'LINE' | ||
if (multiline) { | ||
this.newlineAndIndent(cm) | ||
} else { | ||
|
@@ -152,9 +145,9 @@ export class Editor extends Component { | |
this.setState({ | ||
notifications: [], | ||
historyIndex: -1, | ||
buffer: null, | ||
expanded: false | ||
buffer: null | ||
}) | ||
this.props.setSize('LINE') | ||
} | ||
} | ||
|
||
|
@@ -255,6 +248,9 @@ export class Editor extends Component { | |
console.log(e) | ||
} | ||
}) | ||
if (this.props.editorRef) { | ||
this.props.editorRef.current = this.codeMirror | ||
} | ||
} | ||
|
||
getEditorValue() { | ||
|
@@ -400,8 +396,8 @@ export class Editor extends Component { | |
} | ||
|
||
lineNumberFormatter = line => { | ||
const multiLine = this.codeMirror && this.codeMirror.lineCount() > 1 | ||
if (this.state.expanded || multiLine) { | ||
const multiline = this.props.editorSize !== 'LINE' | ||
if (multiline) { | ||
return line | ||
} else { | ||
return `${this.props.useDb || ''}$` | ||
|
@@ -417,6 +413,13 @@ export class Editor extends Component { | |
} | ||
} | ||
|
||
goToCard(cm) { | ||
this.newlineAndIndent(cm) | ||
if (this.props.editorSize === 'LINE') { | ||
this.props.setSize('CARD') | ||
} | ||
} | ||
|
||
render(cm) { | ||
const options = { | ||
lineNumbers: true, | ||
|
@@ -431,7 +434,7 @@ export class Editor extends Component { | |
extraKeys: { | ||
'Ctrl-Space': 'autocomplete', | ||
Enter: this.handleEnter.bind(this), | ||
'Shift-Enter': this.newlineAndIndent.bind(this), | ||
'Shift-Enter': this.goToCard.bind(this), | ||
'Cmd-Enter': this.execCurrent.bind(this), | ||
'Ctrl-Enter': this.execCurrent.bind(this), | ||
'Cmd-Up': this.historyPrev.bind(this), | ||
|
@@ -461,12 +464,6 @@ export class Editor extends Component { | |
|
||
const editorIsEmpty = this.getEditorValue().length > 0 | ||
const buttons = [ | ||
{ | ||
onClick: () => this.setEditorValue(''), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Erasor removed in favor of discard button (the x) |
||
icon: eraser2, | ||
title: 'Clear', | ||
disabled: editorIsEmpty | ||
}, | ||
{ | ||
onClick: this.state.contentId | ||
? () => | ||
|
@@ -486,18 +483,20 @@ export class Editor extends Component { | |
onClick: this.execCurrent, | ||
icon: controlsPlay, | ||
title: 'Play', | ||
disabled: editorIsEmpty | ||
disabled: editorIsEmpty, | ||
iconColor: this.props.theme.linkHover | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Liza suggested this be blue |
||
} | ||
] | ||
|
||
const cardView = this.codeMirror && this.codeMirror.lineCount() !== 1 | ||
const isFullscreen = this.props.editorSize === 'FULLSCREEN' | ||
const isCardSize = this.props.editorSize === 'CARD' | ||
|
||
return ( | ||
<Bar expanded={this.state.expanded} card={cardView}> | ||
<Header expanded={this.state.expanded} card={cardView}> | ||
<ActionButtons buttons={buttons} /> | ||
<Bar> | ||
<Header> | ||
<ActionButtons width={15} buttons={buttons} /> | ||
</Header> | ||
<EditorWrapper expanded={this.state.expanded} card={cardView}> | ||
<EditorWrapper fullscreen={isFullscreen} cardSize={isCardSize}> | ||
<Codemirror | ||
ref={ref => { | ||
this.editor = ref | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up for discussion if we want to keep this, I liked not needing to write return type on components mostly.