web/satellite: make pinia modules more independent
Make pinia modules not to depent on other pinia modules where possible. Change-Id: I2bcc473936a3e294eed58fafd977d447c7feef91
This commit is contained in:
parent
1480b5b9a0
commit
7921add393
@ -14,7 +14,6 @@ import {
|
||||
} from '@/types/accessGrants';
|
||||
import { SortDirection } from '@/types/common';
|
||||
import { AccessGrantsApiGql } from '@/api/accessGrants';
|
||||
import { useProjectsStore } from '@/store/modules/projectsStore';
|
||||
|
||||
class AccessGrantsState {
|
||||
public cursor: AccessGrantCursor = new AccessGrantCursor();
|
||||
@ -34,7 +33,6 @@ class AccessGrantsState {
|
||||
|
||||
export const useAccessGrantsStore = defineStore('accessGrants', () => {
|
||||
const api = new AccessGrantsApiGql();
|
||||
const { selectedProject } = useProjectsStore();
|
||||
|
||||
const state = reactive<AccessGrantsState>(new AccessGrantsState());
|
||||
|
||||
@ -65,10 +63,10 @@ export const useAccessGrantsStore = defineStore('accessGrants', () => {
|
||||
state.isAccessGrantsWebWorkerReady = false;
|
||||
}
|
||||
|
||||
async function fetchAccessGrants(pageNumber: number): Promise<AccessGrantsPage> {
|
||||
async function fetchAccessGrants(projectID: string, pageNumber: number): Promise<AccessGrantsPage> {
|
||||
state.cursor.page = pageNumber;
|
||||
|
||||
const accessGrantsPage: AccessGrantsPage = await api.get(selectedProject.id, state.cursor);
|
||||
const accessGrantsPage: AccessGrantsPage = await api.get(projectID, state.cursor);
|
||||
|
||||
state.page = accessGrantsPage;
|
||||
state.page.accessGrants = state.page.accessGrants.map(accessGrant => {
|
||||
@ -82,19 +80,19 @@ export const useAccessGrantsStore = defineStore('accessGrants', () => {
|
||||
return accessGrantsPage;
|
||||
}
|
||||
|
||||
async function createAccessGrant(name: string): Promise<AccessGrant> {
|
||||
return await api.create(selectedProject.id, name);
|
||||
async function createAccessGrant(projectID: string, name: string): Promise<AccessGrant> {
|
||||
return await api.create(projectID, name);
|
||||
}
|
||||
|
||||
async function deleteAccessGrants(): Promise<void> {
|
||||
await api.delete(state.selectedAccessGrantsIds);
|
||||
}
|
||||
|
||||
async function deleteAccessGrantByNameAndProjectID(name: string): Promise<void> {
|
||||
await api.deleteByNameAndProjectID(name, selectedProject.id);
|
||||
async function deleteAccessGrantByNameAndProjectID(projectID: string, name: string): Promise<void> {
|
||||
await api.deleteByNameAndProjectID(name, projectID);
|
||||
}
|
||||
|
||||
async function getEdgeCredentials(accessGrant: string, optionalURL: string, isPublic: boolean): Promise<EdgeCredentials> {
|
||||
async function getEdgeCredentials(accessGrant: string, optionalURL?: string, isPublic?: boolean): Promise<EdgeCredentials> {
|
||||
const credentials: EdgeCredentials = await api.getGatewayCredentials(accessGrant, optionalURL, isPublic);
|
||||
|
||||
state.edgeCredentials = credentials;
|
||||
|
@ -6,7 +6,6 @@ import { reactive } from 'vue';
|
||||
|
||||
import { Bucket, BucketCursor, BucketPage, BucketsApi } from '@/types/buckets';
|
||||
import { BucketsApiGql } from '@/api/buckets';
|
||||
import { useProjectsStore } from '@/store/modules/projectsStore';
|
||||
|
||||
const BUCKETS_PAGE_LIMIT = 7;
|
||||
const FIRST_PAGE = 1;
|
||||
@ -32,19 +31,14 @@ export const useBucketsStore = defineStore('buckets', () => {
|
||||
state.page = new BucketPage([], '', BUCKETS_PAGE_LIMIT, 0, 1, 1, 0);
|
||||
}
|
||||
|
||||
async function fetchBuckets(page: number): Promise<void> {
|
||||
const { projectsState } = useProjectsStore();
|
||||
const projectID = projectsState.selectedProject.id;
|
||||
async function fetchBuckets(projectID: string, page: number): Promise<void> {
|
||||
const before = new Date();
|
||||
state.cursor.page = page;
|
||||
|
||||
state.page = await api.get(projectID, before, state.cursor);
|
||||
}
|
||||
|
||||
async function fetchAllBucketsNames(): Promise<void> {
|
||||
const { projectsState } = useProjectsStore();
|
||||
const projectID = projectsState.selectedProject.id;
|
||||
|
||||
async function fetchAllBucketsNames(projectID: string): Promise<void> {
|
||||
state.allBucketNames = await api.getAllBucketNames(projectID);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ import {
|
||||
ProjectUsageDateRange,
|
||||
} from '@/types/projects';
|
||||
import { ProjectsApiGql } from '@/api/projects';
|
||||
import { useUsersStore } from '@/store/modules/usersStore';
|
||||
|
||||
const defaultSelectedProject = new Project('', '', '', '', '', true, 0);
|
||||
|
||||
@ -98,15 +97,14 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
return createdProject.id;
|
||||
}
|
||||
|
||||
async function createDefaultProject(): Promise<void> {
|
||||
async function createDefaultProject(userID: string): Promise<void> {
|
||||
const UNTITLED_PROJECT_NAME = 'My First Project';
|
||||
const UNTITLED_PROJECT_DESCRIPTION = '___';
|
||||
const { usersState } = useUsersStore();
|
||||
|
||||
const project = new ProjectFields(
|
||||
UNTITLED_PROJECT_NAME,
|
||||
UNTITLED_PROJECT_DESCRIPTION,
|
||||
usersState.user.id,
|
||||
userID,
|
||||
);
|
||||
|
||||
const createdProjectId = await createProject(project);
|
||||
@ -243,13 +241,11 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const projectsCount = computed(() => {
|
||||
const projectsCount = computed((userID: string) => {
|
||||
let projectsCount = 0;
|
||||
|
||||
const { usersState } = useUsersStore();
|
||||
|
||||
state.projects.forEach((project: Project) => {
|
||||
if (project.ownerId === usersState.user.id) {
|
||||
if (project.ownerId === userID) {
|
||||
projectsCount++;
|
||||
}
|
||||
});
|
||||
@ -257,10 +253,6 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
return projectsCount;
|
||||
});
|
||||
|
||||
const selectedProject = computed((): Project => {
|
||||
return state.selectedProject;
|
||||
});
|
||||
|
||||
return {
|
||||
projectsState: state,
|
||||
fetchProjects,
|
||||
@ -281,6 +273,5 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
projects,
|
||||
projectsWithoutSelected,
|
||||
projectsCount,
|
||||
selectedProject,
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user