-
Notifications
You must be signed in to change notification settings - Fork 364
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
refactor: Made <RegionSelect />
more dynamic
#8996
refactor: Made <RegionSelect />
more dynamic
#8996
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values in this file allow us map any country
to a continent for the sake of grouping items in the <RegionSelect />
. Is this approach ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and this works π
1 failed tests on run #2966 βοΈ
Details:
Β cypress/e2e/general/smoke-deep-link.spec.ts β’ 1 failed test
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Didn't pull the code locally but just a couple suggestions you may or may not consider π
@@ -0,0 +1,267 @@ | |||
// Thank you https://github.com/BRIXTOL/country-continent | |||
|
|||
export const COUNTRY_CODE_TO_CONTINENT_CODE = Object.freeze({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but why not using readonly enums
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe if I used an enum, we wouldn't be able to do const continentCode = COUNTRY_CODE_TO_CONTINENT_CODE[country]
which is important because we need to be able to access the values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I am misunderstanding your intent, you can
export enum COUNTRY_CODE_TO_CONTINENT_CODE {
AD = 'EU',
AE = 'AS',
AF = 'AS',
AG = 'NA',
AI = 'NA',
AL = 'EU',
AM = 'AS',
...
};
const continentCode = COUNTRY_CODE_TO_CONTINENT_CODE['AE']
console.log(continentCode) // => AS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that totally works, my bad. Do you think an enum makes the most since here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're TS I'd say yes, but what you did works too. With a frozen object, you just need an extra type that refers to keyof the type of that object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to keep this format to maintain parity with the source package, but I'd be okay switching this to an enum if we need to in the future
|
||
.sort(sortRegions), | ||
}, | ||
for (const region of regions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a blocker at all but using reduce could be nicer? something like that
regions.reduce((acc, region) => {
const country = region.country.toUpperCase();
const continentCode = COUNTRY_CODE_TO_CONTINENT_CODE[
country as keyof typeof COUNTRY_CODE_TO_CONTINENT_CODE
];
const group = continentCode
? CONTINENT_CODE_TO_CONTINENT[continentCode] ?? 'Other'
: 'Other';
if (!acc[group]) {
acc[group] = [];
}
acc[group].push({
label: `${region.label} (${region.id})`,
value: region.id,
flag: <Flag country={region.country} />,
country: region.country,
});
return acc;
}, {});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll stick with the for loop for the readability and I think the time complexity is about the same
Description π
Why β
Changes
country
to a continent for grouping<RegionSelect />
component<RegionSelect />
to named exports<RegionSelect />
no longer depends on ramda π€How to test π§ͺ