2024-03-06 13:09:14 +00:00
|
|
|
import size from "lodash/size";
|
2024-01-24 13:42:54 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// hooks
|
2024-03-06 14:46:54 +00:00
|
|
|
import { useApplication, useEventTracker, useIssues } from "hooks/store";
|
2024-01-24 13:42:54 +00:00
|
|
|
// components
|
2024-03-06 14:46:54 +00:00
|
|
|
import { EmptyState } from "components/empty-state";
|
2024-01-24 13:42:54 +00:00
|
|
|
// constants
|
2024-03-06 14:46:54 +00:00
|
|
|
import { EIssueFilterType, EIssuesStoreType } from "constants/issue";
|
|
|
|
import { EmptyStateType } from "constants/empty-state";
|
2024-01-24 13:42:54 +00:00
|
|
|
// types
|
|
|
|
import { IIssueFilterOptions } from "@plane/types";
|
|
|
|
|
|
|
|
export const ProjectEmptyState: React.FC = observer(() => {
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
// store hooks
|
2024-02-05 07:49:07 +00:00
|
|
|
const { commandPalette: commandPaletteStore } = useApplication();
|
|
|
|
const { setTrackElement } = useEventTracker();
|
2024-03-06 14:46:54 +00:00
|
|
|
|
2024-01-24 13:42:54 +00:00
|
|
|
const { issuesFilter } = useIssues(EIssuesStoreType.PROJECT);
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
newFilters[key as keyof IIssueFilterOptions] = null;
|
|
|
|
});
|
|
|
|
issuesFilter.updateFilters(workspaceSlug.toString(), projectId.toString(), EIssueFilterType.FILTERS, {
|
|
|
|
...newFilters,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
const emptyStateType = issueFilterCount > 0 ? EmptyStateType.PROJECT_EMPTY_FILTER : EmptyStateType.PROJECT_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}
|
|
|
|
primaryButtonOnClick={
|
|
|
|
issueFilterCount > 0
|
|
|
|
? undefined
|
|
|
|
: () => {
|
|
|
|
setTrackElement("Project issue empty state");
|
|
|
|
commandPaletteStore.toggleCreateIssueModal(true, EIssuesStoreType.PROJECT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
secondaryButtonOnClick={issueFilterCount > 0 ? handleClearAllFilters : undefined}
|
|
|
|
/>
|
2024-01-24 13:42:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|