2024-03-06 13:09:14 +00:00
|
|
|
import size from "lodash/size";
|
2024-04-29 06:42:33 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-01-24 13:42:54 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IIssueFilterOptions } from "@plane/types";
|
2024-01-24 13:42:54 +00:00
|
|
|
// hooks
|
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { EmptyState } from "@/components/empty-state";
|
2024-01-24 13:42:54 +00:00
|
|
|
// constants
|
2024-03-19 14:38:35 +00:00
|
|
|
import { EmptyStateType } from "@/constants/empty-state";
|
|
|
|
import { EIssueFilterType, EIssuesStoreType } from "@/constants/issue";
|
|
|
|
import { useIssues } from "@/hooks/store";
|
2024-01-24 13:42:54 +00:00
|
|
|
// types
|
|
|
|
|
|
|
|
export const ProjectDraftEmptyState: React.FC = observer(() => {
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
2024-01-29 15:08:32 +00:00
|
|
|
// store hooks
|
2024-01-24 13:42:54 +00:00
|
|
|
const { issuesFilter } = useIssues(EIssuesStoreType.DRAFT);
|
|
|
|
|
|
|
|
const userFilters = issuesFilter?.issueFilters?.filters;
|
|
|
|
const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout;
|
|
|
|
|
|
|
|
const issueFilterCount = size(
|
|
|
|
Object.fromEntries(
|
2024-01-30 08:29:07 +00:00
|
|
|
Object.entries(userFilters ?? {}).filter(([, value]) => value && Array.isArray(value) && value.length > 0)
|
2024-01-24 13:42:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleClearAllFilters = () => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
const newFilters: IIssueFilterOptions = {};
|
|
|
|
Object.keys(userFilters ?? {}).forEach((key) => {
|
2024-03-07 11:23:59 +00:00
|
|
|
newFilters[key as keyof IIssueFilterOptions] = [];
|
2024-01-24 13:42:54 +00:00
|
|
|
});
|
|
|
|
issuesFilter.updateFilters(workspaceSlug.toString(), projectId.toString(), EIssueFilterType.FILTERS, {
|
|
|
|
...newFilters,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
const emptyStateType =
|
|
|
|
issueFilterCount > 0 ? EmptyStateType.PROJECT_DRAFT_EMPTY_FILTER : EmptyStateType.PROJECT_DRAFT_NO_ISSUES;
|
|
|
|
const additionalPath = issueFilterCount > 0 ? activeLayout ?? "list" : undefined;
|
|
|
|
const emptyStateSize = issueFilterCount > 0 ? "lg" : "sm";
|
2024-01-24 13:42:54 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="relative h-full w-full overflow-y-auto">
|
2024-03-06 14:46:54 +00:00
|
|
|
<EmptyState
|
|
|
|
type={emptyStateType}
|
|
|
|
additionalPath={additionalPath}
|
|
|
|
size={emptyStateSize}
|
|
|
|
secondaryButtonOnClick={issueFilterCount > 0 ? handleClearAllFilters : undefined}
|
|
|
|
/>
|
2024-01-24 13:42:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|