Skip to content

Commit 716abdf

Browse files
committed
Adapt UI client to changes in the HTTP API
1 parent 03b5958 commit 716abdf

22 files changed

+99
-66
lines changed

web/src/api/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
import { get, patch, post } from "~/api/http";
24+
import { Config } from "~/types/config";
2425
import { Proposal } from "~/types/proposal";
2526
import { System } from "~/types/system";
2627

@@ -37,7 +38,7 @@ const fetchProposal = (): Promise<Proposal> => get("/api/v2/proposal");
3738
/**
3839
* Updates configuration
3940
*/
40-
const updateConfig = (config) => patch("/api/v2/config", { update: config });
41+
const updateConfig = (config: Config) => patch("/api/v2/config", { update: config });
4142
/**
4243
* Triggers an action
4344
*/

web/src/components/core/InstallerOptions.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const mockChangeUILanguage = jest.fn();
6060

6161
jest.mock("~/queries/system", () => ({
6262
...jest.requireActual("~/queries/system"),
63-
useSystem: () => ({ localization: { locales, keymaps, locale: "us_US.UTF-8", keymap: "us" } }),
63+
useSystem: () => ({ l10n: { locales, keymaps, locale: "us_US.UTF-8", keymap: "us" } }),
6464
}));
6565

6666
jest.mock("~/api/api", () => ({
@@ -188,7 +188,7 @@ describe("InstallerOptions", () => {
188188

189189
await user.click(acceptButton);
190190
expect(mockUpdateConfigFn).toHaveBeenCalledWith({
191-
localization: {
191+
l10n: {
192192
locale: "es_ES.UTF-8",
193193
keymap: "gb",
194194
},
@@ -309,7 +309,7 @@ describe("InstallerOptions", () => {
309309

310310
await user.click(acceptButton);
311311
expect(mockUpdateConfigFn).toHaveBeenCalledWith({
312-
localization: {
312+
l10n: {
313313
locale: "es_ES.UTF-8",
314314
},
315315
});
@@ -400,7 +400,7 @@ describe("InstallerOptions", () => {
400400

401401
await user.click(acceptButton);
402402
expect(mockUpdateConfigFn).toHaveBeenCalledWith({
403-
localization: {
403+
l10n: {
404404
keymap: "gb",
405405
},
406406
});

web/src/components/core/InstallerOptions.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const LangaugeFormInput = ({ value, onChange }: SelectProps) => (
8989
*/
9090
const KeyboardFormInput = ({ value, onChange }: SelectProps) => {
9191
const {
92-
localization: { keymaps },
92+
l10n: { keymaps },
9393
} = useSystem();
9494

9595
if (!localConnection()) {
@@ -553,7 +553,7 @@ export default function InstallerOptions({
553553
}: InstallerOptionsProps) {
554554
const location = useLocation();
555555
const {
556-
localization: { locales },
556+
l10n: { locales },
557557
} = useSystem();
558558
const { language, keymap, changeLanguage, changeKeymap } = useInstallerL10n();
559559
const { phase } = useInstallerStatus({ suspense: true });
@@ -593,7 +593,7 @@ export default function InstallerOptions({
593593
if (variant !== "keyboard") systemL10n.locale = systemLocale?.id;
594594
if (variant !== "language" && localConnection()) systemL10n.keymap = formState.keymap;
595595

596-
updateConfig({ localization: systemL10n });
596+
updateConfig({ l10n: systemL10n });
597597
};
598598

599599
const close = () => {

web/src/components/l10n/KeyboardSelection.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ jest.mock("~/components/product/ProductRegistrationAlert", () => () => (
4040

4141
jest.mock("~/queries/system", () => ({
4242
...jest.requireActual("~/queries/system"),
43-
useSystem: () => ({ localization: { keymaps } }),
43+
useSystem: () => ({ l10n: { keymaps } }),
4444
}));
4545

4646
jest.mock("~/queries/proposal", () => ({
4747
...jest.requireActual("~/queries/proposal"),
48-
useProposal: () => ({ localization: { keymap: "us" } }),
48+
useProposal: () => ({ l10n: { keymap: "us" } }),
4949
}));
5050

5151
jest.mock("~/api/api", () => ({
@@ -65,6 +65,6 @@ it("allows changing the keyboard", async () => {
6565
await userEvent.click(option);
6666
const button = await screen.findByRole("button", { name: "Select" });
6767
await userEvent.click(button);
68-
expect(mockUpdateConfigFn).toHaveBeenCalledWith({ localization: { keymap: "es" } });
68+
expect(mockUpdateConfigFn).toHaveBeenCalledWith({ l10n: { keymap: "es" } });
6969
expect(mockNavigateFn).toHaveBeenCalledWith(-1);
7070
});

web/src/components/l10n/KeyboardSelection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ import { _ } from "~/i18n";
3434
export default function KeyboardSelection() {
3535
const navigate = useNavigate();
3636
const {
37-
localization: { keymaps },
37+
l10n: { keymaps },
3838
} = useSystem();
3939
const {
40-
localization: { keymap: currentKeymap },
40+
l10n: { keymap: currentKeymap },
4141
} = useProposal();
4242

4343
// FIXME: get current keymap from either, proposal or config
@@ -51,7 +51,7 @@ export default function KeyboardSelection() {
5151
const onSubmit = async (e: React.SyntheticEvent) => {
5252
e.preventDefault();
5353
// FIXME: udpate when new API is ready
54-
updateConfig({ localization: { keymap: selected } });
54+
updateConfig({ l10n: { keymap: selected } });
5555
navigate(-1);
5656
};
5757

web/src/components/l10n/L10nPage.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ jest.mock("~/queries/proposal", () => ({
6161

6262
beforeEach(() => {
6363
mockSystemData = {
64-
localization: {
64+
l10n: {
6565
locales,
6666
keymaps,
6767
timezones,
6868
},
6969
};
7070

7171
mockProposedData = {
72-
localization: {
72+
l10n: {
7373
locales,
7474
keymaps,
7575
timezones,
@@ -96,7 +96,7 @@ it("renders a section for configuring the language", () => {
9696

9797
describe("if the language selected is wrong", () => {
9898
beforeEach(() => {
99-
mockProposedData.localization.locale = "us_US.UTF-8";
99+
mockProposedData.l10n.locale = "us_US.UTF-8";
100100
});
101101

102102
it("renders a button for selecting a language", () => {
@@ -116,7 +116,7 @@ it("renders a section for configuring the keyboard", () => {
116116

117117
describe("if the keyboard selected is wrong", () => {
118118
beforeEach(() => {
119-
mockProposedData.localization.keymap = "ess";
119+
mockProposedData.l10n.keymap = "ess";
120120
});
121121

122122
it("renders a button for selecting a keyboard", () => {
@@ -136,7 +136,7 @@ it("renders a section for configuring the time zone", () => {
136136

137137
describe("if the time zone selected is wrong", () => {
138138
beforeEach(() => {
139-
mockProposedData.localization.timezone = "Europee/Beeerlin";
139+
mockProposedData.l10n.timezone = "Europee/Beeerlin";
140140
});
141141

142142
it("renders a button for selecting a time zone", () => {

web/src/components/l10n/L10nPage.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ const InstallerL10nSettingsInfo = () => {
6868
*/
6969
export default function L10nPage() {
7070
// FIXME: retrieve selection from config when ready
71-
const { localization: l10nProposal } = useProposal();
72-
const { localization: l10n } = useSystem();
71+
const { l10n: l10nProposal } = useProposal();
72+
const { l10n: l10nSystem } = useSystem();
7373
console.log(l10nProposal);
7474

75-
const locale = l10nProposal.locale && l10n.locales.find((l) => l.id === l10nProposal.locale);
76-
const keymap = l10nProposal.keymap && l10n.keymaps.find((k) => k.id === l10nProposal.keymap);
75+
const locale =
76+
l10nProposal.locale && l10nSystem.locales.find((l) => l.id === l10nProposal.locale);
77+
const keymap =
78+
l10nProposal.keymap && l10nSystem.keymaps.find((k) => k.id === l10nProposal.keymap);
7779
const timezone =
78-
l10nProposal.timezone && l10n.timezones.find((t) => t.id === l10nProposal.timezone);
80+
l10nProposal.timezone && l10nSystem.timezones.find((t) => t.id === l10nProposal.timezone);
7981

8082
return (
8183
<Page>

web/src/components/l10n/LocaleSelection.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ jest.mock("~/components/product/ProductRegistrationAlert", () => () => (
4040

4141
jest.mock("~/queries/system", () => ({
4242
...jest.requireActual("~/queries/system"),
43-
useSystem: () => ({ localization: { locales } }),
43+
useSystem: () => ({ l10n: { locales } }),
4444
}));
4545

4646
jest.mock("~/queries/proposal", () => ({
4747
...jest.requireActual("~/queries/proposal"),
48-
useProposal: () => ({ localization: { locales, locale: "us_US.UTF-8", keymap: "us" } }),
48+
useProposal: () => ({ l10n: { locales, locale: "us_US.UTF-8", keymap: "us" } }),
4949
}));
5050

5151
jest.mock("~/api/api", () => ({
@@ -66,7 +66,7 @@ it("allows changing the keyboard", async () => {
6666
const button = await screen.findByRole("button", { name: "Select" });
6767
await userEvent.click(button);
6868
expect(mockUpdateConfigFn).toHaveBeenCalledWith({
69-
localization: { locale: "es_ES.UTF-8" },
69+
l10n: { locale: "es_ES.UTF-8" },
7070
});
7171
expect(mockNavigateFn).toHaveBeenCalledWith(-1);
7272
});

web/src/components/l10n/LocaleSelection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import { _ } from "~/i18n";
3535
export default function LocaleSelection() {
3636
const navigate = useNavigate();
3737
const {
38-
localization: { locales },
38+
l10n: { locales },
3939
} = useSystem();
4040
const {
41-
localization: { locale: currentLocale },
41+
l10n: { locale: currentLocale },
4242
} = useProposal();
4343
const [selected, setSelected] = useState(currentLocale);
4444
const [filteredLocales, setFilteredLocales] = useState(locales);
@@ -47,7 +47,7 @@ export default function LocaleSelection() {
4747

4848
const onSubmit = async (e: React.SyntheticEvent) => {
4949
e.preventDefault();
50-
updateConfig({ localization: { locale: selected } });
50+
updateConfig({ l10n: { locale: selected } });
5151
navigate(-1);
5252
};
5353

web/src/components/l10n/TimezoneSelection.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ const timezones: Timezone[] = [
5252

5353
jest.mock("~/queries/system", () => ({
5454
...jest.requireActual("~/queries/system"),
55-
useSystem: () => ({ localization: { timezones } }),
55+
useSystem: () => ({ l10n: { timezones } }),
5656
}));
5757

5858
jest.mock("~/queries/proposal", () => ({
5959
...jest.requireActual("~/queries/proposal"),
60-
useProposal: () => ({ localization: { timezones, timezone: "Europe/Berlin" } }),
60+
useProposal: () => ({ l10n: { timezones, timezone: "Europe/Berlin" } }),
6161
}));
6262

6363
jest.mock("react-router-dom", () => ({
@@ -89,7 +89,7 @@ it("allows changing the timezone", async () => {
8989
await user.click(option);
9090
const button = await screen.findByRole("button", { name: "Select" });
9191
await user.click(button);
92-
expect(mockUpdateConfigFn).toHaveBeenCalledWith({ localization: { timezone: "Europe/Madrid" } });
92+
expect(mockUpdateConfigFn).toHaveBeenCalledWith({ l10n: { timezone: "Europe/Madrid" } });
9393
expect(mockNavigateFn).toHaveBeenCalledWith(-1);
9494
});
9595

0 commit comments

Comments
 (0)