2024-03-12 14:54:21 +00:00
|
|
|
import { ReactElement, useCallback } from "react";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-02-20 08:06:38 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { TModuleFilters } from "@plane/types";
|
2022-12-16 16:20:09 +00:00
|
|
|
// layouts
|
2022-12-22 16:19:46 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { PageHead } from "@/components/core";
|
2024-04-09 08:08:07 +00:00
|
|
|
import { EmptyState } from "@/components/empty-state";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { ModulesListHeader } from "@/components/headers";
|
|
|
|
import { ModuleAppliedFiltersList, ModulesListView } from "@/components/modules";
|
2023-11-02 18:27:44 +00:00
|
|
|
// types
|
2024-02-20 08:06:38 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import ModulesListMobileHeader from "@/components/modules/moduels-list-mobile-header";
|
2024-04-09 08:08:07 +00:00
|
|
|
import { EmptyStateType } from "@/constants/empty-state";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { calculateTotalFilters } from "@/helpers/filter.helper";
|
|
|
|
import { useModuleFilter, useProject } from "@/hooks/store";
|
|
|
|
import { AppLayout } from "@/layouts/app-layout";
|
|
|
|
import { NextPageWithLayout } from "@/lib/types";
|
2023-10-23 13:47:42 +00:00
|
|
|
|
2024-02-20 08:06:38 +00:00
|
|
|
const ProjectModulesPage: NextPageWithLayout = observer(() => {
|
|
|
|
const router = useRouter();
|
2024-04-09 08:08:07 +00:00
|
|
|
const { workspaceSlug, projectId } = router.query;
|
2024-02-20 08:06:38 +00:00
|
|
|
// store
|
2024-04-09 08:08:07 +00:00
|
|
|
const { getProjectById, currentProjectDetails } = useProject();
|
2024-03-12 14:54:21 +00:00
|
|
|
const { currentProjectFilters, clearAllFilters, updateFilters } = useModuleFilter();
|
2024-02-20 08:06:38 +00:00
|
|
|
// derived values
|
|
|
|
const project = projectId ? getProjectById(projectId.toString()) : undefined;
|
|
|
|
const pageTitle = project?.name ? `${project?.name} - Modules` : undefined;
|
|
|
|
|
2024-03-12 14:54:21 +00:00
|
|
|
const handleRemoveFilter = useCallback(
|
|
|
|
(key: keyof TModuleFilters, value: string | null) => {
|
|
|
|
if (!projectId) return;
|
|
|
|
let newValues = currentProjectFilters?.[key] ?? [];
|
|
|
|
|
|
|
|
if (!value) newValues = [];
|
|
|
|
else newValues = newValues.filter((val) => val !== value);
|
|
|
|
|
|
|
|
updateFilters(projectId.toString(), { [key]: newValues });
|
|
|
|
},
|
|
|
|
[currentProjectFilters, projectId, updateFilters]
|
|
|
|
);
|
|
|
|
|
2024-04-09 08:08:07 +00:00
|
|
|
if (!workspaceSlug || !projectId) return <></>;
|
|
|
|
|
|
|
|
// No access to
|
|
|
|
if (currentProjectDetails?.module_view === false)
|
|
|
|
return (
|
|
|
|
<div className="flex items-center justify-center h-full w-full">
|
|
|
|
<EmptyState
|
|
|
|
type={EmptyStateType.DISABLED_PROJECT_MODULE}
|
|
|
|
primaryButtonLink={`/${workspaceSlug}/projects/${projectId}/settings/features`}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2024-02-20 08:06:38 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PageHead title={pageTitle} />
|
2024-03-12 14:54:21 +00:00
|
|
|
<div className="h-full w-full flex flex-col">
|
|
|
|
{calculateTotalFilters(currentProjectFilters ?? {}) !== 0 && (
|
|
|
|
<div className="border-b border-custom-border-200 px-5 py-3">
|
|
|
|
<ModuleAppliedFiltersList
|
|
|
|
appliedFilters={currentProjectFilters ?? {}}
|
|
|
|
handleClearAllFilters={() => clearAllFilters(`${projectId}`)}
|
|
|
|
handleRemoveFilter={handleRemoveFilter}
|
|
|
|
alwaysAllowEditing
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<ModulesListView />
|
|
|
|
</div>
|
2024-02-20 08:06:38 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|
2022-12-16 16:20:09 +00:00
|
|
|
|
2023-11-02 18:27:44 +00:00
|
|
|
ProjectModulesPage.getLayout = function getLayout(page: ReactElement) {
|
|
|
|
return (
|
2024-03-19 14:38:35 +00:00
|
|
|
<AppLayout header={<ModulesListHeader />} mobileHeader={<ModulesListMobileHeader />} withProjectWrapper>
|
2023-11-02 18:27:44 +00:00
|
|
|
{page}
|
|
|
|
</AppLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProjectModulesPage;
|