2023-06-23 11:50:05 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
|
|
// next
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// components
|
|
|
|
import { SpreadsheetColumns, SpreadsheetIssues } from "components/core";
|
2023-06-26 12:31:28 +00:00
|
|
|
import { CustomMenu, Icon, Spinner } from "components/ui";
|
2023-06-23 11:50:05 +00:00
|
|
|
// hooks
|
|
|
|
import useIssuesProperties from "hooks/use-issue-properties";
|
|
|
|
import useSpreadsheetIssuesView from "hooks/use-spreadsheet-issues-view";
|
|
|
|
// types
|
|
|
|
import { ICurrentUserResponse, IIssue, Properties, UserAuth } from "types";
|
|
|
|
// constants
|
|
|
|
import { SPREADSHEET_COLUMN } from "constants/spreadsheet";
|
|
|
|
// icon
|
|
|
|
import { PlusIcon } from "@heroicons/react/24/outline";
|
|
|
|
|
|
|
|
type Props = {
|
2023-06-26 12:31:28 +00:00
|
|
|
type: "issue" | "cycle" | "module";
|
2023-06-23 11:50:05 +00:00
|
|
|
handleEditIssue: (issue: IIssue) => void;
|
|
|
|
handleDeleteIssue: (issue: IIssue) => void;
|
2023-06-26 12:31:28 +00:00
|
|
|
openIssuesListModal?: (() => void) | null;
|
|
|
|
isCompleted?: boolean;
|
2023-06-23 11:50:05 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
|
|
|
userAuth: UserAuth;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SpreadsheetView: React.FC<Props> = ({
|
2023-06-26 12:31:28 +00:00
|
|
|
type,
|
2023-06-23 11:50:05 +00:00
|
|
|
handleEditIssue,
|
|
|
|
handleDeleteIssue,
|
2023-06-26 12:31:28 +00:00
|
|
|
openIssuesListModal,
|
|
|
|
isCompleted = false,
|
2023-06-23 11:50:05 +00:00
|
|
|
user,
|
|
|
|
userAuth,
|
|
|
|
}) => {
|
|
|
|
const [expandedIssues, setExpandedIssues] = useState<string[]>([]);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const { spreadsheetIssues } = useSpreadsheetIssuesView();
|
|
|
|
|
|
|
|
const [properties] = useIssuesProperties(workspaceSlug as string, projectId as string);
|
|
|
|
|
|
|
|
const columnData = SPREADSHEET_COLUMN.map((column) => ({
|
|
|
|
...column,
|
|
|
|
isActive: properties
|
|
|
|
? column.propertyName === "labels"
|
|
|
|
? properties[column.propertyName as keyof Properties]
|
|
|
|
: column.propertyName === "title"
|
|
|
|
? true
|
|
|
|
: properties[column.propertyName as keyof Properties]
|
|
|
|
: false,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const gridTemplateColumns = columnData
|
|
|
|
.filter((column) => column.isActive)
|
|
|
|
.map((column) => column.colSize)
|
|
|
|
.join(" ");
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="h-full rounded-lg text-brand-secondary overflow-x-auto whitespace-nowrap bg-brand-base">
|
2023-06-27 11:42:21 +00:00
|
|
|
<div className="sticky z-[2] top-0 border-b border-brand-base bg-brand-surface-1 w-full min-w-max">
|
2023-06-23 11:50:05 +00:00
|
|
|
<SpreadsheetColumns columnData={columnData} gridTemplateColumns={gridTemplateColumns} />
|
|
|
|
</div>
|
|
|
|
{spreadsheetIssues ? (
|
|
|
|
<div className="flex flex-col h-full w-full bg-brand-base rounded-sm ">
|
|
|
|
{spreadsheetIssues.map((issue: IIssue, index) => (
|
|
|
|
<SpreadsheetIssues
|
|
|
|
key={`${issue.id}_${index}`}
|
2023-06-28 11:57:43 +00:00
|
|
|
index={index}
|
2023-06-23 11:50:05 +00:00
|
|
|
issue={issue}
|
|
|
|
expandedIssues={expandedIssues}
|
|
|
|
setExpandedIssues={setExpandedIssues}
|
|
|
|
gridTemplateColumns={gridTemplateColumns}
|
|
|
|
properties={properties}
|
|
|
|
handleEditIssue={handleEditIssue}
|
|
|
|
handleDeleteIssue={handleDeleteIssue}
|
2023-06-27 11:42:21 +00:00
|
|
|
isCompleted={isCompleted}
|
2023-06-23 11:50:05 +00:00
|
|
|
user={user}
|
|
|
|
userAuth={userAuth}
|
|
|
|
/>
|
|
|
|
))}
|
2023-06-26 08:54:52 +00:00
|
|
|
<div
|
|
|
|
className="relative group grid auto-rows-[minmax(44px,1fr)] hover:rounded-sm hover:bg-brand-surface-2 border-b border-brand-base w-full min-w-max"
|
|
|
|
style={{ gridTemplateColumns }}
|
2023-06-23 11:50:05 +00:00
|
|
|
>
|
2023-06-26 12:31:28 +00:00
|
|
|
{type === "issue" ? (
|
|
|
|
<button
|
|
|
|
className="flex gap-1.5 items-center pl-7 py-2.5 text-sm sticky left-0 z-[1] text-brand-secondary bg-brand-base group-hover:text-brand-base group-hover:bg-brand-surface-2 border-brand-base w-full"
|
|
|
|
onClick={() => {
|
|
|
|
const e = new KeyboardEvent("keydown", { key: "c" });
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<PlusIcon className="h-4 w-4" />
|
|
|
|
Add Issue
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
!isCompleted && (
|
|
|
|
<CustomMenu
|
|
|
|
className="sticky left-0 z-[1]"
|
|
|
|
customButton={
|
|
|
|
<button
|
|
|
|
className="flex gap-1.5 items-center pl-7 py-2.5 text-sm sticky left-0 z-[1] text-brand-secondary bg-brand-base group-hover:text-brand-base group-hover:bg-brand-surface-2 border-brand-base w-full"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<PlusIcon className="h-4 w-4" />
|
|
|
|
Add Issue
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
position="left"
|
|
|
|
menuItemsClassName="left-5 !w-36"
|
|
|
|
noBorder
|
|
|
|
>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={() => {
|
|
|
|
const e = new KeyboardEvent("keydown", { key: "c" });
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Create new
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
{openIssuesListModal && (
|
|
|
|
<CustomMenu.MenuItem onClick={openIssuesListModal}>
|
|
|
|
Add an existing issue
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
|
|
|
</CustomMenu>
|
|
|
|
)
|
|
|
|
)}
|
2023-06-26 08:54:52 +00:00
|
|
|
</div>
|
2023-06-23 11:50:05 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Spinner />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|