Skip to content

Commit

Permalink
Transform countryCode to countryName
Browse files Browse the repository at this point in the history
  • Loading branch information
Joozty committed Oct 28, 2020
1 parent cc92a0f commit b7c5747
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@sentry/node": "^5.24.2",
"core-js": "^3.6.5",
"cssnano": "^4.1.10",
"i18n-iso-countries": "^6.2.2",
"leaflet": "^1.7.1",
"leaflet.markercluster": "^1.4.1",
"mobx": "^5.15.7",
Expand Down
28 changes: 15 additions & 13 deletions templates/data-providers/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useRef, useLayoutEffect } from 'react'
import { Button } from '@oacore/design'
import { countries } from 'i18n-iso-countries/langs/en.json'

import styles from './styles.module.css'
import DataProvidersSelect from './search'
Expand All @@ -10,6 +11,11 @@ import { formatNumber } from 'utils/format-number'
import Search from 'modules/search-layout'
import RepositoriesMap from 'modules/repositories-map'

const getCountryName = (code) => {
const countryName = countries[String(code).toUpperCase()]
return Array.isArray(countryName) ? countryName[0] : countryName
}

const useIsomorphicLayoutEffect =
typeof window !== 'undefined' ? useLayoutEffect : useEffect

Expand Down Expand Up @@ -37,19 +43,15 @@ const SearchResults = ({

return (
<Search.Results>
{results.slice(0, dataProvidersSize).map((el) => {
console.log(JSON.stringify(el))

return (
<ResultCard
key={el.id}
repoId={el.id}
title={el.name}
homePage={el.urlHomepage}
country={el.dataProviderLocation?.countryName || 'unknown location'}
/>
)
})}
{results.slice(0, dataProvidersSize).map((el) => (
<ResultCard
key={el.id}
repoId={el.id}
title={el.name}
homePage={el.urlHomepage}
country={getCountryName(el.dataProviderLocation?.countryCode)}
/>
))}
{dataProvidersSize < results.length && (
<Button
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion templates/data-providers/result-card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ResultCard = ({
{homePage}
</Link>
</li>
<li>{country}</li>
{country && <li>{country}</li>}
</ul>
</Search.Result>
)
Expand Down

0 comments on commit b7c5747

Please sign in to comment.