web/satellite: use frontend config in store modules
References to the meta tag config values in Vuex store modules and Pinia stores have been modified to instead refer to the frontend config fetched through the satellite API. References #5494 Change-Id: I2d16d8fa8f3159c45f00f506825b0c2119e475ff
This commit is contained in:
parent
b3b619efc5
commit
e2abbc3800
@ -10,7 +10,6 @@ import {
|
||||
EdgeCredentials,
|
||||
} from '@/types/accessGrants';
|
||||
import { HttpClient } from '@/utils/httpClient';
|
||||
import { MetaUtils } from '@/utils/meta';
|
||||
|
||||
/**
|
||||
* AccessGrantsApiGql is a graphql implementation of Access Grants API.
|
||||
@ -151,14 +150,11 @@ export class AccessGrantsApiGql extends BaseGql implements AccessGrantsApi {
|
||||
* Used to get gateway credentials using access grant.
|
||||
*
|
||||
* @param accessGrant - generated access grant
|
||||
* @param optionalURL - optional requestURL
|
||||
* @param requestURL - URL to which gateway credential requests are sent
|
||||
* @param isPublic - optional status
|
||||
* @throws Error
|
||||
*/
|
||||
public async getGatewayCredentials(accessGrant: string, optionalURL?: string, isPublic?: boolean): Promise<EdgeCredentials> {
|
||||
const requestURL: string = optionalURL || MetaUtils.getMetaContent('gateway-credentials-request-url');
|
||||
if (!requestURL) throw new Error('Cannot get gateway credentials: request URL is not provided');
|
||||
|
||||
public async getGatewayCredentials(accessGrant: string, requestURL: string, isPublic?: boolean): Promise<EdgeCredentials> {
|
||||
const path = `${requestURL}/v1/access`;
|
||||
const body = {
|
||||
access_grant: accessGrant,
|
||||
|
@ -108,7 +108,10 @@ router.beforeEach(async (to, from, next) => {
|
||||
}
|
||||
|
||||
if (navigateToDefaultSubTab(to.matched, RouteConfig.OnboardingTour)) {
|
||||
next(RouteConfig.OnboardingTour.with(RouteConfig.FirstOnboardingStep).path);
|
||||
const firstOnboardingStep = appStore.state.config.pricingPackagesEnabled
|
||||
? RouteConfig.PricingPlanStep
|
||||
: RouteConfig.OverviewStep;
|
||||
next(RouteConfig.OnboardingTour.with(firstOnboardingStep).path);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -149,7 +152,7 @@ function navigateToDefaultSubTab(routes: RouteRecord[], tabRoute: NavigationLink
|
||||
function updateTitle(): void {
|
||||
const appStore = useAppStore();
|
||||
const routeName = router.currentRoute.name;
|
||||
const parts = [routeName, appStore.state.satelliteName];
|
||||
const parts = [routeName, appStore.state.config.satelliteName];
|
||||
|
||||
if (routeName && !notProjectRelatedRoutes.includes(routeName)) {
|
||||
parts.unshift(store.state.projectsModule.selectedProject.name);
|
||||
|
@ -4,13 +4,12 @@
|
||||
import { reactive } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { MetaUtils } from '@/utils/meta';
|
||||
import { ABHitAction, ABTestApi, ABTestValues } from '@/types/abtesting';
|
||||
import { ABHttpApi } from '@/api/abtesting';
|
||||
import { useAppStore } from '@/store/modules/appStore';
|
||||
|
||||
export class ABTestingState {
|
||||
public abTestValues = new ABTestValues();
|
||||
public abTestingEnabled = MetaUtils.getMetaContent('ab-testing-enabled') === 'true';
|
||||
public abTestingInitialized = false;
|
||||
}
|
||||
|
||||
@ -19,8 +18,10 @@ export const useABTestingStore = defineStore('abTesting', () => {
|
||||
|
||||
const api: ABTestApi = new ABHttpApi();
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
||||
async function fetchValues(): Promise<ABTestValues> {
|
||||
if (!state.abTestingEnabled) return state.abTestValues;
|
||||
if (!appStore.state.config.abTestingEnabled) return state.abTestValues;
|
||||
|
||||
const values = await api.fetchABTestValues();
|
||||
|
||||
@ -31,7 +32,7 @@ export const useABTestingStore = defineStore('abTesting', () => {
|
||||
}
|
||||
|
||||
async function hit(action: ABHitAction): Promise<void> {
|
||||
if (!state.abTestingEnabled) return;
|
||||
if (!appStore.state.config.abTestingEnabled) return;
|
||||
if (!state.abTestingInitialized) {
|
||||
await fetchValues();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
} from '@/types/accessGrants';
|
||||
import { SortDirection } from '@/types/common';
|
||||
import { AccessGrantsApiGql } from '@/api/accessGrants';
|
||||
import { useAppStore } from '@/store/modules/appStore';
|
||||
|
||||
class AccessGrantsState {
|
||||
public cursor: AccessGrantCursor = new AccessGrantCursor();
|
||||
@ -36,6 +37,8 @@ export const useAccessGrantsStore = defineStore('accessGrants', () => {
|
||||
|
||||
const state = reactive<AccessGrantsState>(new AccessGrantsState());
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
||||
async function startWorker(): Promise<void> {
|
||||
const worker = new Worker(new URL('@/utils/accessGrant.worker.js', import.meta.url), { type: 'module' });
|
||||
worker.postMessage({ 'type': 'Setup' });
|
||||
@ -93,7 +96,8 @@ export const useAccessGrantsStore = defineStore('accessGrants', () => {
|
||||
}
|
||||
|
||||
async function getEdgeCredentials(accessGrant: string, optionalURL?: string, isPublic?: boolean): Promise<EdgeCredentials> {
|
||||
const credentials: EdgeCredentials = await api.getGatewayCredentials(accessGrant, optionalURL, isPublic);
|
||||
const url = optionalURL || appStore.state.config.gatewayCredentialsRequestURL;
|
||||
const credentials: EdgeCredentials = await api.getGatewayCredentials(accessGrant, url, isPublic);
|
||||
|
||||
state.edgeCredentials = credentials;
|
||||
|
||||
|
@ -7,9 +7,7 @@ import { defineStore } from 'pinia';
|
||||
import { OnboardingOS, PartneredSatellite, PricingPlanInfo } from '@/types/common';
|
||||
import { FetchState } from '@/utils/constants/fetchStateEnum';
|
||||
import { ManageProjectPassphraseStep } from '@/types/managePassphrase';
|
||||
import { MetaUtils } from '@/utils/meta';
|
||||
import { FrontendConfig } from '@/types/config.gen';
|
||||
import { FrontendConfigApi } from '@/types/config';
|
||||
import { FrontendConfig, FrontendConfigApi } from '@/types/config';
|
||||
import { FrontendConfigHttpApi } from '@/api/config';
|
||||
|
||||
class ViewsState {
|
||||
@ -49,7 +47,7 @@ export class State {
|
||||
public isBetaSatellite = false;
|
||||
public couponCodeBillingUIEnabled = false;
|
||||
public couponCodeSignupUIEnabled = false;
|
||||
public isAllProjectsDashboard = MetaUtils.getMetaContent('all-projects-dashboard') === 'true';
|
||||
public isAllProjectsDashboard = false;
|
||||
public config: FrontendConfig = new FrontendConfig();
|
||||
}
|
||||
|
||||
@ -62,6 +60,7 @@ export const useAppStore = defineStore('app', () => {
|
||||
const result = await configApi.get();
|
||||
|
||||
state.config = result;
|
||||
state.isAllProjectsDashboard = result.allProjectsDashboard;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import { BucketsApiGql } from '@/api/buckets';
|
||||
import { AccessGrant, EdgeCredentials } from '@/types/accessGrants';
|
||||
import { useAccessGrantsStore } from '@/store/modules/accessGrantsStore';
|
||||
import { useProjectsStore } from '@/store/modules/projectsStore';
|
||||
import { MetaUtils } from '@/utils/meta';
|
||||
import { useAppStore } from '@/store/modules/appStore';
|
||||
import { MODALS } from '@/utils/constants/appStatePopUps';
|
||||
|
||||
@ -52,6 +51,8 @@ export const useBucketsStore = defineStore('buckets', () => {
|
||||
|
||||
const api: BucketsApi = new BucketsApiGql();
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
||||
function setBucketsSearch(search: string): void {
|
||||
state.cursor.search = search;
|
||||
}
|
||||
@ -155,7 +156,7 @@ export const useBucketsStore = defineStore('buckets', () => {
|
||||
const { getProjectSalt } = useProjectsStore();
|
||||
|
||||
const salt = await getProjectSalt(projectID);
|
||||
const satelliteNodeURL: string = MetaUtils.getMetaContent('satellite-nodeurl');
|
||||
const satelliteNodeURL: string = appStore.state.config.satelliteNodeURL;
|
||||
|
||||
if (!state.passphrase) {
|
||||
throw new Error('Passphrase can\'t be empty');
|
||||
@ -256,8 +257,7 @@ export const useBucketsStore = defineStore('buckets', () => {
|
||||
|
||||
state.leaveRoute = leaveRoute;
|
||||
|
||||
const { updateActiveModal } = useAppStore();
|
||||
updateActiveModal(MODALS.uploadCancelPopup);
|
||||
appStore.updateActiveModal(MODALS.uploadCancelPopup);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import { FilesState } from '@/store/modules/files';
|
||||
import { StoreModule } from '@/types/store';
|
||||
import { MODALS } from '@/utils/constants/appStatePopUps';
|
||||
import { PROJECTS_ACTIONS } from '@/store/modules/projects';
|
||||
import { MetaUtils } from '@/utils/meta';
|
||||
import { useAppStore } from '@/store/modules/appStore';
|
||||
import { useAccessGrantsStore } from '@/store/modules/accessGrantsStore';
|
||||
|
||||
@ -255,7 +254,8 @@ export function makeObjectsModule(): StoreModule<ObjectsState, ObjectsContext> {
|
||||
}
|
||||
|
||||
const salt = await dispatch(PROJECTS_ACTIONS.GET_SALT, rootGetters.selectedProject.id, { root: true });
|
||||
const satelliteNodeURL: string = MetaUtils.getMetaContent('satellite-nodeurl');
|
||||
const appStore = useAppStore();
|
||||
const satelliteNodeURL: string = appStore.state.config.satelliteNodeURL;
|
||||
|
||||
if (!state.passphrase) {
|
||||
throw new Error('Passphrase can\'t be empty');
|
||||
|
@ -12,8 +12,8 @@ import {
|
||||
UsersApi,
|
||||
UserSettings,
|
||||
} from '@/types/users';
|
||||
import { MetaUtils } from '@/utils/meta';
|
||||
import { AuthHttpApi } from '@/api/auth';
|
||||
import { useAppStore } from '@/store/modules/appStore';
|
||||
|
||||
export class UsersState {
|
||||
public user: User = new User();
|
||||
@ -25,6 +25,8 @@ export class UsersState {
|
||||
export const useUsersStore = defineStore('users', () => {
|
||||
const state = reactive<UsersState>(new UsersState());
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
||||
const userName = computed(() => {
|
||||
return state.user.getFullName();
|
||||
});
|
||||
@ -44,11 +46,7 @@ export const useUsersStore = defineStore('users', () => {
|
||||
|
||||
async function getUser(): Promise<void> {
|
||||
const user = await api.get();
|
||||
|
||||
if (user.projectLimit === 0) {
|
||||
const limitFromConfig = MetaUtils.getMetaContent('default-project-limit');
|
||||
user.projectLimit = parseInt(limitFromConfig);
|
||||
}
|
||||
user.projectLimit ||= appStore.state.config.defaultProjectLimit;
|
||||
|
||||
setUser(user);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ export interface AccessGrantsApi {
|
||||
* @returns EdgeCredentials
|
||||
* @throws Error
|
||||
*/
|
||||
getGatewayCredentials(accessGrant: string, optionalURL?: string, isPublic?: boolean): Promise<EdgeCredentials>;
|
||||
getGatewayCredentials(accessGrant: string, requestURL: string, isPublic?: boolean): Promise<EdgeCredentials>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ export class AccessGrantsMock implements AccessGrantsApi {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
getGatewayCredentials(_accessGrant: string, _optionalURL?: string): Promise<EdgeCredentials> {
|
||||
getGatewayCredentials(_accessGrant: string, _requestURL: string): Promise<EdgeCredentials> {
|
||||
return Promise.resolve(new EdgeCredentials('testCredId', new Date(), 'testAccessKeyId', 'testSecret', 'testEndpoint'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user