• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / fx-private-relay / 3f95e773-4285-4332-9493-3dd749e78fc4

13 Aug 2024 09:12AM CUT coverage: 85.408%. Remained the same
3f95e773-4285-4332-9493-3dd749e78fc4

push

circleci

web-flow
Merge pull request #4937 from mozilla/dependabot/pip/testing-libraries-22f8d21061

Bump model-bakery from 1.18.2 to 1.19.1 in the testing-libraries group

4100 of 5252 branches covered (78.07%)

Branch coverage included in aggregate %.

15970 of 18247 relevant lines covered (87.52%)

10.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/frontend/src/components/waitlist/CountryPicker.tsx
1
import { SelectHTMLAttributes, useEffect, useState } from "react";
×
2
import { getLocale } from "../../functions/getLocale";
×
3
import { useL10n } from "../../hooks/l10n";
×
4

5
type LocaleDisplayNames = Record<string, string>;
6
type Territories = {
7
  main: Record<
8
    string,
9
    {
10
      localeDisplayNames: {
11
        territories: LocaleDisplayNames;
12
      };
13
    }
14
  >;
15
};
16
export type Props = SelectHTMLAttributes<HTMLSelectElement>;
17
export const CountryPicker = (props: Props) => {
×
18
  const l10n = useL10n();
×
19
  const currentLocale = getLocale(l10n);
×
20
  const [localeDisplayNames, setLocaleDisplayNames] =
21
    useState<LocaleDisplayNames>();
×
22

23
  useEffect(() => {
×
24
    importTerritories(currentLocale).then((localeDisplayNames) => {
×
25
      setLocaleDisplayNames(localeDisplayNames);
×
26
    });
27
  }, [currentLocale]);
28

29
  const options = Object.entries(localeDisplayNames ?? {})
×
30
    // cldr-localenames-modern also includes names of continents,
31
    // whose territory codes consist of numbers.
32
    // (See e.g. node_modules/cldr-localenames-modern/main/en/territories.json.)
33
    // Since we're only interested in countries, filter those out:
34
    .filter(
35
      ([code]) =>
36
        !["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].some((nr) =>
×
37
          code.includes(nr),
×
38
        ),
39
    )
40
    .sort(([_codeA, nameA], [_codeB, nameB]) => nameA.localeCompare(nameB))
×
41
    .map(([code, name]) => (
42
      <option key={code} value={code}>
×
43
        {name}
44
      </option>
45
    ));
46

47
  return <select {...props}>{options}</select>;
48
};
49

50
async function importTerritories(locale: string): Promise<LocaleDisplayNames> {
51
  try {
×
52
    const territories: Territories = await import(
×
53
      `cldr-localenames-modern/main/${locale}/territories.json`
×
54
    );
55
    return territories.main[locale].localeDisplayNames.territories;
×
56
  } catch (_e) {
57
    try {
×
58
      // cldr-localenames-modern doesn't include suffixed locale codes for
59
      // locales in their main territory (i.e. it only has `es`, not `es-ES`, or
60
      // `nl` but not `nl-NL`, or `sv` but not `sv-SE`), so try loading a
61
      // truncated version if the full version was not found:
62
      const truncatedLocale = locale.split("-")[0];
×
63
      const territories: Territories = await import(
×
64
        `cldr-localenames-modern/main/${truncatedLocale}/territories.json`
×
65
      );
66
      return territories.main[truncatedLocale].localeDisplayNames.territories;
×
67
    } catch (_e) {
68
      const territoriesEn = await import(
×
69
        "cldr-localenames-modern/main/en/territories.json"
70
      );
71
      return territoriesEn.main.en.localeDisplayNames.territories;
×
72
    }
73
  }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc