Skip to content

Commit f186fa7

Browse files
committed
fix: load countries without region and multiple slugs
1 parent 0002fe9 commit f186fa7

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

src/views/DashboardView.vue

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,43 @@ const fetchCountries = async () => {
113113
// Filter for Africa and Central America
114114
const validRegions = ['africa', 'central-america', 'asia', 'europe', 'north-america','south-america', 'australia-oceania'];
115115
const filteredCountries = Object.entries(data)
116-
.filter(([_, val]) => validRegions.includes(val.region) || val.slug === 'central-america')
117-
.map(([code, val]) => ({
118-
value: code.toLowerCase(),
119-
label: val.name || (val.slug.charAt(0).toUpperCase() + val.slug.slice(1))
120-
}))
116+
.filter(([code, val]) => {
117+
if (!val) return false;
118+
119+
if (code === 'RUS' || code === 'USA' || code === 'FRA') {
120+
console.log(`Checking ${code}:`, val);
121+
console.log(`Region Array? ${Array.isArray(val.region)}`);
122+
console.log(`Region Value: ${val.region}`);
123+
}
124+
// 1. Handle Array Regions (e.g., USA: ['north-america', 'north-america/us'])
125+
if (Array.isArray(val.region)) {
126+
return val.region.some((r: string) => validRegions.includes(r));
127+
}
128+
// 2. Handle String Regions (Standard)
129+
if (val.region && validRegions.includes(val.region)) {
130+
return true;
131+
}
132+
// 3. Handle Special Cases / Missing Regions (e.g. Russia has no region but has slug)
133+
if (!val.region && val.slug) {
134+
return true; // Allow if it has a valid slug (e.g. Russia)
135+
}
136+
137+
return val.slug === 'central-america';
138+
})
139+
.map(([code, val]) => {
140+
// Handle Slug (can be string or array)
141+
const slug = Array.isArray(val.slug) ? val.slug[0] : val.slug;
142+
// Prefer explicit name, otherwise format specific slug
143+
let label = val.name;
144+
if (!label && slug) {
145+
label = slug.charAt(0).toUpperCase() + slug.slice(1);
146+
}
147+
148+
return {
149+
value: code.toLowerCase(),
150+
label: label || code
151+
};
152+
})
121153
.sort((a, b) => a.label.localeCompare(b.label));
122154
123155
countries.value = filteredCountries;

0 commit comments

Comments
 (0)