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";
|
2024-05-08 08:10:58 +00:00
|
|
|
import { ModuleViewHeader, 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-05-08 08:10:58 +00:00
|
|
|
const { currentProjectFilters, currentProjectDisplayFilters, clearAllFilters, updateFilters, updateDisplayFilters } =
|
|
|
|
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">
|
2024-05-08 08:10:58 +00:00
|
|
|
<div className="h-[50px] flex-shrink-0 w-full border-b border-custom-border-200 px-6 relative flex items-center gap-4 justify-between">
|
|
|
|
<div className="flex items-center">
|
|
|
|
<span className="block text-sm font-medium">Module name</span>
|
|
|
|
</div>
|
|
|
|
<ModuleViewHeader />
|
|
|
|
</div>
|
|
|
|
{(calculateTotalFilters(currentProjectFilters ?? {}) !== 0 || currentProjectDisplayFilters?.favorites) && (
|
2024-03-12 14:54:21 +00:00
|
|
|
<div className="border-b border-custom-border-200 px-5 py-3">
|
|
|
|
<ModuleAppliedFiltersList
|
|
|
|
appliedFilters={currentProjectFilters ?? {}}
|
2024-05-08 08:10:58 +00:00
|
|
|
isFavoriteFilterApplied={currentProjectDisplayFilters?.favorites ?? false}
|
2024-03-12 14:54:21 +00:00
|
|
|
handleClearAllFilters={() => clearAllFilters(`${projectId}`)}
|
|
|
|
handleRemoveFilter={handleRemoveFilter}
|
2024-05-08 08:10:58 +00:00
|
|
|
handleDisplayFiltersUpdate={(val) => {
|
|
|
|
if (!projectId) return;
|
|
|
|
updateDisplayFilters(projectId.toString(), val);
|
|
|
|
}}
|
2024-03-12 14:54:21 +00:00
|
|
|
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;
|