From 21447d22a1e73e46d6e2b35b1e8fd731ec77613c Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 13 Mar 2018 13:04:55 +0200 Subject: [PATCH] chore: fix lint issues --- demo/ComboBox.tsx | 51 ++++++++++++++++-------------- demo/index.tsx | 12 +++---- src/components/ApiLogo/ApiLogo.tsx | 2 +- src/components/StoreProvider.ts | 2 +- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/demo/ComboBox.tsx b/demo/ComboBox.tsx index 819e7d320f..4f18e45740 100644 --- a/demo/ComboBox.tsx +++ b/demo/ComboBox.tsx @@ -19,7 +19,7 @@ const DropDownItem = withProps<{ active: boolean }>(styled.li)` background-color: #eee; } cursor: pointer; - text-overflow: ellipsis; + text-overflow: ellipsis; overflow: hidden; `; @@ -93,7 +93,7 @@ const Button = styled.button` export interface ComboBoxProps { onChange?: (val: string) => void; - options: { value: string; label: string }[]; + options: Array<{ value: string; label: string }>; placeholder?: string; value?: string; } @@ -142,6 +142,10 @@ export default class ComboBox extends React.Component { + this.handleSelect(this.state.value); + }; + handleKeyPress = (e: React.KeyboardEvent) => { if (e.keyCode === 13) { this.handleSelect(e.currentTarget.value); @@ -176,8 +180,27 @@ export default class ComboBox extends React.Component { + return ( + { + this.handleItemClick(option.value, idx); + }} + > + + {option.label} + +
+ {option.value} +
+ ); + }; + render() { - const { open, value, activeItemIdx } = this.state; + const { open, value } = this.state; const { options, placeholder } = this.props; return ( @@ -189,26 +212,8 @@ export default class ComboBox extends React.Component - - {open && ( - - {options.map((option, idx) => ( - { - this.handleItemClick(option.value, idx); - }} - > - - {option.label} - -
- {option.value} -
- ))} -
- )} + + {open && {options.map(this.renderOption)}}
); } diff --git a/demo/index.tsx b/demo/index.tsx index 9297811e4f..97c0abcf2f 100644 --- a/demo/index.tsx +++ b/demo/index.tsx @@ -1,9 +1,9 @@ import * as React from 'react'; import { render } from 'react-dom'; import styled from 'styled-components'; +import { resolve as urlResolve } from 'url'; import { RedocStandalone } from '../'; import ComboBox from './ComboBox'; -import * as url from 'url'; const demos = [ { value: 'https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml', label: 'Instagram' }, @@ -61,7 +61,7 @@ class DemoApp extends React.Component< toggleCors = (e: React.ChangeEvent) => { const cors = e.currentTarget.checked; this.setState({ - cors: cors, + cors, }); window.history.pushState( undefined, @@ -75,7 +75,7 @@ class DemoApp extends React.Component< let proxiedUrl = specUrl; if (specUrl !== DEFAULT_SPEC) { proxiedUrl = cors - ? '\\\\cors.apis.guru/' + url.resolve(window.location.href, specUrl) + ? '\\\\cors.apis.guru/' + urlResolve(window.location.href, specUrl) : specUrl; } return ( @@ -155,7 +155,7 @@ render(, document.getElementById('container')); /* ====== Helpers ====== */ function updateQueryStringParameter(uri, key, value) { const keyValue = value === '' ? key : key + '=' + value; - var re = new RegExp('([?|&])' + key + '=?.*?(&|#|$)', 'i'); + const re = new RegExp('([?|&])' + key + '=?.*?(&|#|$)', 'i'); if (uri.match(re)) { if (value !== undefined) { return uri.replace(re, '$1' + keyValue + '$2'); @@ -171,12 +171,12 @@ function updateQueryStringParameter(uri, key, value) { if (value === undefined) { return uri; } - var hash = ''; + let hash = ''; if (uri.indexOf('#') !== -1) { hash = uri.replace(/.*#/, '#'); uri = uri.replace(/#.*/, ''); } - var separator = uri.indexOf('?') !== -1 ? '&' : '?'; + const separator = uri.indexOf('?') !== -1 ? '&' : '?'; return uri + separator + keyValue + hash; } } diff --git a/src/components/ApiLogo/ApiLogo.tsx b/src/components/ApiLogo/ApiLogo.tsx index fdf2b60ded..d08b2b4b2a 100644 --- a/src/components/ApiLogo/ApiLogo.tsx +++ b/src/components/ApiLogo/ApiLogo.tsx @@ -1,7 +1,7 @@ import { observer } from 'mobx-react'; import * as React from 'react'; import { OpenAPIInfo } from '../../types'; -import { LogoImgEl, LogoWrap, LinkWrap } from './styled.elements'; +import { LinkWrap, LogoImgEl, LogoWrap } from './styled.elements'; @observer export class ApiLogo extends React.Component<{ info: OpenAPIInfo }> { diff --git a/src/components/StoreProvider.ts b/src/components/StoreProvider.ts index 1bb3547736..09d7749022 100644 --- a/src/components/StoreProvider.ts +++ b/src/components/StoreProvider.ts @@ -2,8 +2,8 @@ import { Component } from 'react'; import { AppStore } from '../services/'; import { RedocRawOptions } from '../services/RedocNormalizedOptions'; -import { loadAndBundleSpec } from '../utils'; import { OpenAPISpec } from '../types'; +import { loadAndBundleSpec } from '../utils'; interface StoreProviderProps { specUrl?: string;