bb-plane-fork/apps/space/store/module.store.ts
darkingtail d9695afcdc fix: remove unused imports and variables (part 1 — packages & non-web-core) (#8751)
* fix: remove unused imports and variables (part 1)

Resolve oxlint no-unused-vars warnings in packages/*, apps/admin,
apps/space, apps/live, and apps/web (non-core).

* fix: resolve CI check failures

* fix: resolve check:types failures

* fix: resolve check:types and check:format failures

- Use destructuring alias for activeCycleResolvedPath
- Format propel tab-navigation file

* fix: format propel button helper with oxfmt

Reorder Tailwind classes to match oxfmt canonical ordering.
2026-03-25 02:04:20 +05:30

77 lines
2.1 KiB
TypeScript

/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/
import { set } from "lodash-es";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
// plane imports
import { SitesModuleService } from "@plane/services";
// types
import type { TPublicModule } from "@/types/modules";
// root store
import type { RootStore } from "./root.store";
export interface IIssueModuleStore {
// observables
modules: TPublicModule[] | undefined;
// computed actions
getModuleById: (moduleId: string | undefined) => TPublicModule | undefined;
getModulesByIds: (moduleIds: string[]) => TPublicModule[];
// fetch actions
fetchModules: (anchor: string) => Promise<TPublicModule[]>;
}
export class ModuleStore implements IIssueModuleStore {
moduleMap: Record<string, TPublicModule> = {};
moduleService: SitesModuleService;
rootStore: RootStore;
constructor(_rootStore: RootStore) {
makeObservable(this, {
// observables
moduleMap: observable,
// computed
modules: computed,
// fetch action
fetchModules: action,
});
this.moduleService = new SitesModuleService();
this.rootStore = _rootStore;
}
get modules() {
return Object.values(this.moduleMap);
}
getModuleById = (moduleId: string | undefined) => (moduleId ? this.moduleMap[moduleId] : undefined);
getModulesByIds = (moduleIds: string[]) => {
const currModules = [];
for (const moduleId of moduleIds) {
const issueModule = this.getModuleById(moduleId);
if (issueModule) {
currModules.push(issueModule);
}
}
return currModules;
};
fetchModules = async (anchor: string) => {
try {
const modulesResponse = await this.moduleService.list(anchor);
runInAction(() => {
this.moduleMap = {};
for (const issueModule of modulesResponse) {
set(this.moduleMap, [issueModule.id], issueModule);
}
});
return modulesResponse;
} catch (error) {
console.error("Failed to fetch members:", error);
return [];
}
};
}