mirror of
https://github.com/makeplane/plane
synced 2025-08-07 19:59:33 +00:00
* refactor: page store hooks * fix: page details instances * fix: build errors * refactor: page store hooks * fix: minor bug
102 lines
3.3 KiB
TypeScript
102 lines
3.3 KiB
TypeScript
import { useCallback } from "react";
|
|
import { observer } from "mobx-react";
|
|
import { ListFilter } from "lucide-react";
|
|
import { useTranslation } from "@plane/i18n";
|
|
import { TPageFilterProps, TPageNavigationTabs } from "@plane/types";
|
|
// components
|
|
import { Header, EHeaderVariant } from "@plane/ui";
|
|
import { FiltersDropdown } from "@/components/issues";
|
|
import {
|
|
PageAppliedFiltersList,
|
|
PageFiltersSelection,
|
|
PageOrderByDropdown,
|
|
PageSearchInput,
|
|
PageTabNavigation,
|
|
} from "@/components/pages";
|
|
// helpers
|
|
import { calculateTotalFilters } from "@/helpers/filter.helper";
|
|
// hooks
|
|
import { useMember } from "@/hooks/store";
|
|
// plane web hooks
|
|
import { EPageStoreType, usePageStore } from "@/plane-web/hooks/store";
|
|
|
|
type Props = {
|
|
pageType: TPageNavigationTabs;
|
|
projectId: string;
|
|
storeType: EPageStoreType;
|
|
workspaceSlug: string;
|
|
};
|
|
|
|
export const PagesListHeaderRoot: React.FC<Props> = observer((props) => {
|
|
const { pageType, projectId, storeType, workspaceSlug } = props;
|
|
const { t } = useTranslation();
|
|
// store hooks
|
|
const { filters, updateFilters, clearAllFilters } = usePageStore(storeType);
|
|
const {
|
|
workspace: { workspaceMemberIds },
|
|
} = useMember();
|
|
|
|
const handleRemoveFilter = useCallback(
|
|
(key: keyof TPageFilterProps, value: string | null) => {
|
|
let newValues = filters.filters?.[key];
|
|
|
|
if (key === "favorites") newValues = !!value;
|
|
if (Array.isArray(newValues)) {
|
|
if (!value) newValues = [];
|
|
else newValues = newValues.filter((val) => val !== value);
|
|
}
|
|
|
|
updateFilters("filters", { [key]: newValues });
|
|
},
|
|
[filters.filters, updateFilters]
|
|
);
|
|
|
|
const isFiltersApplied = calculateTotalFilters(filters?.filters ?? {}) !== 0;
|
|
|
|
return (
|
|
<>
|
|
<Header variant={EHeaderVariant.SECONDARY}>
|
|
<Header.LeftItem>
|
|
<PageTabNavigation workspaceSlug={workspaceSlug} projectId={projectId} pageType={pageType} />
|
|
</Header.LeftItem>
|
|
<Header.RightItem className="items-center">
|
|
<PageSearchInput
|
|
searchQuery={filters.searchQuery}
|
|
updateSearchQuery={(val) => updateFilters("searchQuery", val)}
|
|
/>
|
|
<PageOrderByDropdown
|
|
sortBy={filters.sortBy}
|
|
sortKey={filters.sortKey}
|
|
onChange={(val) => {
|
|
if (val.key) updateFilters("sortKey", val.key);
|
|
if (val.order) updateFilters("sortBy", val.order);
|
|
}}
|
|
/>
|
|
<FiltersDropdown
|
|
icon={<ListFilter className="h-3 w-3" />}
|
|
title={t("common.filters")}
|
|
placement="bottom-end"
|
|
isFiltersApplied={isFiltersApplied}
|
|
>
|
|
<PageFiltersSelection
|
|
filters={filters}
|
|
handleFiltersUpdate={updateFilters}
|
|
memberIds={workspaceMemberIds ?? undefined}
|
|
/>
|
|
</FiltersDropdown>
|
|
</Header.RightItem>
|
|
</Header>
|
|
{calculateTotalFilters(filters?.filters ?? {}) !== 0 && (
|
|
<Header variant={EHeaderVariant.TERNARY}>
|
|
<PageAppliedFiltersList
|
|
appliedFilters={filters.filters ?? {}}
|
|
handleClearAllFilters={clearAllFilters}
|
|
handleRemoveFilter={handleRemoveFilter}
|
|
alwaysAllowEditing
|
|
/>
|
|
</Header>
|
|
)}
|
|
</>
|
|
);
|
|
});
|