feat(Try it out): Request editor in console mode redesigned

This commit is contained in:
Arian Rahimi 2020-01-20 17:31:39 +03:30
parent 705cea6a35
commit 13a3e76fc2
5 changed files with 99 additions and 27 deletions

View File

@ -9,12 +9,15 @@ export const Button = styled.button`
padding: 5px; padding: 5px;
`; `;
export const SendButton = styled(Button)` export const SubmitButton = styled(Button)`
background: #B0045E; background: ${props => props.theme.colors.primary.main}
`; padding: 10px 30px;
border-radius: 4px;
export const ConsoleButton = styled(Button)` cursor: pointer;
background: #e2e2e2; text-align: center;
color: black; outline: none;
float: right; margin: 1em 0;
min-width: 60px;
font-weight: bold;
order: 1;
`; `;

View File

@ -80,10 +80,6 @@ export const FlexLayout = styled.div`
width: 100%; width: 100%;
`; `;
export const ConsoleActionsRow = styled(FlexLayout)`
padding: 5px 0px;
`;
export const FlexLayoutReverse = styled(FlexLayout)` export const FlexLayoutReverse = styled(FlexLayout)`
flex-direction: row-reverse; flex-direction: row-reverse;
`; `;

View File

@ -8,7 +8,8 @@ import 'brace/mode/json';
import 'brace/theme/github'; import 'brace/theme/github';
import 'brace/theme/monokai'; import 'brace/theme/monokai';
import { MediaTypeModel } from '../../services/models'; import {MediaTypeModel} from '../../services/models';
import {ConsoleEditorWrapper} from './ConsoleEditorWrapper';
export interface ConsoleEditorProps { export interface ConsoleEditorProps {
mediaTypes: MediaTypeModel[]; mediaTypes: MediaTypeModel[];
@ -37,7 +38,7 @@ export class ConsoleEditor extends React.Component<ConsoleEditorProps> {
} }
return ( return (
<div> <ConsoleEditorWrapper>
<AceEditor <AceEditor
setOptions={{ setOptions={{
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
@ -46,17 +47,14 @@ export class ConsoleEditor extends React.Component<ConsoleEditorProps> {
showLineNumbers: true, showLineNumbers: true,
tabSize: 2, tabSize: 2,
}} }}
fontSize={10} fontSize={15}
mode="json" mode="json"
theme="monokai"
name="request-builder-editor" name="request-builder-editor"
editorProps={{ $blockScrolling: true }} editorProps={{ $blockScrolling: true }}
value={JSON.stringify(sample, null, 2)} value={JSON.stringify(sample, null, 2)}
ref={(ace: AceEditor) => (this.editor = ace)} ref={(ace: AceEditor) => (this.editor = ace)}
width="100%"
height="400px"
/> />
</div> </ConsoleEditorWrapper>
); );
} }

View File

@ -0,0 +1,75 @@
import {lighten} from 'polished';
import {styled} from '../../index';
export const ConsoleEditorWrapper = styled.div`
font-family: ${props => props.theme.typography.code.fontFamily};
font-size: ${props => props.theme.typography.code.fontSize} !important;
direction: ltr;
white-space: ${({ theme }) => (theme.typography.code.wrap ? 'pre-wrap' : 'pre')};
contain: content;
overflow-x: auto;
background: #11171a !important;
padding: 5px 0;
& .ace_editor {
background: #11171a !important;
width: 100% !important;
}
& .ace_editor .ace_marker-layer .ace_selection {
background: ${lighten(0.05, '#11171a')} !important;
}
& .ace_editor .ace_marker-layer .ace_active-line {
background: rgba(0, 0, 0, 0.2);
}
& .ace_editor .ace_line, & .ace_editor .ace_cursor {
color: #aaa;
}
& .ace_editor .ace_marker-layer .ace_bracket {
border: none !important;
}
& .ace_editor .ace_line .ace_fold {
background: none !important;
color: #aaa;
}
& .ace_editor .ace_line .ace_fold:hover {
background: none !important;
}
& .ace_editor .ace_string {
color: #71e4ff;
}
& .ace_editor .ace_variable {
color: #a0fbaa;
}
& .ace_editor .ace_indent-guide {
background: none;
color: rgba(255, 255, 255, 0.3)
}
& .ace_editor .ace_indent-guide::after {
content: "|";
}
& .ace_editor .ace_gutter {
background: ${lighten(0.01, '#11171a')} !important;
color: #fff !important;
}
& .ace_editor .ace_gutter .ace_fold-widget {
background-image: none;
}
& .ace_editor .ace_gutter .ace_fold-widget.ace_open::after {
content: "-";
}
& .ace_editor .ace_gutter .ace_fold-widget.ace_closed::after {
content: "+";
}
& .ace_editor .ace_gutter .ace_gutter-active-line {
background: rgba(0, 0, 0, 0.2) !important;
}
& .ace_editor .ace_gutter .ace_gutter-cell.ace_error {
background: none !important;
}
& .ace_editor .ace_gutter .ace_gutter-cell.ace_error::before {
position: absolute;
color: red;
content: "X";
left: 0.5em;
}
`;

View File

@ -1,7 +1,7 @@
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import * as React from 'react'; import * as React from 'react';
import { SendButton } from '../../common-elements/buttons'; import { SubmitButton } from '../../common-elements/buttons';
import { ConsoleActionsRow } from '../../common-elements/panels'; import { FlexLayoutReverse } from '../../common-elements/panels';
import { FieldModel, OperationModel } from '../../services/models'; import { FieldModel, OperationModel } from '../../services/models';
import { OpenAPISchema } from '../../types'; import { OpenAPISchema } from '../../types';
import { SourceCodeWithCopy } from '../SourceCode/SourceCode'; import { SourceCodeWithCopy } from '../SourceCode/SourceCode';
@ -30,7 +30,7 @@ export class ConsoleViewer extends React.Component<ConsoleViewerProps, ConsoleVi
operation: OperationModel; operation: OperationModel;
additionalHeaders: object; additionalHeaders: object;
visited = new Set(); visited = new Set();
private consoleEditor: ConsoleEditor; private consoleEditor: any;
constructor(props) { constructor(props) {
super(props); super(props);
@ -158,19 +158,19 @@ export class ConsoleViewer extends React.Component<ConsoleViewerProps, ConsoleVi
const { result } = this.state; const { result } = this.state;
return ( return (
<div> <div>
<h3> Console </h3> <h3> Request </h3>
{hasBodySample && ( {hasBodySample && (
<ConsoleEditor <ConsoleEditor
mediaTypes={mediaTypes} mediaTypes={mediaTypes}
ref={(editor: ConsoleEditor) => (this.consoleEditor = editor)} ref={(editor: any) => (this.consoleEditor = editor)}
/> />
)} )}
{false && samples.map(sample => ( {false && samples.map(sample => (
<SourceCodeWithCopy lang={sample.lang} source={sample.source} /> <SourceCodeWithCopy lang={sample.lang} source={sample.source} />
))} ))}
<ConsoleActionsRow> <FlexLayoutReverse>
<SendButton onClick={this.onClickSend} >Send Request</SendButton> <SubmitButton onClick={this.onClickSend} >Send Request</SubmitButton>
</ConsoleActionsRow> </FlexLayoutReverse>
{result && {result &&
<SourceCodeWithCopy lang="json" source={JSON.stringify(result, null, 2)} /> <SourceCodeWithCopy lang="json" source={JSON.stringify(result, null, 2)} />
} }