From be567021d9c20d16070bfc2ed405b25ac67202a6 Mon Sep 17 00:00:00 2001 From: Jeremy Wharton Date: Fri, 24 Mar 2023 00:55:48 -0500 Subject: [PATCH] web/satellite: fetch frontend config from the satellite This change updates the satellite frontend to retrieve its configuration from the satellite. References #5494 Change-Id: I1eb961f8a32f7d88173006117d41eddb57624692 --- web/satellite/src/App.vue | 8 + web/satellite/src/api/config.ts | 26 ++ .../components/EndDateSelection.vue | 2 +- .../permissions/BucketsSelection.vue | 2 +- .../permissions/DurationSelection.vue | 2 +- .../account/billing/BillingArea.vue | 4 +- .../PeriodSelection.vue | 2 +- .../paymentMethods/TokenDepositSelection.vue | 2 +- .../src/components/modals/AllModals.vue | 2 +- .../components/modals/PricingPlanModal.vue | 21 +- .../ManageProjectPassphraseModal.vue | 2 +- .../src/components/navigation/AccountArea.vue | 2 +- .../components/navigation/NavigationArea.vue | 4 +- .../navigation/ProjectSelection.vue | 2 +- .../src/components/objects/UploadFile.vue | 2 +- .../onboardingTour/steps/cliFlow/AGName.vue | 2 +- .../steps/cliFlow/AGPermissions.vue | 2 +- .../onboardingTour/steps/cliFlow/APIKey.vue | 4 +- .../steps/cliFlow/PermissionsSelect.vue | 2 +- .../steps/common/OSContainer.vue | 2 +- .../project/dashboard/ProjectDashboard.vue | 4 +- web/satellite/src/store/index.ts | 15 +- web/satellite/src/store/modules/appState.ts | 267 +++++++++--------- web/satellite/src/store/mutationConstants.ts | 3 +- .../src/{utils => types}/config.gen.ts | 0 web/satellite/src/types/config.ts | 17 ++ web/satellite/src/utils/configgen.go | 4 +- .../src/utils/constants/actionNames.ts | 3 +- .../{appStateEnum.ts => fetchStateEnum.ts} | 2 +- web/satellite/src/views/AuthorizeArea.vue | 4 +- web/satellite/src/views/DashboardArea.vue | 12 +- web/satellite/src/views/LoginArea.vue | 4 +- web/satellite/src/views/ResetPassword.vue | 2 +- .../views/all-dashboard/AllDashboardArea.vue | 10 +- .../components/MyAccountButton.vue | 2 +- .../all-dashboard/components/ProjectItem.vue | 2 +- .../paymentMethods/AddCardForm.spec.ts | 5 +- .../billing/coupons/CouponArea.spec.ts | 5 +- .../PeriodSelection.spec.ts | 4 +- .../paymentMethods/PaymentMethods.spec.ts | 4 +- .../unit/ignore/common/HeaderArea.spec.ts | 4 +- .../unit/ignore/views/DashboardArea.spec.ts | 8 +- web/satellite/tests/unit/mock/api/config.ts | 13 + .../onboardingTour/steps/OverviewStep.spec.ts | 6 +- .../projectMembers/ProjectMembersArea.spec.ts | 4 +- 45 files changed, 303 insertions(+), 196 deletions(-) create mode 100644 web/satellite/src/api/config.ts rename web/satellite/src/{utils => types}/config.gen.ts (100%) create mode 100644 web/satellite/src/types/config.ts rename web/satellite/src/utils/constants/{appStateEnum.ts => fetchStateEnum.ts} (82%) create mode 100644 web/satellite/tests/unit/mock/api/config.ts diff --git a/web/satellite/src/App.vue b/web/satellite/src/App.vue index 9b24d18be..550cd4fc0 100644 --- a/web/satellite/src/App.vue +++ b/web/satellite/src/App.vue @@ -31,6 +31,14 @@ export default class App extends Vue { * Sets up variables from meta tags from config such satellite name, etc. */ public mounted(): void { + try { + this.$store.dispatch(APP_STATE_ACTIONS.FETCH_CONFIG); + } catch (error) { + // TODO: Use a harsher error-handling approach when the config is necessary + // for the frontend to function. + this.$notify.error(error.message, null); + } + const satelliteName = MetaUtils.getMetaContent('satellite-name'); const partneredSatellitesData = MetaUtils.getMetaContent('partnered-satellites'); let partneredSatellitesJSON = []; diff --git a/web/satellite/src/api/config.ts b/web/satellite/src/api/config.ts new file mode 100644 index 000000000..b194f243e --- /dev/null +++ b/web/satellite/src/api/config.ts @@ -0,0 +1,26 @@ +// Copyright (C) 2023 Storj Labs, Inc. +// See LICENSE for copying information. + +import { HttpClient } from '@/utils/httpClient'; +import { FrontendConfig, FrontendConfigApi } from '@/types/config'; + +/** + * FrontendConfigHttpApi is an HTTP implementation of the frontend config API. + */ +export class FrontendConfigHttpApi implements FrontendConfigApi { + private readonly http: HttpClient = new HttpClient(); + private readonly ROOT_PATH: string = '/config'; + + /** + * Returns the frontend config. + * + * @throws Error + */ + public async get(): Promise { + const response = await this.http.get(this.ROOT_PATH); + if (!response.ok) { + throw new Error('Cannot get frontend config'); + } + return await response.json() as FrontendConfig; + } +} diff --git a/web/satellite/src/components/accessGrants/newCreateFlow/components/EndDateSelection.vue b/web/satellite/src/components/accessGrants/newCreateFlow/components/EndDateSelection.vue index c242bf5cd..301b12352 100644 --- a/web/satellite/src/components/accessGrants/newCreateFlow/components/EndDateSelection.vue +++ b/web/satellite/src/components/accessGrants/newCreateFlow/components/EndDateSelection.vue @@ -44,7 +44,7 @@ const store = useStore(); * Indicates if date picker is shown. */ const isDatePickerVisible = computed((): boolean => { - return store.state.appStateModule.appState.activeDropdown === APP_STATE_DROPDOWNS.AG_DATE_PICKER; + return store.state.appStateModule.viewsState.activeDropdown === APP_STATE_DROPDOWNS.AG_DATE_PICKER; }); /** diff --git a/web/satellite/src/components/accessGrants/permissions/BucketsSelection.vue b/web/satellite/src/components/accessGrants/permissions/BucketsSelection.vue index 612f82b0d..a6f2dd767 100644 --- a/web/satellite/src/components/accessGrants/permissions/BucketsSelection.vue +++ b/web/satellite/src/components/accessGrants/permissions/BucketsSelection.vue @@ -51,7 +51,7 @@ export default class BucketsSelection extends Vue { * Indicates if dropdown is shown. */ public get isDropdownShown(): boolean { - return this.$store.state.appStateModule.appState.activeDropdown === APP_STATE_DROPDOWNS.BUCKET_NAMES; + return this.$store.state.appStateModule.viewsState.activeDropdown === APP_STATE_DROPDOWNS.BUCKET_NAMES; } /** diff --git a/web/satellite/src/components/accessGrants/permissions/DurationSelection.vue b/web/satellite/src/components/accessGrants/permissions/DurationSelection.vue index 3e6ab16f8..373cb03b3 100644 --- a/web/satellite/src/components/accessGrants/permissions/DurationSelection.vue +++ b/web/satellite/src/components/accessGrants/permissions/DurationSelection.vue @@ -80,7 +80,7 @@ export default class DurationSelection extends Vue { * Indicates if date picker is shown. */ public get isDurationPickerVisible(): boolean { - return this.$store.state.appStateModule.appState.activeDropdown === APP_STATE_DROPDOWNS.AG_DATE_PICKER; + return this.$store.state.appStateModule.viewsState.activeDropdown === APP_STATE_DROPDOWNS.AG_DATE_PICKER; } /** diff --git a/web/satellite/src/components/account/billing/BillingArea.vue b/web/satellite/src/components/account/billing/BillingArea.vue index 25b7ad99a..1d5eb5260 100644 --- a/web/satellite/src/components/account/billing/BillingArea.vue +++ b/web/satellite/src/components/account/billing/BillingArea.vue @@ -159,14 +159,14 @@ export default class BillingArea extends Vue { * Indicates if free credits dropdown shown. */ public get isCreditsDropdownShown(): boolean { - return this.$store.state.appStateModule.appState.activeDropdown === APP_STATE_DROPDOWNS.FREE_CREDITS; + return this.$store.state.appStateModule.viewsState.activeDropdown === APP_STATE_DROPDOWNS.FREE_CREDITS; } /** * Indicates if available balance dropdown shown. */ public get isBalanceDropdownShown(): boolean { - return this.$store.state.appStateModule.appState.activeDropdown === APP_STATE_DROPDOWNS.AVAILABLE_BALANCE; + return this.$store.state.appStateModule.viewsState.activeDropdown === APP_STATE_DROPDOWNS.AVAILABLE_BALANCE; } /** diff --git a/web/satellite/src/components/account/billing/depositAndBillingHistory/PeriodSelection.vue b/web/satellite/src/components/account/billing/depositAndBillingHistory/PeriodSelection.vue index 29adecc1f..f59d8c411 100644 --- a/web/satellite/src/components/account/billing/depositAndBillingHistory/PeriodSelection.vue +++ b/web/satellite/src/components/account/billing/depositAndBillingHistory/PeriodSelection.vue @@ -61,7 +61,7 @@ const currentOption = ref(periodOptions[0]); * Indicates if periods dropdown is shown. */ const isDropdownShown = computed((): boolean => { - return store.state.appStateModule.appState.activeDropdown === APP_STATE_DROPDOWNS.PERIODS; + return store.state.appStateModule.viewsState.activeDropdown === APP_STATE_DROPDOWNS.PERIODS; }); /** diff --git a/web/satellite/src/components/account/billing/paymentMethods/TokenDepositSelection.vue b/web/satellite/src/components/account/billing/paymentMethods/TokenDepositSelection.vue index f205e7106..7d93832cb 100644 --- a/web/satellite/src/components/account/billing/paymentMethods/TokenDepositSelection.vue +++ b/web/satellite/src/components/account/billing/paymentMethods/TokenDepositSelection.vue @@ -103,7 +103,7 @@ export default class TokenDepositSelection3 extends Vue { * isSelectionShown flag that indicate is token amount selection shown. */ public get isSelectionShown(): boolean { - return this.$store.state.appStateModule.appState.activeDropdown === APP_STATE_DROPDOWNS.PAYMENT_SELECTION; + return this.$store.state.appStateModule.viewsState.activeDropdown === APP_STATE_DROPDOWNS.PAYMENT_SELECTION; } /** diff --git a/web/satellite/src/components/modals/AllModals.vue b/web/satellite/src/components/modals/AllModals.vue index a3c6933fe..1ede9ae56 100644 --- a/web/satellite/src/components/modals/AllModals.vue +++ b/web/satellite/src/components/modals/AllModals.vue @@ -72,7 +72,7 @@ export default class AllModals extends Vue { */ public get activeModal(): unknown | null { // modal could be of VueConstructor type or Object (for composition api components). - return this.$store.state.appStateModule.appState.activeModal; + return this.$store.state.appStateModule.viewsState.activeModal; } } diff --git a/web/satellite/src/components/modals/PricingPlanModal.vue b/web/satellite/src/components/modals/PricingPlanModal.vue index 6fd10cf58..1ed4aaba6 100644 --- a/web/satellite/src/components/modals/PricingPlanModal.vue +++ b/web/satellite/src/components/modals/PricingPlanModal.vue @@ -2,7 +2,7 @@ // See LICENSE for copying information.