Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions web/components/pages/pages-list/all-pages-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { Loader } from "@plane/ui";

export const AllPagesList: FC = observer(() => {
// store
const { projectPages } = usePage();
const { projectPageIds } = usePage();

if (!projectPages)
if (!projectPageIds)
return (
<Loader className="space-y-4">
<Loader.Item height="40px" />
Expand All @@ -20,5 +20,5 @@ export const AllPagesList: FC = observer(() => {
</Loader>
);

return <PagesListView pages={projectPages} />;
return <PagesListView pageIds={projectPageIds} />;
});
6 changes: 3 additions & 3 deletions web/components/pages/pages-list/archived-pages-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { usePage } from "hooks/store";
import { Loader } from "@plane/ui";

export const ArchivedPagesList: FC = observer(() => {
const { archivedProjectPages } = usePage();
const { archivedProjectPageIds } = usePage();

if (!archivedProjectPages)
if (!archivedProjectPageIds)
return (
<Loader className="space-y-4">
<Loader.Item height="40px" />
Expand All @@ -19,5 +19,5 @@ export const ArchivedPagesList: FC = observer(() => {
</Loader>
);

return <PagesListView pages={archivedProjectPages} />;
return <PagesListView pageIds={archivedProjectPageIds} />;
});
6 changes: 3 additions & 3 deletions web/components/pages/pages-list/favorite-pages-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { usePage } from "hooks/store";
import { Loader } from "@plane/ui";

export const FavoritePagesList: FC = observer(() => {
const { favoriteProjectPages } = usePage();
const { favoriteProjectPageIds } = usePage();

if (!favoriteProjectPages)
if (!favoriteProjectPageIds)
return (
<Loader className="space-y-4">
<Loader.Item height="40px" />
Expand All @@ -19,5 +19,5 @@ export const FavoritePagesList: FC = observer(() => {
</Loader>
);

return <PagesListView pages={favoriteProjectPages} />;
return <PagesListView pageIds={favoriteProjectPageIds} />;
});
10 changes: 5 additions & 5 deletions web/components/pages/pages-list/list-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import emptyPage from "public/empty-state/empty_page.png";
import { EUserProjectRoles } from "constants/project";

type IPagesListView = {
pages: string[];
pageIds: string[];
};

export const PagesListView: FC<IPagesListView> = observer((props) => {
const { pages } = props;
const { pageIds } = props;
// store hooks
const {
commandPalette: { toggleCreatePageModal },
Expand All @@ -35,11 +35,11 @@ export const PagesListView: FC<IPagesListView> = observer((props) => {

return (
<>
{pages && workspaceSlug && projectId ? (
{pageIds && workspaceSlug && projectId ? (
<div className="h-full space-y-4 overflow-y-auto">
{pages.length > 0 ? (
{pageIds.length > 0 ? (
<ul role="list" className="divide-y divide-custom-border-200">
{pages.map((pageId) => (
{pageIds.map((pageId) => (
<PagesListItem
key={pageId}
workspaceSlug={workspaceSlug.toString()}
Expand Down
6 changes: 3 additions & 3 deletions web/components/pages/pages-list/private-page-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { PagesListView } from "components/pages/pages-list";
import { Loader } from "@plane/ui";

export const PrivatePagesList: FC = observer(() => {
const { privateProjectPages } = usePage();
const { privateProjectPageIds } = usePage();

if (!privateProjectPages)
if (!privateProjectPageIds)
return (
<Loader className="space-y-4">
<Loader.Item height="40px" />
Expand All @@ -19,5 +19,5 @@ export const PrivatePagesList: FC = observer(() => {
</Loader>
);

return <PagesListView pages={privateProjectPages} />;
return <PagesListView pageIds={privateProjectPageIds} />;
});
6 changes: 3 additions & 3 deletions web/components/pages/pages-list/shared-pages-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { usePage } from "hooks/store";
import { Loader } from "@plane/ui";

export const SharedPagesList: FC = observer(() => {
const { publicProjectPages } = usePage();
const { publicProjectPageIds } = usePage();

if (!publicProjectPages)
if (!publicProjectPageIds)
return (
<Loader className="space-y-4">
<Loader.Item height="40px" />
Expand All @@ -19,5 +19,5 @@ export const SharedPagesList: FC = observer(() => {
</Loader>
);

return <PagesListView pages={publicProjectPages} />;
return <PagesListView pageIds={publicProjectPageIds} />;
});
3 changes: 1 addition & 2 deletions web/services/module.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// services
import { APIService } from "services/api.service";
// types
import type { IModule, IIssue, ILinkDetails, ModuleLink } from "types";
import { IIssueResponse } from "types";
import type { IModule, IIssue, ILinkDetails, ModuleLink, IIssueResponse } from "types";
import { API_BASE_URL } from "helpers/common.helper";

export class ModuleService extends APIService {
Expand Down
2 changes: 1 addition & 1 deletion web/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import type {
IUserProfileProjectSegregation,
IUserSettings,
IUserWorkspaceDashboard,
IIssueResponse,
} from "types";
// helpers
import { API_BASE_URL } from "helpers/common.helper";
import { IIssueResponse } from "types";

export class UserService extends APIService {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion web/services/workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
IWorkspaceBulkInviteFormData,
IWorkspaceViewProps,
IUserProjectsRole,
IIssueResponse,
} from "types";
import { IWorkspaceView } from "types/workspace-views";
import { IIssueResponse } from "types";

export class WorkspaceService extends APIService {
constructor() {
Expand Down
89 changes: 16 additions & 73 deletions web/store/estimate.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { IEstimate, IEstimateFormData } from "types";

// TODO: rename to IEstimateStore
export interface IProjectEstimateStore {
// states
loader: boolean;
error: any | null;
// observables
estimates: Record<string, IEstimate[] | null>;
// computed
Expand All @@ -20,8 +17,9 @@ export interface IProjectEstimateStore {
// computed actions
getEstimatePointValue: (estimateKey: number | null) => string;
getProjectEstimateById: (estimateId: string) => IEstimate | null;
// actions
// fetch actions
fetchProjectEstimates: (workspaceSlug: string, projectId: string) => Promise<IEstimate[]>;
// crud actions
createEstimate: (workspaceSlug: string, projectId: string, data: IEstimateFormData) => Promise<IEstimate>;
updateEstimate: (
workspaceSlug: string,
Expand All @@ -33,9 +31,6 @@ export interface IProjectEstimateStore {
}

export class ProjectEstimatesStore implements IProjectEstimateStore {
// states
loader: boolean = false;
error: any | null = null;
// observables
estimates: Record<string, IEstimate[] | null> = {};
// root store
Expand All @@ -45,9 +40,6 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {

constructor(_rootStore: RootStore) {
makeObservable(this, {
// states
loader: observable,
error: observable,
// observables
estimates: observable,
// computed
Expand Down Expand Up @@ -75,9 +67,7 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {
*/
get areEstimatesEnabledForCurrentProject() {
const currentProjectDetails = this.rootStore.projectRoot.project.currentProjectDetails;

if (!currentProjectDetails) return false;

return Boolean(currentProjectDetails?.estimate);
}

Expand All @@ -86,7 +76,6 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {
*/
get projectEstimates() {
const projectId = this.rootStore.app.router.projectId;

if (!projectId) return null;
return this.estimates?.[projectId] || null;
}
Expand All @@ -96,9 +85,7 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {
*/
get activeEstimateDetails() {
const currentProjectDetails = this.rootStore.projectRoot.project.currentProjectDetails;

if (!currentProjectDetails || !currentProjectDetails?.estimate) return null;

return this.projectEstimates?.find((estimate) => estimate.id === currentProjectDetails?.estimate) || null;
}

Expand All @@ -107,9 +94,7 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {
*/
getEstimatePointValue = (estimateKey: number | null) => {
if (estimateKey === null) return "None";

const activeEstimate = this.activeEstimateDetails;

return activeEstimate?.points?.find((point) => point.key === estimateKey)?.value || "None";
};

Expand All @@ -118,7 +103,6 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {
*/
getProjectEstimateById = (estimateId: string) => {
if (!this.projectEstimates) return null;

const estimateInfo = this.projectEstimates?.find((estimate) => estimate.id === estimateId) || null;
return estimateInfo;
};
Expand All @@ -128,53 +112,31 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {
* @param workspaceSlug
* @param projectId
*/
fetchProjectEstimates = async (workspaceSlug: string, projectId: string) => {
try {
this.loader = true;
this.error = null;

const estimatesResponse = await this.estimateService.getEstimatesList(workspaceSlug, projectId);

fetchProjectEstimates = async (workspaceSlug: string, projectId: string) =>
await this.estimateService.getEstimatesList(workspaceSlug, projectId).then((response) => {
runInAction(() => {
set(this.estimates, projectId, estimatesResponse);
this.loader = false;
this.error = null;
set(this.estimates, projectId, response);
});

return estimatesResponse;
} catch (error) {
this.loader = false;
this.error = error;

throw error;
}
};
return response;
});

/**
* @description creates a new estimate for the given project
* @param workspaceSlug
* @param projectId
* @param data
*/
createEstimate = async (workspaceSlug: string, projectId: string, data: IEstimateFormData) => {
try {
const response = await this.estimateService.createEstimate(workspaceSlug, projectId, data);

createEstimate = async (workspaceSlug: string, projectId: string, data: IEstimateFormData) =>
await this.estimateService.createEstimate(workspaceSlug, projectId, data).then((response) => {
const responseEstimate = {
...response.estimate,
points: response.estimate_points,
};

runInAction(() => {
set(this.estimates, projectId, [responseEstimate, ...(this.estimates?.[projectId] || [])]);
});

return response.estimate;
} catch (error) {
console.log("Failed to create estimate from project store");
throw error;
}
};
});

/**
* @description updates the given estimate for the given project
Expand All @@ -183,47 +145,28 @@ export class ProjectEstimatesStore implements IProjectEstimateStore {
* @param estimateId
* @param data
*/
updateEstimate = async (workspaceSlug: string, projectId: string, estimateId: string, data: IEstimateFormData) => {
try {
updateEstimate = async (workspaceSlug: string, projectId: string, estimateId: string, data: IEstimateFormData) =>
await this.estimateService.patchEstimate(workspaceSlug, projectId, estimateId, data).then((response) => {
const updatedEstimates = (this.estimates?.[projectId] ?? []).map((estimate) =>
estimate.id === estimateId ? { ...estimate, ...data.estimate } : estimate
);

runInAction(() => {
set(this.estimates, projectId, updatedEstimates);
});

const response = await this.estimateService.patchEstimate(workspaceSlug, projectId, estimateId, data);

return response;
} catch (error) {
console.log("Failed to update estimate from project store");

this.fetchProjectEstimates(workspaceSlug, projectId);

throw error;
}
};
});

/**
* @description deletes the given estimate for the given project
* @param workspaceSlug
* @param projectId
* @param estimateId
*/
deleteEstimate = async (workspaceSlug: string, projectId: string, estimateId: string) => {
try {
deleteEstimate = async (workspaceSlug: string, projectId: string, estimateId: string) =>
await this.estimateService.deleteEstimate(workspaceSlug, projectId, estimateId).then(() => {
const updatedEstimates = (this.estimates?.[projectId] ?? []).filter((estimate) => estimate.id !== estimateId);

runInAction(() => {
set(this.estimates, projectId, updatedEstimates);
});

await this.estimateService.deleteEstimate(workspaceSlug, projectId, estimateId);
} catch (error) {
console.log("Failed to delete estimate from project store");

this.fetchProjectEstimates(workspaceSlug, projectId);
}
};
});
}
Loading