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";
|
2022-12-16 16:20:09 +00:00
|
|
|
// layouts
|
2022-12-22 16:19:46 +00:00
|
|
|
// components
|
2024-02-20 08:06:38 +00:00
|
|
|
import { PageHead } from "components/core";
|
2023-10-23 13:47:42 +00:00
|
|
|
import { ModulesListHeader } from "components/headers";
|
2024-03-12 14:54:21 +00:00
|
|
|
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-12 14:54:21 +00:00
|
|
|
import { useModuleFilter, useProject } from "hooks/store";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { AppLayout } from "layouts/app-layout";
|
|
|
|
import { NextPageWithLayout } from "lib/types";
|
2024-03-12 14:54:21 +00:00
|
|
|
import { calculateTotalFilters } from "helpers/filter.helper";
|
|
|
|
import { TModuleFilters } from "@plane/types";
|
2024-03-18 07:20:33 +00:00
|
|
|
import ModulesListMobileHeader from "components/modules/moduels-list-mobile-header";
|
2023-10-23 13:47:42 +00:00
|
|
|
|
2024-02-20 08:06:38 +00:00
|
|
|
const ProjectModulesPage: NextPageWithLayout = observer(() => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { projectId } = router.query;
|
|
|
|
// store
|
|
|
|
const { getProjectById } = 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-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-18 07:20:33 +00:00
|
|
|
<AppLayout header={<ModulesListHeader />} mobileHeader={<ModulesListMobileHeader/>} withProjectWrapper>
|
2023-11-02 18:27:44 +00:00
|
|
|
{page}
|
|
|
|
</AppLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProjectModulesPage;
|