Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change the id from en:united-kingdom to en:uk #743

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/assets/countries.json
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@
"countryCode": "AE"
},
{
"id": "en:united-kingdom",
"id": "en:uk",
"label": "United Kingdom",
"languageCode": "en",
"countryCode": "UK"
Expand Down
14 changes: 8 additions & 6 deletions src/pages/eco-score/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SmallQuestionCard from "../../components/SmallQuestionCard";
import Opportunities from "../../components/Opportunities";
import { DEFAULT_FILTER_STATE } from "../../components/QuestionFilter/const";
import { useTranslation } from "react-i18next";
import { capitaliseName } from "../../utils";
import { getCountryName } from "../../utils";
import Loader from "../loader";

const ecoScoreCards = [
Expand Down Expand Up @@ -161,12 +161,14 @@ export const countryNames = [
"en:united-states",
"en:canada",
"en:australia",
"en:united-kingdom",
];
"en:uk",
].map((id) => ({ id, label: getCountryName(id) }));

export default function EcoScore() {
const { t } = useTranslation();
const [selectedCountry, setSelectedCountry] = React.useState(countryNames[0]);
const [selectedCountry, setSelectedCountry] = React.useState(
countryNames[0].id
);

return (
<React.Suspense fallback={<Loader />}>
Expand Down Expand Up @@ -202,8 +204,8 @@ export default function EcoScore() {
sx={{ width: 200 }}
>
{countryNames.map((country) => (
<MenuItem value={country} key={country}>
{capitaliseName(country)}
<MenuItem value={country.id} key={country.id}>
{country.label}
</MenuItem>
))}
</TextField>
Expand Down
13 changes: 13 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import counties from "./assets/countries.json";

const reformatTagMapping = {
" ": "-",
"'": "-",
Expand Down Expand Up @@ -50,3 +52,14 @@ export const capitaliseName = (string: string | undefined) => {
let name = string.slice(3);
return name.charAt(0).toUpperCase() + name.slice(1);
};

export const getCountryName = (countryId?: string) => {
if (!countryId) {
return "";
}
const country = counties.find((item) => item.id === countryId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

countries

if (!country) {
return "";
}
return country.label;
};