import { FC, useCallback } from "react"; import { observer } from "mobx-react-lite"; // types import { TCreateModalStoreTypes } from "constants/issue"; import { EUserProjectRoles } from "constants/project"; import { useIssues, useUser } from "hooks/store"; import { IArchivedIssuesFilter, IArchivedIssues } from "store/issue/archived"; import { ICycleIssues, ICycleIssuesFilter } from "store/issue/cycle"; import { IDraftIssuesFilter, IDraftIssues } from "store/issue/draft"; import { IModuleIssues, IModuleIssuesFilter } from "store/issue/module"; import { IProfileIssues, IProfileIssuesFilter } from "store/issue/profile"; import { IProjectIssues, IProjectIssuesFilter } from "store/issue/project"; import { IProjectViewIssues, IProjectViewIssuesFilter } from "store/issue/project-views"; import { TIssue } from "@plane/types"; import { EIssueActions } from "../types"; // components import { List } from "./default"; import { IQuickActionProps } from "./list-view-types"; // constants // hooks interface IBaseListRoot { issuesFilter: | IProjectIssuesFilter | IModuleIssuesFilter | ICycleIssuesFilter | IProjectViewIssuesFilter | IProfileIssuesFilter | IDraftIssuesFilter | IArchivedIssuesFilter; issues: | IProjectIssues | ICycleIssues | IModuleIssues | IProjectViewIssues | IProfileIssues | IDraftIssues | IArchivedIssues; QuickActions: FC; issueActions: { [EIssueActions.DELETE]: (issue: TIssue) => Promise; [EIssueActions.UPDATE]?: (issue: TIssue) => Promise; [EIssueActions.REMOVE]?: (issue: TIssue) => Promise; [EIssueActions.ARCHIVE]?: (issue: TIssue) => Promise; [EIssueActions.RESTORE]?: (issue: TIssue) => Promise; }; viewId?: string; storeType: TCreateModalStoreTypes; addIssuesToView?: (issueIds: string[]) => Promise; canEditPropertiesBasedOnProject?: (projectId: string) => boolean; isCompletedCycle?: boolean; } export const BaseListRoot = observer((props: IBaseListRoot) => { const { issuesFilter, issues, QuickActions, issueActions, viewId, storeType, addIssuesToView, canEditPropertiesBasedOnProject, isCompletedCycle = false, } = props; // mobx store const { membership: { currentProjectRole }, } = useUser(); const { issueMap } = useIssues(); const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; const issueIds = issues?.groupedIssueIds || []; const { enableInlineEditing, enableQuickAdd, enableIssueCreation } = issues?.viewFlags || {}; const canEditProperties = useCallback( (projectId: string | undefined) => { const isEditingAllowedBasedOnProject = canEditPropertiesBasedOnProject && projectId ? canEditPropertiesBasedOnProject(projectId) : isEditingAllowed; return enableInlineEditing && isEditingAllowedBasedOnProject; }, [canEditPropertiesBasedOnProject, enableInlineEditing, isEditingAllowed] ); const displayFilters = issuesFilter?.issueFilters?.displayFilters; const displayProperties = issuesFilter?.issueFilters?.displayProperties; const group_by = displayFilters?.group_by || null; const showEmptyGroup = displayFilters?.show_empty_groups ?? false; const handleIssues = useCallback( async (issue: TIssue, action: EIssueActions) => { if (issueActions[action]) { await issueActions[action]!(issue); } }, [issueActions] ); const renderQuickActions = useCallback( (issue: TIssue) => ( handleIssues(issue, EIssueActions.DELETE)} handleUpdate={ issueActions[EIssueActions.UPDATE] ? async (data) => handleIssues(data, EIssueActions.UPDATE) : undefined } handleRemoveFromView={ issueActions[EIssueActions.REMOVE] ? async () => handleIssues(issue, EIssueActions.REMOVE) : undefined } handleArchive={ issueActions[EIssueActions.ARCHIVE] ? async () => handleIssues(issue, EIssueActions.ARCHIVE) : undefined } handleRestore={ issueActions[EIssueActions.RESTORE] ? async () => handleIssues(issue, EIssueActions.RESTORE) : undefined } readOnly={!isEditingAllowed || isCompletedCycle} /> ), // eslint-disable-next-line react-hooks/exhaustive-deps [handleIssues] ); return (
); });