Skip to content

Commit

Permalink
fix(region): remove deprecated/erroring regions API call
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed May 31, 2018
1 parent cf2c7c6 commit 5dd8d6b
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions lib/public/components/RegionSearch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { PropTypes } from 'react'
import fetch from 'isomorphic-fetch'
import { Glyphicon } from 'react-bootstrap'
import { shallowEqual } from 'react-pure-render'
import Select from 'react-select'
Expand Down Expand Up @@ -29,38 +28,44 @@ export default class RegionSearch extends React.Component {
}

getOptions = (input) => {
const entities = typeof this.props.entities !== 'undefined' ? this.props.entities : ['regions', 'feeds']
const {entities, feeds} = this.props
const entitiesToSearch = typeof entities !== 'undefined'
? entities
: ['regions', 'feeds']
const entitySearches = []
if (entities.indexOf('regions') > -1) {
entitySearches.push(this.getRegions(input))
if (entitiesToSearch.indexOf('regions') > -1) {
// TODO: Regions endpoint is no longer active. Remove this code entirely?
// entitySearches.push(this.getRegions(input))
}
if (entities.indexOf('feeds') > -1) {
if (entitiesToSearch.indexOf('feeds') > -1) {
// entitySearches.push(getFeeds(input))
}
return Promise.all(entitySearches).then((results) => {
const regions = results[0]
const feeds = this.props.feeds ? this.props.feeds.map(feed => ({feed, value: feed.feed_id, label: feed.name})) : []
// const feeds = typeof results[1] !== 'undefined' ? results[1] : []
const options = { options: [...regions, ...feeds] }
const feedOptions = feeds
? feeds.map(feed => ({feed, value: feed.feed_id, label: feed.name}))
: []
// const feeds = typeof results[1] !== 'undefined' ? results[1] : []
const options = { options: [...regions, ...feedOptions] }
return options
})
}

getRegions = (input) => {
const url = `/api/manager/public/region`
return fetch(url)
.then((response) => {
return response.json()
})
.then((regions) => {
const regionOptions = regions !== null && regions.length > 0 ? regions.map(region => ({region, value: region.id, label: `${region.name}`})) : []
return regionOptions
})
.catch((error) => {
console.log(error)
return []
})
}
// getRegions = (input) => {
// const url = `/api/manager/public/region`
// return fetch(url)
// .then((response) => {
// return response.json()
// })
// .then((regions) => {
// const regionOptions = regions !== null && regions.length > 0 ? regions.map(region => ({region, value: region.id, label: `${region.name}`})) : []
// return regionOptions
// })
// .catch((error) => {
// console.log(error)
// return []
// })
// }

renderOption (option) {
return (
Expand Down

0 comments on commit 5dd8d6b

Please # to comment.