2023-10-18 07:02:02 +00:00
|
|
|
import React, { useCallback } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// components
|
|
|
|
import { SpreadsheetView } from "components/issues";
|
|
|
|
// types
|
|
|
|
import { IIssue, IIssueDisplayFilterOptions } from "types";
|
|
|
|
// constants
|
|
|
|
import { IIssueUnGroupedStructure } from "store/issue";
|
|
|
|
|
|
|
|
export const ProjectSpreadsheetLayout: React.FC = observer(() => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const {
|
|
|
|
issue: issueStore,
|
|
|
|
issueFilter: issueFilterStore,
|
|
|
|
issueDetail: issueDetailStore,
|
2023-11-18 20:16:11 +00:00
|
|
|
projectLabel: { projectLabels },
|
2023-11-09 12:26:55 +00:00
|
|
|
projectMember: { projectMembers },
|
2023-11-08 15:01:46 +00:00
|
|
|
projectState: projectStateStore,
|
2023-10-18 07:02:02 +00:00
|
|
|
user: userStore,
|
|
|
|
} = useMobxStore();
|
|
|
|
|
|
|
|
const user = userStore.currentUser;
|
|
|
|
const issues = issueStore.getIssues;
|
|
|
|
|
|
|
|
const handleDisplayFiltersUpdate = useCallback(
|
|
|
|
(updatedDisplayFilter: Partial<IIssueDisplayFilterOptions>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
|
|
|
issueFilterStore.updateUserFilters(workspaceSlug.toString(), projectId.toString(), {
|
|
|
|
display_filters: {
|
|
|
|
...updatedDisplayFilter,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[issueFilterStore, projectId, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
2023-11-20 06:52:43 +00:00
|
|
|
const handleIssueAction = async (issue: IIssue, action: "copy" | "delete" | "edit") => {
|
|
|
|
if (!workspaceSlug || !projectId || !user) return;
|
|
|
|
|
|
|
|
if (action === "delete") {
|
|
|
|
issueDetailStore.deleteIssue(workspaceSlug.toString(), projectId.toString(), issue.id);
|
|
|
|
issueStore.removeIssueFromStructure(null, null, issue);
|
|
|
|
} else if (action === "edit") {
|
|
|
|
issueDetailStore.updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, issue);
|
|
|
|
issueStore.updateIssueStructure(null, null, issue);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-18 07:02:02 +00:00
|
|
|
const handleUpdateIssue = useCallback(
|
|
|
|
(issue: IIssue, data: Partial<IIssue>) => {
|
|
|
|
if (!workspaceSlug || !projectId || !user) return;
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
...issue,
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
|
|
|
|
issueStore.updateIssueStructure(null, null, payload);
|
2023-10-20 11:37:46 +00:00
|
|
|
issueDetailStore.updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, data);
|
2023-10-18 07:02:02 +00:00
|
|
|
},
|
|
|
|
[issueStore, issueDetailStore, projectId, user, workspaceSlug]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SpreadsheetView
|
|
|
|
displayProperties={issueFilterStore.userDisplayProperties}
|
|
|
|
displayFilters={issueFilterStore.userDisplayFilters}
|
|
|
|
handleDisplayFilterUpdate={handleDisplayFiltersUpdate}
|
|
|
|
issues={issues as IIssueUnGroupedStructure}
|
2023-11-09 12:26:55 +00:00
|
|
|
members={projectMembers?.map((m) => m.member)}
|
2023-11-18 20:16:11 +00:00
|
|
|
labels={projectLabels || undefined}
|
2023-11-08 15:01:46 +00:00
|
|
|
states={projectId ? projectStateStore.states?.[projectId.toString()] : undefined}
|
2023-11-20 06:52:43 +00:00
|
|
|
handleIssueAction={handleIssueAction}
|
2023-10-18 07:02:02 +00:00
|
|
|
handleUpdateIssue={handleUpdateIssue}
|
|
|
|
disableUserActions={false}
|
2023-10-27 07:02:24 +00:00
|
|
|
enableQuickCreateIssue
|
2023-10-18 07:02:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|