[WEB-2707] fix: draft issue module update and code refactor (#5889)
* chore: draft issue module update * chore: code refactor
This commit is contained in:
parent
4c20be6cf2
commit
36b868e375
2 changed files with 8 additions and 36 deletions
|
|
@ -177,7 +177,6 @@ export const DraftIssueBlock: FC<Props> = observer((props) => {
|
||||||
updateIssue={async (projectId, issueId, data) => {
|
updateIssue={async (projectId, issueId, data) => {
|
||||||
await updateIssue(workspaceSlug, issueId, data);
|
await updateIssue(workspaceSlug, issueId, data);
|
||||||
}}
|
}}
|
||||||
activeLayout="List"
|
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className={cn("hidden", {
|
className={cn("hidden", {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useMemo } from "react";
|
import { useCallback, useMemo } from "react";
|
||||||
import xor from "lodash/xor";
|
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { useParams, usePathname } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
// icons
|
// icons
|
||||||
import { CalendarCheck2, CalendarClock } from "lucide-react";
|
import { CalendarCheck2, CalendarClock } from "lucide-react";
|
||||||
// types
|
// types
|
||||||
import { TIssue, TIssuePriorities, TWorkspaceDraftIssue } from "@plane/types";
|
import { TIssuePriorities, TWorkspaceDraftIssue } from "@plane/types";
|
||||||
// components
|
// components
|
||||||
import {
|
import {
|
||||||
DateDropdown,
|
DateDropdown,
|
||||||
|
|
@ -18,20 +17,11 @@ import {
|
||||||
CycleDropdown,
|
CycleDropdown,
|
||||||
StateDropdown,
|
StateDropdown,
|
||||||
} from "@/components/dropdowns";
|
} from "@/components/dropdowns";
|
||||||
// constants
|
|
||||||
import { ISSUE_UPDATED } from "@/constants/event-tracker";
|
|
||||||
// helpers
|
// helpers
|
||||||
import { getDate, renderFormattedPayloadDate } from "@/helpers/date-time.helper";
|
import { getDate, renderFormattedPayloadDate } from "@/helpers/date-time.helper";
|
||||||
import { shouldHighlightIssueDueDate } from "@/helpers/issue.helper";
|
import { shouldHighlightIssueDueDate } from "@/helpers/issue.helper";
|
||||||
// hooks
|
// hooks
|
||||||
import {
|
import { useLabel, useProjectState, useProject, useProjectEstimates, useWorkspaceDraftIssues } from "@/hooks/store";
|
||||||
useEventTracker,
|
|
||||||
useLabel,
|
|
||||||
useProjectState,
|
|
||||||
useProject,
|
|
||||||
useProjectEstimates,
|
|
||||||
useWorkspaceDraftIssues,
|
|
||||||
} from "@/hooks/store";
|
|
||||||
import { usePlatformOS } from "@/hooks/use-platform-os";
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
||||||
// local components
|
// local components
|
||||||
import { IssuePropertyLabels } from "../issue-layouts";
|
import { IssuePropertyLabels } from "../issue-layouts";
|
||||||
|
|
@ -42,15 +32,13 @@ export interface IIssueProperties {
|
||||||
| ((projectId: string | null, issueId: string, data: Partial<TWorkspaceDraftIssue>) => Promise<void>)
|
| ((projectId: string | null, issueId: string, data: Partial<TWorkspaceDraftIssue>) => Promise<void>)
|
||||||
| undefined;
|
| undefined;
|
||||||
className: string;
|
className: string;
|
||||||
activeLayout: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DraftIssueProperties: React.FC<IIssueProperties> = observer((props) => {
|
export const DraftIssueProperties: React.FC<IIssueProperties> = observer((props) => {
|
||||||
const { issue, updateIssue, activeLayout, className } = props;
|
const { issue, updateIssue, className } = props;
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getProjectById } = useProject();
|
const { getProjectById } = useProject();
|
||||||
const { labelMap } = useLabel();
|
const { labelMap } = useLabel();
|
||||||
const { captureIssueEvent } = useEventTracker();
|
|
||||||
const { addCycleToIssue, addModulesToIssue } = useWorkspaceDraftIssues();
|
const { addCycleToIssue, addModulesToIssue } = useWorkspaceDraftIssues();
|
||||||
const { areEstimateEnabledByProjectId } = useProjectEstimates();
|
const { areEstimateEnabledByProjectId } = useProjectEstimates();
|
||||||
const { getStateById } = useProjectState();
|
const { getStateById } = useProjectState();
|
||||||
|
|
@ -59,19 +47,12 @@ export const DraftIssueProperties: React.FC<IIssueProperties> = observer((props)
|
||||||
|
|
||||||
// router
|
// router
|
||||||
const { workspaceSlug } = useParams();
|
const { workspaceSlug } = useParams();
|
||||||
const pathname = usePathname();
|
|
||||||
|
|
||||||
const currentLayout = `${activeLayout} layout`;
|
|
||||||
// derived values
|
// derived values
|
||||||
const stateDetails = getStateById(issue.state_id);
|
const stateDetails = getStateById(issue.state_id);
|
||||||
|
|
||||||
const issueOperations = useMemo(
|
const issueOperations = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
addModulesToIssue: async (moduleIds: string[]) => {
|
updateIssueModules: async (moduleIds: string[]) => {
|
||||||
if (!workspaceSlug || !issue.id) return;
|
|
||||||
await addModulesToIssue(workspaceSlug.toString(), issue.id, moduleIds);
|
|
||||||
},
|
|
||||||
removeModulesFromIssue: async (moduleIds: string[]) => {
|
|
||||||
if (!workspaceSlug || !issue.id) return;
|
if (!workspaceSlug || !issue.id) return;
|
||||||
await addModulesToIssue(workspaceSlug.toString(), issue.id, moduleIds);
|
await addModulesToIssue(workspaceSlug.toString(), issue.id, moduleIds);
|
||||||
},
|
},
|
||||||
|
|
@ -103,17 +84,9 @@ export const DraftIssueProperties: React.FC<IIssueProperties> = observer((props)
|
||||||
const handleModule = useCallback(
|
const handleModule = useCallback(
|
||||||
(moduleIds: string[] | null) => {
|
(moduleIds: string[] | null) => {
|
||||||
if (!issue || !issue.module_ids || !moduleIds) return;
|
if (!issue || !issue.module_ids || !moduleIds) return;
|
||||||
|
issueOperations.updateIssueModules(moduleIds);
|
||||||
const updatedModuleIds = xor(issue.module_ids, moduleIds);
|
|
||||||
const modulesToAdd: string[] = [];
|
|
||||||
const modulesToRemove: string[] = [];
|
|
||||||
for (const moduleId of updatedModuleIds)
|
|
||||||
if (issue.module_ids.includes(moduleId)) modulesToRemove.push(moduleId);
|
|
||||||
else modulesToAdd.push(moduleId);
|
|
||||||
if (modulesToAdd.length > 0) issueOperations.addModulesToIssue(modulesToAdd);
|
|
||||||
if (modulesToRemove.length > 0) issueOperations.removeModulesFromIssue(modulesToRemove);
|
|
||||||
},
|
},
|
||||||
[issueOperations, currentLayout, pathname, issue]
|
[issueOperations, issue]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCycle = useCallback(
|
const handleCycle = useCallback(
|
||||||
|
|
@ -122,7 +95,7 @@ export const DraftIssueProperties: React.FC<IIssueProperties> = observer((props)
|
||||||
if (cycleId) issueOperations.addIssueToCycle?.(cycleId);
|
if (cycleId) issueOperations.addIssueToCycle?.(cycleId);
|
||||||
else issueOperations.removeIssueFromCycle?.();
|
else issueOperations.removeIssueFromCycle?.();
|
||||||
},
|
},
|
||||||
[issue, issueOperations, currentLayout, pathname]
|
[issue, issueOperations]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleStartDate = (date: Date | null) =>
|
const handleStartDate = (date: Date | null) =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue