Skip to content

Commit

Permalink
docs(Search): replace deprecated lifecycle methods in examples (#3511)
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored Mar 17, 2019
1 parent 68932ca commit 3ab3bac
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import React from 'react'
import SourceRender from 'react-source-render'

import { updateForKeys } from 'docs/src/hoc'
import SearchExampleStandard from 'docs/src/examples/modules/Search/Types/SearchExampleStandard'
import SearchExampleCategory from 'docs/src/examples/modules/Search/Types/SearchExampleCategory'
import { babelConfig, externals } from './renderConfig'

const resolver = (importPath, { displayName }) => {
if (externals[importPath]) return externals[importPath]

if (_.endsWith(importPath, '/SearchExampleCategory')) return SearchExampleCategory
if (_.endsWith(importPath, '/SearchExampleStandard')) return SearchExampleStandard

throw new Error(
[
'An error in resolver(), please check that import is defined, details:',
Expand Down
22 changes: 13 additions & 9 deletions docs/src/examples/modules/Search/Types/SearchExampleCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import faker from 'faker'
import React, { Component } from 'react'
import { Search, Grid, Header, Segment } from 'semantic-ui-react'

const initialState = { isLoading: false, results: [], value: '' }

const getResults = () =>
_.times(5, () => ({
title: faker.company.companyName(),
Expand All @@ -24,19 +26,15 @@ const source = _.range(0, 3).reduce((memo) => {
}, {})

export default class SearchExampleCategory extends Component {
componentWillMount() {
this.resetComponent()
}

resetComponent = () => this.setState({ isLoading: false, results: [], value: '' })
state = initialState

handleResultSelect = (e, { result }) => this.setState({ value: result.title })

handleSearchChange = (e, { value }) => {
this.setState({ isLoading: true, value })

setTimeout(() => {
if (this.state.value.length < 1) return this.resetComponent()
if (this.state.value.length < 1) return this.setState(initialState)

const re = new RegExp(_.escapeRegExp(this.state.value), 'i')
const isMatch = result => re.test(result.title)
Expand Down Expand Up @@ -69,7 +67,9 @@ export default class SearchExampleCategory extends Component {
category
loading={isLoading}
onResultSelect={this.handleResultSelect}
onSearchChange={_.debounce(this.handleSearchChange, 500, { leading: true })}
onSearchChange={_.debounce(this.handleSearchChange, 500, {
leading: true,
})}
results={results}
value={value}
{...this.props}
Expand All @@ -78,9 +78,13 @@ export default class SearchExampleCategory extends Component {
<Grid.Column width={8}>
<Segment>
<Header>State</Header>
<pre style={{ overflowX: 'auto' }}>{JSON.stringify(this.state, null, 2)}</pre>
<pre style={{ overflowX: 'auto' }}>
{JSON.stringify(this.state, null, 2)}
</pre>
<Header>Options</Header>
<pre style={{ overflowX: 'auto' }}>{JSON.stringify(source, null, 2)}</pre>
<pre style={{ overflowX: 'auto' }}>
{JSON.stringify(source, null, 2)}
</pre>
</Segment>
</Grid.Column>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ resultRenderer.propTypes = {
description: PropTypes.string,
}

const initialState = { isLoading: false, results: [], value: '' }

const getResults = () =>
_.times(5, () => ({
title: faker.company.companyName(),
Expand All @@ -38,20 +40,15 @@ const source = _.range(0, 3).reduce((memo) => {
}, {})

export default class SearchExampleCategory extends Component {
componentWillMount() {
this.resetComponent()
}

resetComponent = () =>
this.setState({ isLoading: false, results: [], value: '' })
state = initialState

handleResultSelect = (e, { result }) => this.setState({ value: result.title })

handleSearchChange = (e, { value }) => {
this.setState({ isLoading: true, value })

setTimeout(() => {
if (this.state.value.length < 1) return this.resetComponent()
if (this.state.value.length < 1) return this.setState(initialState)

const re = new RegExp(_.escapeRegExp(this.state.value), 'i')
const isMatch = result => re.test(result.title)
Expand Down
22 changes: 13 additions & 9 deletions docs/src/examples/modules/Search/Types/SearchExampleStandard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import faker from 'faker'
import React, { Component } from 'react'
import { Search, Grid, Header, Segment } from 'semantic-ui-react'

const initialState = { isLoading: false, results: [], value: '' }

const source = _.times(5, () => ({
title: faker.company.companyName(),
description: faker.company.catchPhrase(),
Expand All @@ -11,19 +13,15 @@ const source = _.times(5, () => ({
}))

export default class SearchExampleStandard extends Component {
componentWillMount() {
this.resetComponent()
}

resetComponent = () => this.setState({ isLoading: false, results: [], value: '' })
state = initialState

handleResultSelect = (e, { result }) => this.setState({ value: result.title })

handleSearchChange = (e, { value }) => {
this.setState({ isLoading: true, value })

setTimeout(() => {
if (this.state.value.length < 1) return this.resetComponent()
if (this.state.value.length < 1) return this.setState(initialState)

const re = new RegExp(_.escapeRegExp(this.state.value), 'i')
const isMatch = result => re.test(result.title)
Expand All @@ -44,7 +42,9 @@ export default class SearchExampleStandard extends Component {
<Search
loading={isLoading}
onResultSelect={this.handleResultSelect}
onSearchChange={_.debounce(this.handleSearchChange, 500, { leading: true })}
onSearchChange={_.debounce(this.handleSearchChange, 500, {
leading: true,
})}
results={results}
value={value}
{...this.props}
Expand All @@ -53,9 +53,13 @@ export default class SearchExampleStandard extends Component {
<Grid.Column width={10}>
<Segment>
<Header>State</Header>
<pre style={{ overflowX: 'auto' }}>{JSON.stringify(this.state, null, 2)}</pre>
<pre style={{ overflowX: 'auto' }}>
{JSON.stringify(this.state, null, 2)}
</pre>
<Header>Options</Header>
<pre style={{ overflowX: 'auto' }}>{JSON.stringify(source, null, 2)}</pre>
<pre style={{ overflowX: 'auto' }}>
{JSON.stringify(source, null, 2)}
</pre>
</Segment>
</Grid.Column>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,18 @@ resultRenderer.propTypes = {
description: PropTypes.string,
}

export default class SearchExampleStandard extends Component {
componentWillMount() {
this.resetComponent()
}
const initialState = { isLoading: false, results: [], value: '' }

resetComponent = () =>
this.setState({ isLoading: false, results: [], value: '' })
export default class SearchExampleStandard extends Component {
state = initialState

handleResultSelect = (e, { result }) => this.setState({ value: result.title })

handleSearchChange = (e, { value }) => {
this.setState({ isLoading: true, value })

setTimeout(() => {
if (this.state.value.length < 1) return this.resetComponent()
if (this.state.value.length < 1) return this.setState(initialState)

const re = new RegExp(_.escapeRegExp(this.state.value), 'i')
const isMatch = result => re.test(result.title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ const source = _.times(5, () => ({
price: faker.finance.amount(0, 100, 2, '$'),
}))

export default class SearchExampleStandard extends Component {
componentWillMount() {
this.resetComponent()
}
const initialState = { isLoading: false, results: [], value: '' }

resetComponent = () =>
this.setState({ isLoading: false, results: [], value: '' })
export default class SearchExampleStandard extends Component {
state = initialState

handleResultSelect = (e, { result }) => this.setState({ value: result.title })

handleSearchChange = (e, { value }) => {
this.setState({ isLoading: true, value })

setTimeout(() => {
if (this.state.value.length < 1) return this.resetComponent()
if (this.state.value.length < 1) return this.setState(initialState)

const re = new RegExp(_.escapeRegExp(this.state.value), 'i')
const isMatch = result => re.test(result.title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ const source = _.times(5, () => ({
price: faker.finance.amount(0, 100, 2, '$'),
}))

export default class SearchExampleStandard extends Component {
componentWillMount() {
this.resetComponent()
}
const initialState = { isLoading: false, results: [], value: '' }

resetComponent = () =>
this.setState({ isLoading: false, results: [], value: '' })
export default class SearchExampleStandard extends Component {
state = initialState

handleResultSelect = (e, { result }) => this.setState({ value: result.title })

handleSearchChange = (e, { value }) => {
this.setState({ isLoading: true, value })

setTimeout(() => {
if (this.state.value.length < 1) return this.resetComponent()
if (this.state.value.length < 1) return this.setState(initialState)

const re = new RegExp(_.escapeRegExp(this.state.value), 'i')
const isMatch = result => re.test(result.title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ const source = _.times(5, () => ({
price: faker.finance.amount(0, 100, 2, '$'),
}))

export default class SearchExampleStandard extends Component {
componentWillMount() {
this.resetComponent()
}
const initialState = { isLoading: false, results: [], value: '' }

resetComponent = () =>
this.setState({ isLoading: false, results: [], value: '' })
export default class SearchExampleStandard extends Component {
state = initialState

handleResultSelect = (e, { result }) => this.setState({ value: result.title })

handleSearchChange = (e, { value }) => {
this.setState({ isLoading: true, value })

setTimeout(() => {
if (this.state.value.length < 1) return this.resetComponent()
if (this.state.value.length < 1) return this.setState(initialState)

const re = new RegExp(_.escapeRegExp(this.state.value), 'i')
const isMatch = result => re.test(result.title)
Expand Down

0 comments on commit 3ab3bac

Please sign in to comment.