2024-05-08 08:29:51 +00:00
|
|
|
import { Dispatch, MouseEvent, MutableRefObject, SetStateAction, useRef, useState } from "react";
|
2024-05-08 17:31:20 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-01-11 15:31:05 +00:00
|
|
|
// icons
|
|
|
|
import { ChevronRight, MoreHorizontal } from "lucide-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IIssueDisplayProperties, TIssue } from "@plane/types";
|
2024-01-11 15:31:05 +00:00
|
|
|
// ui
|
2024-01-12 08:22:04 +00:00
|
|
|
import { ControlLink, Tooltip } from "@plane/ui";
|
2024-03-06 13:09:14 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import RenderIfVisible from "@/components/core/render-if-visible-HOC";
|
2024-01-30 14:42:39 +00:00
|
|
|
// helper
|
2024-03-19 14:38:35 +00:00
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-03-06 13:09:14 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useIssueDetail, useProject } from "@/hooks/store";
|
|
|
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
|
|
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
2024-01-11 15:31:05 +00:00
|
|
|
// types
|
2024-03-06 13:09:14 +00:00
|
|
|
// local components
|
2024-04-30 13:29:07 +00:00
|
|
|
import { TRenderQuickActions } from "../list/list-view-types";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { WithDisplayPropertiesHOC } from "../properties/with-display-properties-HOC";
|
|
|
|
import { IssueColumn } from "./issue-column";
|
2024-01-11 12:49:19 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
displayProperties: IIssueDisplayProperties;
|
|
|
|
isEstimateEnabled: boolean;
|
2024-04-30 13:29:07 +00:00
|
|
|
quickActions: TRenderQuickActions;
|
2024-01-11 12:49:19 +00:00
|
|
|
canEditProperties: (projectId: string | undefined) => boolean;
|
2024-03-06 15:17:38 +00:00
|
|
|
updateIssue: ((projectId: string, issueId: string, data: Partial<TIssue>) => Promise<void>) | undefined;
|
2024-01-11 12:49:19 +00:00
|
|
|
portalElement: React.MutableRefObject<HTMLDivElement | null>;
|
|
|
|
nestingLevel: number;
|
|
|
|
issueId: string;
|
2024-02-09 10:23:15 +00:00
|
|
|
isScrolled: MutableRefObject<boolean>;
|
|
|
|
containerRef: MutableRefObject<HTMLTableElement | null>;
|
|
|
|
issueIds: string[];
|
2024-04-04 10:19:25 +00:00
|
|
|
spreadsheetColumnsList: (keyof IIssueDisplayProperties)[];
|
2024-05-08 08:29:51 +00:00
|
|
|
spacingLeft?: number;
|
2024-01-11 12:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const SpreadsheetIssueRow = observer((props: Props) => {
|
|
|
|
const {
|
|
|
|
displayProperties,
|
|
|
|
issueId,
|
|
|
|
isEstimateEnabled,
|
|
|
|
nestingLevel,
|
|
|
|
portalElement,
|
2024-03-06 15:17:38 +00:00
|
|
|
updateIssue,
|
2024-01-11 12:49:19 +00:00
|
|
|
quickActions,
|
|
|
|
canEditProperties,
|
2024-02-09 10:23:15 +00:00
|
|
|
isScrolled,
|
|
|
|
containerRef,
|
|
|
|
issueIds,
|
2024-04-04 10:19:25 +00:00
|
|
|
spreadsheetColumnsList,
|
2024-05-08 08:29:51 +00:00
|
|
|
spacingLeft = 14,
|
2024-01-11 12:49:19 +00:00
|
|
|
} = props;
|
2024-01-12 08:22:04 +00:00
|
|
|
|
2024-02-09 10:23:15 +00:00
|
|
|
const [isExpanded, setExpanded] = useState<boolean>(false);
|
|
|
|
const { subIssues: subIssuesStore } = useIssueDetail();
|
|
|
|
|
|
|
|
const subIssues = subIssuesStore.subIssuesByIssueId(issueId);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{/* first column/ issue name and key column */}
|
|
|
|
<RenderIfVisible
|
|
|
|
as="tr"
|
|
|
|
defaultHeight="calc(2.75rem - 1px)"
|
|
|
|
root={containerRef}
|
2024-02-12 14:55:37 +00:00
|
|
|
placeholderChildren={<td colSpan={100} className="border-b-[0.5px] border-custom-border-200" />}
|
2024-02-09 10:23:15 +00:00
|
|
|
changingReference={issueIds}
|
|
|
|
>
|
|
|
|
<IssueRowDetails
|
|
|
|
issueId={issueId}
|
|
|
|
displayProperties={displayProperties}
|
|
|
|
quickActions={quickActions}
|
|
|
|
canEditProperties={canEditProperties}
|
|
|
|
nestingLevel={nestingLevel}
|
2024-05-08 08:29:51 +00:00
|
|
|
spacingLeft={spacingLeft}
|
2024-02-09 10:23:15 +00:00
|
|
|
isEstimateEnabled={isEstimateEnabled}
|
2024-03-06 15:17:38 +00:00
|
|
|
updateIssue={updateIssue}
|
2024-02-09 10:23:15 +00:00
|
|
|
portalElement={portalElement}
|
|
|
|
isScrolled={isScrolled}
|
|
|
|
isExpanded={isExpanded}
|
|
|
|
setExpanded={setExpanded}
|
2024-04-04 10:19:25 +00:00
|
|
|
spreadsheetColumnsList={spreadsheetColumnsList}
|
2024-02-09 10:23:15 +00:00
|
|
|
/>
|
|
|
|
</RenderIfVisible>
|
|
|
|
|
|
|
|
{isExpanded &&
|
|
|
|
subIssues &&
|
|
|
|
subIssues.length > 0 &&
|
|
|
|
subIssues.map((subIssueId: string) => (
|
|
|
|
<SpreadsheetIssueRow
|
|
|
|
key={subIssueId}
|
|
|
|
issueId={subIssueId}
|
|
|
|
displayProperties={displayProperties}
|
|
|
|
quickActions={quickActions}
|
|
|
|
canEditProperties={canEditProperties}
|
|
|
|
nestingLevel={nestingLevel + 1}
|
2024-05-08 08:29:51 +00:00
|
|
|
spacingLeft={spacingLeft + (displayProperties.key ? 16 : 28)}
|
2024-02-09 10:23:15 +00:00
|
|
|
isEstimateEnabled={isEstimateEnabled}
|
2024-03-06 15:17:38 +00:00
|
|
|
updateIssue={updateIssue}
|
2024-02-09 10:23:15 +00:00
|
|
|
portalElement={portalElement}
|
|
|
|
isScrolled={isScrolled}
|
|
|
|
containerRef={containerRef}
|
|
|
|
issueIds={issueIds}
|
2024-04-04 10:19:25 +00:00
|
|
|
spreadsheetColumnsList={spreadsheetColumnsList}
|
2024-02-09 10:23:15 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IssueRowDetailsProps {
|
|
|
|
displayProperties: IIssueDisplayProperties;
|
|
|
|
isEstimateEnabled: boolean;
|
2024-04-30 13:29:07 +00:00
|
|
|
quickActions: TRenderQuickActions;
|
2024-02-09 10:23:15 +00:00
|
|
|
canEditProperties: (projectId: string | undefined) => boolean;
|
2024-03-06 15:17:38 +00:00
|
|
|
updateIssue: ((projectId: string, issueId: string, data: Partial<TIssue>) => Promise<void>) | undefined;
|
2024-02-09 10:23:15 +00:00
|
|
|
portalElement: React.MutableRefObject<HTMLDivElement | null>;
|
|
|
|
nestingLevel: number;
|
|
|
|
issueId: string;
|
|
|
|
isScrolled: MutableRefObject<boolean>;
|
|
|
|
isExpanded: boolean;
|
|
|
|
setExpanded: Dispatch<SetStateAction<boolean>>;
|
2024-04-04 10:19:25 +00:00
|
|
|
spreadsheetColumnsList: (keyof IIssueDisplayProperties)[];
|
2024-05-08 08:29:51 +00:00
|
|
|
spacingLeft?: number;
|
2024-02-09 10:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const IssueRowDetails = observer((props: IssueRowDetailsProps) => {
|
|
|
|
const {
|
|
|
|
displayProperties,
|
|
|
|
issueId,
|
|
|
|
isEstimateEnabled,
|
|
|
|
nestingLevel,
|
|
|
|
portalElement,
|
2024-03-06 15:17:38 +00:00
|
|
|
updateIssue,
|
2024-02-09 10:23:15 +00:00
|
|
|
quickActions,
|
|
|
|
canEditProperties,
|
|
|
|
isScrolled,
|
|
|
|
isExpanded,
|
|
|
|
setExpanded,
|
2024-04-04 10:19:25 +00:00
|
|
|
spreadsheetColumnsList,
|
2024-05-08 08:29:51 +00:00
|
|
|
spacingLeft = 14,
|
2024-02-09 10:23:15 +00:00
|
|
|
} = props;
|
2024-04-30 13:29:07 +00:00
|
|
|
// states
|
|
|
|
const [isMenuActive, setIsMenuActive] = useState(false);
|
|
|
|
// refs
|
|
|
|
const cellRef = useRef(null);
|
|
|
|
const menuActionRef = useRef<HTMLDivElement | null>(null);
|
2024-01-11 12:49:19 +00:00
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
2024-04-30 13:29:07 +00:00
|
|
|
// hooks
|
2024-02-28 09:48:11 +00:00
|
|
|
const { getProjectIdentifierById } = useProject();
|
2024-04-30 11:50:02 +00:00
|
|
|
const { getIsIssuePeeked, setPeekIssue } = useIssueDetail();
|
2024-03-12 15:09:36 +00:00
|
|
|
const { isMobile } = usePlatformOS();
|
2024-01-11 12:49:19 +00:00
|
|
|
|
2024-04-08 13:08:05 +00:00
|
|
|
const handleIssuePeekOverview = (issue: TIssue) =>
|
|
|
|
workspaceSlug &&
|
|
|
|
issue &&
|
|
|
|
issue.project_id &&
|
|
|
|
issue.id &&
|
2024-04-30 11:50:02 +00:00
|
|
|
!getIsIssuePeeked(issue.id) &&
|
2024-04-08 13:08:05 +00:00
|
|
|
setPeekIssue({ workspaceSlug: workspaceSlug.toString(), projectId: issue.project_id, issueId: issue.id });
|
2024-01-11 12:49:19 +00:00
|
|
|
|
|
|
|
const { subIssues: subIssuesStore, issue } = useIssueDetail();
|
|
|
|
|
|
|
|
const issueDetail = issue.getIssueById(issueId);
|
|
|
|
|
2024-05-08 08:29:51 +00:00
|
|
|
const paddingLeft = `${spacingLeft}px`;
|
2024-01-11 12:49:19 +00:00
|
|
|
|
|
|
|
useOutsideClickDetector(menuActionRef, () => setIsMenuActive(false));
|
|
|
|
|
|
|
|
const customActionButton = (
|
|
|
|
<div
|
|
|
|
ref={menuActionRef}
|
2024-05-08 08:29:51 +00:00
|
|
|
className={`flex items-center h-full w-full cursor-pointer rounded p-1 text-custom-sidebar-text-400 hover:bg-custom-background-80 ${
|
2024-01-11 12:49:19 +00:00
|
|
|
isMenuActive ? "bg-custom-background-80 text-custom-text-100" : "text-custom-text-200"
|
|
|
|
}`}
|
|
|
|
onClick={() => setIsMenuActive(!isMenuActive)}
|
|
|
|
>
|
|
|
|
<MoreHorizontal className="h-3.5 w-3.5" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
if (!issueDetail) return null;
|
|
|
|
|
2024-05-08 08:29:51 +00:00
|
|
|
const handleToggleExpand = (e: MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
if (nestingLevel >= 3) {
|
|
|
|
handleIssuePeekOverview(issueDetail);
|
|
|
|
} else {
|
|
|
|
setExpanded((prevState) => {
|
|
|
|
if (!prevState && workspaceSlug && issueDetail)
|
|
|
|
subIssuesStore.fetchSubIssues(workspaceSlug.toString(), issueDetail.project_id, issueDetail.id);
|
|
|
|
return !prevState;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-11 12:49:19 +00:00
|
|
|
const disableUserActions = !canEditProperties(issueDetail.project_id);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-05-08 08:29:51 +00:00
|
|
|
<td ref={cellRef} id={`issue-${issueDetail.id}`} tabIndex={0}>
|
|
|
|
<ControlLink
|
|
|
|
id={`issue-${issueId}`}
|
|
|
|
href={`/${workspaceSlug}/projects/${issueDetail.project_id}/issues/${issueId}`}
|
|
|
|
target="_blank"
|
|
|
|
onClick={() => handleIssuePeekOverview(issueDetail)}
|
|
|
|
className={cn(
|
|
|
|
"group clickable cursor-pointer sticky left-0 h-11 w-[28rem] flex items-center bg-custom-background-100 text-sm after:absolute border-r-[0.5px] z-10 border-custom-border-200",
|
|
|
|
{
|
|
|
|
"border-b-[0.5px]": !getIsIssuePeeked(issueDetail.id),
|
|
|
|
"border border-custom-primary-70 hover:border-custom-primary-70": getIsIssuePeeked(issueDetail.id),
|
|
|
|
"shadow-[8px_22px_22px_10px_rgba(0,0,0,0.05)]": isScrolled.current,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
disabled={!!issueDetail?.tempId}
|
|
|
|
>
|
2024-02-09 10:23:15 +00:00
|
|
|
<div
|
2024-05-08 08:29:51 +00:00
|
|
|
className="flex min-w-min items-center gap-1 px-4 py-2.5 pr-0"
|
2024-02-09 10:23:15 +00:00
|
|
|
style={issueDetail.parent_id && nestingLevel !== 0 ? { paddingLeft } : {}}
|
|
|
|
>
|
2024-05-08 08:29:51 +00:00
|
|
|
<div className="flex h-5 w-5 items-center justify-center">
|
|
|
|
{issueDetail.sub_issues_count > 0 && (
|
2024-02-09 10:23:15 +00:00
|
|
|
<button
|
2024-05-08 08:29:51 +00:00
|
|
|
className="flex items-center justify-center h-5 w-5 cursor-pointer rounded-sm text-custom-text-400 hover:text-custom-text-300"
|
|
|
|
onClick={handleToggleExpand}
|
2024-02-08 06:19:00 +00:00
|
|
|
>
|
2024-05-08 08:29:51 +00:00
|
|
|
<ChevronRight className={`h-4 w-4 ${isExpanded ? "rotate-90" : ""}`} />
|
2024-02-09 10:23:15 +00:00
|
|
|
</button>
|
2024-05-08 08:29:51 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<WithDisplayPropertiesHOC displayProperties={displayProperties} displayPropertyKey="key">
|
|
|
|
<div className="relative flex cursor-pointer items-center text-center text-xs hover:text-custom-text-100">
|
|
|
|
<p className={`flex items-center justify-center font-medium leading-7`}>
|
|
|
|
{getProjectIdentifierById(issueDetail.project_id)}-{issueDetail.sequence_id}
|
|
|
|
</p>
|
2024-02-09 10:23:15 +00:00
|
|
|
</div>
|
2024-05-08 08:29:51 +00:00
|
|
|
</WithDisplayPropertiesHOC>
|
2024-02-09 10:23:15 +00:00
|
|
|
</div>
|
2024-05-08 08:29:51 +00:00
|
|
|
|
|
|
|
<div className="flex items-center gap-2 justify-between h-full w-full pr-4 truncate">
|
|
|
|
<div className="w-full line-clamp-1 text-sm text-custom-text-100">
|
|
|
|
<div className="w-full overflow-hidden">
|
|
|
|
<Tooltip tooltipContent={issueDetail.name} isMobile={isMobile}>
|
|
|
|
<div
|
|
|
|
className="h-full w-full cursor-pointer truncate px-4 text-left text-[0.825rem] text-custom-text-100 focus:outline-none"
|
|
|
|
tabIndex={-1}
|
|
|
|
>
|
|
|
|
{issueDetail.name}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2024-02-09 10:23:15 +00:00
|
|
|
</div>
|
2024-05-08 08:29:51 +00:00
|
|
|
</div>
|
|
|
|
<div className={`hidden group-hover:block ${isMenuActive ? "!block" : ""}`}>
|
|
|
|
{quickActions({
|
|
|
|
issue: issueDetail,
|
|
|
|
parentRef: cellRef,
|
|
|
|
customActionButton,
|
|
|
|
portalElement: portalElement.current,
|
|
|
|
})}
|
|
|
|
</div>
|
2024-02-09 10:23:15 +00:00
|
|
|
</div>
|
|
|
|
</ControlLink>
|
|
|
|
</td>
|
|
|
|
{/* Rest of the columns */}
|
2024-04-04 10:19:25 +00:00
|
|
|
{spreadsheetColumnsList.map((property) => (
|
2024-02-21 13:50:46 +00:00
|
|
|
<IssueColumn
|
2024-03-06 13:09:14 +00:00
|
|
|
key={property}
|
2024-02-21 13:50:46 +00:00
|
|
|
displayProperties={displayProperties}
|
|
|
|
issueDetail={issueDetail}
|
|
|
|
disableUserActions={disableUserActions}
|
|
|
|
property={property}
|
2024-03-06 15:17:38 +00:00
|
|
|
updateIssue={updateIssue}
|
2024-02-21 13:50:46 +00:00
|
|
|
isEstimateEnabled={isEstimateEnabled}
|
|
|
|
/>
|
|
|
|
))}
|
2024-01-11 12:49:19 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|