Skip to content

Commit

Permalink
code refactor and improvement (#6203)
Browse files Browse the repository at this point in the history
* chore: package code refactoring

* chore: component restructuring and refactor

* chore: comment create improvement
  • Loading branch information
anmolsinghbhatia authored Dec 16, 2024
1 parent 442b0fd commit 438cc33
Show file tree
Hide file tree
Showing 134 changed files with 1,337 additions and 507 deletions.
5 changes: 5 additions & 0 deletions packages/constants/src/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ export enum EServerGroupByToFilterOptions {
"project_id" = "project",
"created_by" = "created_by",
}

export enum EIssueServiceType {
ISSUES = "issues",
EPICS = "epics",
}
6 changes: 6 additions & 0 deletions packages/types/src/issues/issue.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EIssueServiceType } from "@plane/constants";
import { TIssuePriorities } from "../issues";
import { TIssueAttachment } from "./issue_attachment";
import { TIssueLink } from "./issue_link";
Expand Down Expand Up @@ -39,6 +40,7 @@ export type TBaseIssue = {
updated_by: string;

is_draft: boolean;
is_epic?: boolean;
};

export type IssueRelation = {
Expand Down Expand Up @@ -121,3 +123,7 @@ export type TIssueDetailWidget =
| "relations"
| "links"
| "attachments";

export type TIssueServiceType =
| EIssueServiceType.ISSUES
| EIssueServiceType.EPICS;
1 change: 1 addition & 0 deletions packages/types/src/project/projects.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export type TProjectIssuesSearchParams = {
issue_id?: string;
workspace_search: boolean;
target_date?: string;
epic?: boolean;
};

export interface ISearchIssueResponse {
Expand Down
1 change: 1 addition & 0 deletions web/ce/components/epics/epic-modal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./modal";
19 changes: 19 additions & 0 deletions web/ce/components/epics/epic-modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";
import React, { FC } from "react";
import { TIssue } from "@plane/types";

export interface EpicModalProps {
data?: Partial<TIssue>;
isOpen: boolean;
onClose: () => void;
beforeFormSubmit?: () => Promise<void>;
onSubmit?: (res: TIssue) => Promise<void>;
fetchIssueDetails?: boolean;
primaryButtonText?: {
default: string;
loading: string;
};
isProjectSelectionDisabled?: boolean;
}

export const CreateUpdateEpicModal: FC<EpicModalProps> = (props) => <></>;
1 change: 1 addition & 0 deletions web/ce/components/epics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./epic-modal";
10 changes: 9 additions & 1 deletion web/ce/components/gantt-chart/dependency/dependency-paths.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export const TimelineDependencyPaths = () => <></>;
import { FC } from "react";

type Props = {
isEpic?: boolean;
};
export const TimelineDependencyPaths: FC<Props> = (props) => {
const { isEpic = false } = props;
return <></>;
};
3 changes: 3 additions & 0 deletions web/ce/components/issue-types/values/update.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { TIssueServiceType } from "@plane/types";

export type TIssueAdditionalPropertyValuesUpdateProps = {
issueId: string;
issueTypeId: string;
projectId: string;
workspaceSlug: string;
isDisabled: boolean;
issueServiceType?: TIssueServiceType;
};

export const IssueAdditionalPropertyValuesUpdate: React.FC<TIssueAdditionalPropertyValuesUpdateProps> = () => <></>;
1 change: 1 addition & 0 deletions web/ce/hooks/use-debounced-duplicate-issues.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TDeDupeIssue } from "@plane/types";

export const useDebouncedDuplicateIssues = (
workspaceSlug: string | undefined,
workspaceId: string | undefined,
projectId: string | undefined,
formData: { name: string | undefined; description_html?: string | undefined; issueId?: string | undefined }
Expand Down
15 changes: 15 additions & 0 deletions web/ce/store/issue/epic/filter.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IProjectIssuesFilter, ProjectIssuesFilter } from "@/store/issue/project";
import { IIssueRootStore } from "@/store/issue/root.store";

// @ts-nocheck - This class will never be used, extending similar class to avoid type errors
export type IProjectEpicsFilter = IProjectIssuesFilter;

// @ts-nocheck - This class will never be used, extending similar class to avoid type errors
export class ProjectEpicsFilter extends ProjectIssuesFilter implements IProjectEpicsFilter {
constructor(_rootStore: IIssueRootStore) {
super(_rootStore);

// root store
this.rootIssueStore = _rootStore;
}
}
2 changes: 2 additions & 0 deletions web/ce/store/issue/epic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./filter.store";
export * from "./issue.store";
14 changes: 14 additions & 0 deletions web/ce/store/issue/epic/issue.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IProjectIssues, ProjectIssues } from "@/store/issue/project";
import { IIssueRootStore } from "@/store/issue/root.store";
import { IProjectEpicsFilter } from "./filter.store";

// @ts-nocheck - This class will never be used, extending similar class to avoid type errors

export type IProjectEpics = IProjectIssues;

// @ts-nocheck - This class will never be used, extending similar class to avoid type errors
export class ProjectEpics extends ProjectIssues implements IProjectEpics {
constructor(_rootStore: IIssueRootStore, issueFilterStore: IProjectEpicsFilter) {
super(_rootStore, issueFilterStore);
}
}
40 changes: 27 additions & 13 deletions web/ce/store/issue/issue-details/activity.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import uniq from "lodash/uniq";
import update from "lodash/update";
import { action, makeObservable, observable, runInAction } from "mobx";
import { computedFn } from "mobx-utils";
import { TIssueActivityComment, TIssueActivity, TIssueActivityMap, TIssueActivityIdMap } from "@plane/types";
import { EIssueServiceType } from "@plane/constants";
import {
TIssueActivityComment,
TIssueActivity,
TIssueActivityMap,
TIssueActivityIdMap,
TIssueServiceType,
} from "@plane/types";
// plane web constants
import { EActivityFilterType } from "@/plane-web/constants/issues";
// services
Expand All @@ -29,28 +36,32 @@ export interface IIssueActivityStoreActions {

export interface IIssueActivityStore extends IIssueActivityStoreActions {
// observables
sortOrder: 'asc' | 'desc'
sortOrder: "asc" | "desc";
loader: TActivityLoader;
activities: TIssueActivityIdMap;
activityMap: TIssueActivityMap;
// helper methods
getActivitiesByIssueId: (issueId: string) => string[] | undefined;
getActivityById: (activityId: string) => TIssueActivity | undefined;
getActivityCommentByIssueId: (issueId: string) => TIssueActivityComment[] | undefined;
toggleSortOrder: ()=>void;
toggleSortOrder: () => void;
}

export class IssueActivityStore implements IIssueActivityStore {
// observables
sortOrder: "asc" | "desc" = 'asc';
sortOrder: "asc" | "desc" = "asc";
loader: TActivityLoader = "fetch";
activities: TIssueActivityIdMap = {};
activityMap: TIssueActivityMap = {};

// services
serviceType;
issueActivityService;

constructor(protected store: CoreRootStore) {
constructor(
protected store: CoreRootStore,
serviceType: TIssueServiceType = EIssueServiceType.ISSUES
) {
makeObservable(this, {
// observables
sortOrder: observable.ref,
Expand All @@ -59,10 +70,11 @@ export class IssueActivityStore implements IIssueActivityStore {
activityMap: observable,
// actions
fetchActivities: action,
toggleSortOrder: action
toggleSortOrder: action,
});
this.serviceType = serviceType;
// services
this.issueActivityService = new IssueActivityService();
this.issueActivityService = new IssueActivityService(this.serviceType);
}

// helper methods
Expand All @@ -81,8 +93,10 @@ export class IssueActivityStore implements IIssueActivityStore {

let activityComments: TIssueActivityComment[] = [];

const currentStore = this.serviceType === EIssueServiceType.EPICS ? this.store.epic : this.store.issue;

const activities = this.getActivitiesByIssueId(issueId) || [];
const comments = this.store.issue.issueDetail.comment.getCommentsByIssueId(issueId) || [];
const comments = currentStore.issueDetail.comment.getCommentsByIssueId(issueId) || [];

activities.forEach((activityId) => {
const activity = this.getActivityById(activityId);
Expand All @@ -95,7 +109,7 @@ export class IssueActivityStore implements IIssueActivityStore {
});

comments.forEach((commentId) => {
const comment = this.store.issue.issueDetail.comment.getCommentById(commentId);
const comment = currentStore.issueDetail.comment.getCommentById(commentId);
if (!comment) return;
activityComments.push({
id: comment.id,
Expand All @@ -104,14 +118,14 @@ export class IssueActivityStore implements IIssueActivityStore {
});
});

activityComments = orderBy(activityComments, (e)=>new Date(e.created_at || 0), this.sortOrder);
activityComments = orderBy(activityComments, (e) => new Date(e.created_at || 0), this.sortOrder);

return activityComments;
});

toggleSortOrder = ()=>{
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
}
toggleSortOrder = () => {
this.sortOrder = this.sortOrder === "asc" ? "desc" : "asc";
};

// actions
public async fetchActivities(
Expand Down
55 changes: 35 additions & 20 deletions web/core/components/editor/lite-text-editor/lite-text-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
// editor
import { EditorRefApi, ILiteTextEditor, LiteTextEditorWithRef } from "@plane/editor";
// types
Expand Down Expand Up @@ -27,6 +27,7 @@ interface LiteTextEditorWrapperProps
showAccessSpecifier?: boolean;
showSubmitButton?: boolean;
isSubmitting?: boolean;
showToolbarInitially?: boolean;
uploadFile: (file: File) => Promise<string>;
}

Expand All @@ -41,10 +42,13 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrapp
showAccessSpecifier = false,
showSubmitButton = true,
isSubmitting = false,
showToolbarInitially = true,
placeholder = "Add comment...",
uploadFile,
...rest
} = props;
// states
const [isFocused, setIsFocused] = useState(showToolbarInitially);
// store hooks
const { data: currentUser } = useUser();
const {
Expand Down Expand Up @@ -73,7 +77,11 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrapp
const editorRef = isMutableRefObject<EditorRefApi>(ref) ? ref.current : null;

return (
<div className="border border-custom-border-200 rounded p-3 space-y-3">
<div
className={cn("relative border border-custom-border-200 rounded p-3")}
onFocus={() => !showToolbarInitially && setIsFocused(true)}
onBlur={() => !showToolbarInitially && setIsFocused(false)}
>
<LiteTextEditorWithRef
ref={ref}
disabledExtensions={disabledExtensions}
Expand All @@ -92,24 +100,31 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrapp
containerClassName={cn(containerClassName, "relative")}
{...rest}
/>
<IssueCommentToolbar
accessSpecifier={accessSpecifier}
executeCommand={(item) => {
// TODO: update this while toolbar homogenization
// @ts-expect-error type mismatch here
editorRef?.executeMenuItemCommand({
itemKey: item.itemKey,
...item.extraProps,
});
}}
handleAccessChange={handleAccessChange}
handleSubmit={(e) => rest.onEnterKeyPress?.(e)}
isCommentEmpty={isEmpty}
isSubmitting={isSubmitting}
showAccessSpecifier={showAccessSpecifier}
editorRef={editorRef}
showSubmitButton={showSubmitButton}
/>
<div
className={cn(
"transition-all duration-300 ease-out origin-top overflow-hidden",
isFocused ? "max-h-[200px] opacity-100 scale-y-100 mt-3" : "max-h-0 opacity-0 scale-y-0 invisible"
)}
>
<IssueCommentToolbar
accessSpecifier={accessSpecifier}
executeCommand={(item) => {
// TODO: update this while toolbar homogenization
// @ts-expect-error type mismatch here
editorRef?.executeMenuItemCommand({
itemKey: item.itemKey,
...item.extraProps,
});
}}
handleAccessChange={handleAccessChange}
handleSubmit={(e) => rest.onEnterKeyPress?.(e)}
isCommentEmpty={isEmpty}
isSubmitting={isSubmitting}
showAccessSpecifier={showAccessSpecifier}
editorRef={editorRef}
showSubmitButton={showSubmitButton}
/>
</div>
</div>
);
});
Expand Down
7 changes: 5 additions & 2 deletions web/core/components/gantt-chart/chart/main-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Props = {
targetDate?: Date
) => ChartDataType | undefined;
quickAdd?: React.JSX.Element | undefined;
isEpic?: boolean;
};

export const GanttChartMainContent: React.FC<Props> = observer((props) => {
Expand All @@ -79,6 +80,7 @@ export const GanttChartMainContent: React.FC<Props> = observer((props) => {
updateCurrentViewRenderPayload,
quickAdd,
updateBlockDates,
isEpic = false,
} = props;
// refs
const ganttContainerRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -159,7 +161,7 @@ export const GanttChartMainContent: React.FC<Props> = observer((props) => {
entities={{
[GANTT_SELECT_GROUP]: blockIds ?? [],
}}
disabled={!isBulkOperationsEnabled}
disabled={!isBulkOperationsEnabled || isEpic}
>
{(helpers) => (
<>
Expand Down Expand Up @@ -187,6 +189,7 @@ export const GanttChartMainContent: React.FC<Props> = observer((props) => {
title={title}
quickAdd={quickAdd}
selectionHelpers={helpers}
isEpic={isEpic}
/>
<div className="relative min-h-full h-max flex-shrink-0 flex-grow">
<ActiveChartView />
Expand All @@ -208,7 +211,7 @@ export const GanttChartMainContent: React.FC<Props> = observer((props) => {
selectionHelpers={helpers}
ganttContainerRef={ganttContainerRef}
/>
<TimelineDependencyPaths />
<TimelineDependencyPaths isEpic={isEpic} />
<TimelineDraggablePath />
<GanttChartBlocksList
blockIds={blockIds}
Expand Down
3 changes: 3 additions & 0 deletions web/core/components/gantt-chart/chart/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ChartViewRootProps = {
canLoadMoreBlocks?: boolean;
quickAdd?: React.JSX.Element | undefined;
showToday: boolean;
isEpic?: boolean;
};

const timelineViewHelpers = {
Expand Down Expand Up @@ -71,6 +72,7 @@ export const ChartViewRoot: FC<ChartViewRootProps> = observer((props) => {
quickAdd,
showToday,
updateBlockDates,
isEpic = false,
} = props;
// states
const [itemsContainerWidth, setItemsContainerWidth] = useState(0);
Expand Down Expand Up @@ -204,6 +206,7 @@ export const ChartViewRoot: FC<ChartViewRootProps> = observer((props) => {
updateCurrentViewRenderPayload={updateCurrentViewRenderPayload}
quickAdd={quickAdd}
updateBlockDates={updateBlockDates}
isEpic={isEpic}
/>
</div>
);
Expand Down
Loading

0 comments on commit 438cc33

Please sign in to comment.