2024-04-11 15:58:59 +00:00
|
|
|
import { useCallback } from "react";
|
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import { ListFilter } from "lucide-react";
|
|
|
|
import { TPageFilterProps, TPageNavigationTabs } from "@plane/types";
|
|
|
|
// components
|
|
|
|
import { FiltersDropdown } from "@/components/issues";
|
|
|
|
import {
|
|
|
|
PageAppliedFiltersList,
|
|
|
|
PageFiltersSelection,
|
|
|
|
PageOrderByDropdown,
|
|
|
|
PageSearchInput,
|
|
|
|
PageTabNavigation,
|
|
|
|
} from "@/components/pages";
|
|
|
|
// helpers
|
|
|
|
import { calculateTotalFilters } from "@/helpers/filter.helper";
|
|
|
|
// hooks
|
2024-04-30 11:51:24 +00:00
|
|
|
import { useMember, useProjectPages } from "@/hooks/store";
|
2024-04-11 15:58:59 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
pageType: TPageNavigationTabs;
|
|
|
|
projectId: string;
|
|
|
|
workspaceSlug: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const PagesListHeaderRoot: React.FC<Props> = observer((props) => {
|
|
|
|
const { pageType, projectId, workspaceSlug } = props;
|
|
|
|
// store hooks
|
|
|
|
const { filters, updateFilters, clearAllFilters } = useProjectPages(projectId);
|
|
|
|
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]
|
|
|
|
);
|
|
|
|
|
2024-05-07 09:26:19 +00:00
|
|
|
const isFiltersApplied = calculateTotalFilters(filters?.filters ?? {}) !== 0;
|
|
|
|
|
2024-04-11 15:58:59 +00:00
|
|
|
return (
|
|
|
|
<>
|
2024-04-30 11:51:24 +00:00
|
|
|
<div className="flex-shrink-0 h-[50px] w-full border-b border-custom-border-200 px-6 relative flex items-center gap-4 justify-between">
|
2024-04-11 15:58:59 +00:00
|
|
|
<PageTabNavigation workspaceSlug={workspaceSlug} projectId={projectId} pageType={pageType} />
|
|
|
|
<div className="h-full flex items-center gap-2 self-end">
|
|
|
|
<PageSearchInput projectId={projectId} />
|
|
|
|
<PageOrderByDropdown
|
|
|
|
sortBy={filters.sortBy}
|
|
|
|
sortKey={filters.sortKey}
|
|
|
|
onChange={(val) => {
|
|
|
|
if (val.key) updateFilters("sortKey", val.key);
|
|
|
|
if (val.order) updateFilters("sortBy", val.order);
|
|
|
|
}}
|
|
|
|
/>
|
2024-05-07 09:26:19 +00:00
|
|
|
<FiltersDropdown
|
|
|
|
icon={<ListFilter className="h-3 w-3" />}
|
|
|
|
title="Filters"
|
|
|
|
placement="bottom-end"
|
|
|
|
isFiltersApplied={isFiltersApplied}
|
|
|
|
>
|
2024-04-11 15:58:59 +00:00
|
|
|
<PageFiltersSelection
|
|
|
|
filters={filters}
|
|
|
|
handleFiltersUpdate={updateFilters}
|
|
|
|
memberIds={workspaceMemberIds ?? undefined}
|
|
|
|
/>
|
|
|
|
</FiltersDropdown>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{calculateTotalFilters(filters?.filters ?? {}) !== 0 && (
|
|
|
|
<div className="border-b border-custom-border-200 px-5 py-3">
|
|
|
|
<PageAppliedFiltersList
|
|
|
|
appliedFilters={filters.filters ?? {}}
|
|
|
|
handleClearAllFilters={clearAllFilters}
|
|
|
|
handleRemoveFilter={handleRemoveFilter}
|
|
|
|
alwaysAllowEditing
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|