From 30b741e732b0d9171bbee3d5b2309de0019bbda2 Mon Sep 17 00:00:00 2001 From: Harjeet Singh Date: Tue, 8 May 2018 14:28:55 -0700 Subject: [PATCH] working with backend apis , content type was not set right, also added max height to response panel as some responses can be lengthy --- package.json | 12 ++++---- src/components/Console/ConsoleViewer.tsx | 9 +++--- src/components/SourceCode/SourceCode.tsx | 4 +-- src/theme.ts | 6 ++++ src/utils/fetch.ts | 38 +----------------------- 5 files changed, 20 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 592757f4..3a1022fc 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "@types/mark.js": "^8.11.1", "@types/marked": "^0.3.0", "@types/prismjs": "^1.6.4", + "@types/promise": "^7.1.30", "@types/prop-types": "^15.5.2", "@types/qs": "^6.5.1", "@types/react": "^16.0.41", @@ -71,6 +72,7 @@ "@types/react-tabs": "^1.0.2", "@types/webpack": "^4.1.2", "@types/webpack-env": "^1.13.0", + "@types/whatwg-fetch": "^0.0.33", "@types/yargs": "^11.0.0", "ajv": "^6.4.0", "ajv-errors": "^1.0.0", @@ -151,12 +153,10 @@ "@types/chai": "4.0.8", "@types/tapable": "1.0.0" }, - "bundlesize": [ - { - "path": "./bundles/redoc.standalone.js", - "maxSize": "300 kB" - } - ], + "bundlesize": [{ + "path": "./bundles/redoc.standalone.js", + "maxSize": "300 kB" + }], "jest": { "transform": { "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" diff --git a/src/components/Console/ConsoleViewer.tsx b/src/components/Console/ConsoleViewer.tsx index afba7dc0..9e2a0127 100644 --- a/src/components/Console/ConsoleViewer.tsx +++ b/src/components/Console/ConsoleViewer.tsx @@ -55,7 +55,8 @@ export class ConsoleViewer extends React.Component props.theme.responsePanel}; const StyledPre = styled.pre` font-family: ${props => props.theme.code.fontFamily}; font-size: ${props => props.theme.code.fontSize}; overflow-x: auto; margin: 0; - + max-height: ${props => props.theme.styledPre.maxHeight}; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; diff --git a/src/theme.ts b/src/theme.ts index ae0b53f9..4711efe5 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -65,6 +65,9 @@ const defaultTheme: ThemeInterface = { backgroundColor: '#263238', width: '40%', }, + styledPre: { + maxHeight: '500px' + }, }; export default defaultTheme; @@ -168,6 +171,9 @@ export interface ResolvedThemeInterface { backgroundColor: string; width: string; }; + styledPre: { + maxHeight: string; + } } export type primitive = string | number | boolean | undefined | null; diff --git a/src/utils/fetch.ts b/src/utils/fetch.ts index 590f8e44..835e785a 100644 --- a/src/utils/fetch.ts +++ b/src/utils/fetch.ts @@ -1,37 +1 @@ -import { Promise } from "core-js"; - -export class Fetch { - - - execute(): Promise> { - return fetch('https://api.github.com/orgs/lemoncode/members') - .then((response) => this.checkStatus(response)) - .then((response) => this.parseJSON(response) - .then((response) => { return Promise.resolve(this._parse(response)) }) - .catch((error) => this.throwError(error)) - ); - } - - private checkStatus(response: Response): Promise { - if (response.status >= 200 && response.status < 300) { - return Promise.resolve(response); - } else { - let error = new Error(response.statusText); - throw error; - } - } - - private parseJSON(response: Response): Promise { - return response.json(); - } - - private _parse(data) { - return data; - } - - private throwError(error) { - document.write("

Ops! something wrong! We are so embarrased..

"); - console.log(error); - return Promise.reject(error); - } -} \ No newline at end of file +parseparseFetchFetch \ No newline at end of file