From 63e3af95e00b7bf39828603ac545387e24c8b0a7 Mon Sep 17 00:00:00 2001 From: Katerina Koukiou Date: Wed, 21 Jun 2023 14:20:40 +0200 Subject: [PATCH] webui: split actions per data type --- ui/webui/src/actions/localization-actions.js | 57 +++++++++++++++++++ .../storage-actions.js} | 43 +------------- .../localization/InstallationLanguage.jsx | 2 +- .../storage/InstallationDestination.jsx | 2 +- 4 files changed, 61 insertions(+), 43 deletions(-) create mode 100644 ui/webui/src/actions/localization-actions.js rename ui/webui/src/{actions.js => actions/storage-actions.js} (69%) diff --git a/ui/webui/src/actions/localization-actions.js b/ui/webui/src/actions/localization-actions.js new file mode 100644 index 000000000000..a7ec46e36ba0 --- /dev/null +++ b/ui/webui/src/actions/localization-actions.js @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2023 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with This program; If not, see . + */ + +import { + getCommonLocales, + getLanguages, + getLanguageData, + getLocales, + getLocaleData, +} from "../apis/localization.js"; + +export const getLanguagesAction = () => { + return async function fetchUserThunk (dispatch) { + const languageIds = await getLanguages(); + + dispatch(getCommonLocalesAction()); + return languageIds.map(language => dispatch(getLanguageDataAction({ language }))); + }; +}; + +export const getLanguageDataAction = ({ language }) => { + return async function fetchUserThunk (dispatch) { + const localeIds = await getLocales({ lang: language }); + const languageData = await getLanguageData({ lang: language }); + const locales = await Promise.all(localeIds.map(async locale => await getLocaleData({ locale }))); + + return dispatch({ + type: "GET_LANGUAGE_DATA", + payload: { languageData: { [language]: { languageData, locales } } } + }); + }; +}; + +export const getCommonLocalesAction = () => { + return async function fetchUserThunk (dispatch) { + const commonLocales = await getCommonLocales(); + + return dispatch({ + type: "GET_COMMON_LOCALES", + payload: { commonLocales } + }); + }; +}; diff --git a/ui/webui/src/actions.js b/ui/webui/src/actions/storage-actions.js similarity index 69% rename from ui/webui/src/actions.js rename to ui/webui/src/actions/storage-actions.js index 38559087037b..df5b9cd7b216 100644 --- a/ui/webui/src/actions.js +++ b/ui/webui/src/actions/storage-actions.js @@ -14,6 +14,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with This program; If not, see . */ + import cockpit from "cockpit"; import { @@ -24,14 +25,7 @@ import { getDiskTotalSpace, getFormatData, getUsableDisks, -} from "./apis/storage.js"; -import { - getCommonLocales, - getLanguages, - getLanguageData, - getLocales, - getLocaleData, -} from "./apis/localization.js"; +} from "../apis/storage.js"; export const getDevicesAction = () => { return async function fetchUserThunk (dispatch) { @@ -88,36 +82,3 @@ export const getDiskSelectionAction = () => { }); }; }; - -export const getLanguagesAction = () => { - return async function fetchUserThunk (dispatch) { - const languageIds = await getLanguages(); - - dispatch(getCommonLocalesAction()); - return languageIds.map(language => dispatch(getLanguageDataAction({ language }))); - }; -}; - -export const getLanguageDataAction = ({ language }) => { - return async function fetchUserThunk (dispatch) { - const localeIds = await getLocales({ lang: language }); - const languageData = await getLanguageData({ lang: language }); - const locales = await Promise.all(localeIds.map(async locale => await getLocaleData({ locale }))); - - return dispatch({ - type: "GET_LANGUAGE_DATA", - payload: { languageData: { [language]: { languageData, locales } } } - }); - }; -}; - -export const getCommonLocalesAction = () => { - return async function fetchUserThunk (dispatch) { - const commonLocales = await getCommonLocales(); - - return dispatch({ - type: "GET_COMMON_LOCALES", - payload: { commonLocales } - }); - }; -}; diff --git a/ui/webui/src/components/localization/InstallationLanguage.jsx b/ui/webui/src/components/localization/InstallationLanguage.jsx index 8a3038feab7c..dc92b3653600 100644 --- a/ui/webui/src/components/localization/InstallationLanguage.jsx +++ b/ui/webui/src/components/localization/InstallationLanguage.jsx @@ -49,7 +49,7 @@ import { } from "../../helpers/language.js"; import { AnacondaPage } from "../AnacondaPage.jsx"; import { getOsReleaseByKey } from "../../helpers/product.js"; -import { getLanguagesAction } from "../../actions.js"; +import { getLanguagesAction } from "../../actions/localization-actions.js"; import "./InstallationLanguage.scss"; diff --git a/ui/webui/src/components/storage/InstallationDestination.jsx b/ui/webui/src/components/storage/InstallationDestination.jsx index 9003a7f42671..07b1557b684a 100644 --- a/ui/webui/src/components/storage/InstallationDestination.jsx +++ b/ui/webui/src/components/storage/InstallationDestination.jsx @@ -68,7 +68,7 @@ import { import { getRequiredSpace, } from "../../apis/payloads"; -import { getDevicesAction, getDiskSelectionAction } from "../../actions.js"; +import { getDevicesAction, getDiskSelectionAction } from "../../actions/storage-actions.js"; import { sleep,