2024-03-06 13:09:14 +00:00
|
|
|
import { useCallback, useState } from "react";
|
2024-03-18 07:20:33 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-03-06 13:09:14 +00:00
|
|
|
import router from "next/router";
|
2024-03-18 07:20:33 +00:00
|
|
|
// icons
|
2024-03-06 13:09:14 +00:00
|
|
|
import { Calendar, ChevronDown, Kanban, List } from "lucide-react";
|
2024-05-07 09:26:19 +00:00
|
|
|
// types
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TIssueLayouts } from "@plane/types";
|
2024-03-18 07:20:33 +00:00
|
|
|
// ui
|
2024-02-07 08:14:03 +00:00
|
|
|
import { CustomMenu } from "@plane/ui";
|
2024-03-18 07:20:33 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { ProjectAnalyticsModal } from "@/components/analytics";
|
|
|
|
import { DisplayFiltersSelection, FilterSelection, FiltersDropdown } from "@/components/issues";
|
2024-05-07 09:26:19 +00:00
|
|
|
// constants
|
2024-03-19 14:38:35 +00:00
|
|
|
import { EIssueFilterType, EIssuesStoreType, ISSUE_DISPLAY_FILTERS_BY_LAYOUT, ISSUE_LAYOUTS } from "@/constants/issue";
|
2024-05-07 09:26:19 +00:00
|
|
|
// helpers
|
|
|
|
import { calculateTotalFilters } from "@/helpers/filter.helper";
|
|
|
|
// hooks
|
2024-04-03 15:19:02 +00:00
|
|
|
import { useIssues, useLabel, useMember, useModule, useProject, useProjectState } from "@/hooks/store";
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-03-18 07:20:33 +00:00
|
|
|
export const ModuleMobileHeader = observer(() => {
|
2024-02-29 10:01:03 +00:00
|
|
|
const [analyticsModal, setAnalyticsModal] = useState(false);
|
2024-04-03 15:19:02 +00:00
|
|
|
const { currentProjectDetails } = useProject();
|
2024-02-29 10:01:03 +00:00
|
|
|
const { getModuleById } = useModule();
|
|
|
|
const layouts = [
|
|
|
|
{ key: "list", title: "List", icon: List },
|
|
|
|
{ key: "kanban", title: "Kanban", icon: Kanban },
|
|
|
|
{ key: "calendar", title: "Calendar", icon: Calendar },
|
|
|
|
];
|
|
|
|
const { workspaceSlug, projectId, moduleId } = router.query as {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
moduleId: string;
|
|
|
|
};
|
|
|
|
const moduleDetails = moduleId ? getModuleById(moduleId.toString()) : undefined;
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
const {
|
|
|
|
issuesFilter: { issueFilters, updateFilters },
|
|
|
|
} = useIssues(EIssuesStoreType.MODULE);
|
|
|
|
const activeLayout = issueFilters?.displayFilters?.layout;
|
|
|
|
const { projectStates } = useProjectState();
|
|
|
|
const { projectLabels } = useLabel();
|
|
|
|
const {
|
|
|
|
project: { projectMemberIds },
|
|
|
|
} = useMember();
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
const handleLayoutChange = useCallback(
|
|
|
|
(layout: TIssueLayouts) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_FILTERS, { layout: layout }, moduleId);
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, moduleId, updateFilters]
|
|
|
|
);
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
const handleFiltersUpdate = useCallback(
|
|
|
|
(key: keyof IIssueFilterOptions, value: string | string[]) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
const newValues = issueFilters?.filters?.[key] ?? [];
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
if (Array.isArray(value)) {
|
2024-03-22 13:08:39 +00:00
|
|
|
// this validation is majorly for the filter start_date, target_date custom
|
2024-02-29 10:01:03 +00:00
|
|
|
value.forEach((val) => {
|
|
|
|
if (!newValues.includes(val)) newValues.push(val);
|
2024-03-22 13:08:39 +00:00
|
|
|
else newValues.splice(newValues.indexOf(val), 1);
|
2024-02-29 10:01:03 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
|
|
|
|
else newValues.push(value);
|
|
|
|
}
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }, moduleId);
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, moduleId, issueFilters, updateFilters]
|
|
|
|
);
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
const handleDisplayFilters = useCallback(
|
|
|
|
(updatedDisplayFilter: Partial<IIssueDisplayFilterOptions>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_FILTERS, updatedDisplayFilter, moduleId);
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, moduleId, updateFilters]
|
|
|
|
);
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
const handleDisplayProperties = useCallback(
|
|
|
|
(property: Partial<IIssueDisplayProperties>) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
updateFilters(workspaceSlug, projectId, EIssueFilterType.DISPLAY_PROPERTIES, property, moduleId);
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, moduleId, updateFilters]
|
|
|
|
);
|
2024-02-07 08:14:03 +00:00
|
|
|
|
2024-05-07 09:26:19 +00:00
|
|
|
const isFiltersApplied = calculateTotalFilters(issueFilters?.filters ?? {}) !== 0;
|
|
|
|
|
2024-02-29 10:01:03 +00:00
|
|
|
return (
|
|
|
|
<div className="block md:hidden">
|
|
|
|
<ProjectAnalyticsModal
|
|
|
|
isOpen={analyticsModal}
|
|
|
|
onClose={() => setAnalyticsModal(false)}
|
|
|
|
moduleDetails={moduleDetails ?? undefined}
|
|
|
|
/>
|
2024-03-18 07:20:33 +00:00
|
|
|
<div className="flex justify-evenly border-b border-custom-border-200 bg-custom-background-100 py-2">
|
2024-02-29 10:01:03 +00:00
|
|
|
<CustomMenu
|
|
|
|
maxHeight={"md"}
|
2024-03-06 13:09:14 +00:00
|
|
|
className="flex flex-grow justify-center text-sm text-custom-text-200"
|
2024-02-29 10:01:03 +00:00
|
|
|
placement="bottom-start"
|
2024-03-06 13:09:14 +00:00
|
|
|
customButton={<span className="flex flex-grow justify-center text-sm text-custom-text-200">Layout</span>}
|
2024-02-29 10:01:03 +00:00
|
|
|
customButtonClassName="flex flex-grow justify-center text-custom-text-200 text-sm"
|
|
|
|
closeOnSelect
|
|
|
|
>
|
|
|
|
{layouts.map((layout, index) => (
|
|
|
|
<CustomMenu.MenuItem
|
2024-03-06 13:09:14 +00:00
|
|
|
key={layout.key}
|
2024-02-29 10:01:03 +00:00
|
|
|
onClick={() => {
|
|
|
|
handleLayoutChange(ISSUE_LAYOUTS[index].key);
|
|
|
|
}}
|
|
|
|
className="flex items-center gap-2"
|
|
|
|
>
|
2024-03-06 13:09:14 +00:00
|
|
|
<layout.icon className="h-3 w-3" />
|
2024-02-29 10:01:03 +00:00
|
|
|
<div className="text-custom-text-300">{layout.title}</div>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
))}
|
|
|
|
</CustomMenu>
|
2024-03-06 13:09:14 +00:00
|
|
|
<div className="flex flex-grow items-center justify-center border-l border-custom-border-200 text-sm text-custom-text-200">
|
2024-02-29 10:01:03 +00:00
|
|
|
<FiltersDropdown
|
|
|
|
title="Filters"
|
|
|
|
placement="bottom-end"
|
|
|
|
menuButton={
|
2024-03-06 13:09:14 +00:00
|
|
|
<span className="flex items-center text-sm text-custom-text-200">
|
2024-02-29 10:01:03 +00:00
|
|
|
Filters
|
2024-03-06 13:09:14 +00:00
|
|
|
<ChevronDown className="ml-2 h-4 w-4 text-custom-text-200" />
|
2024-02-29 10:01:03 +00:00
|
|
|
</span>
|
|
|
|
}
|
2024-05-07 09:26:19 +00:00
|
|
|
isFiltersApplied={isFiltersApplied}
|
2024-02-29 10:01:03 +00:00
|
|
|
>
|
|
|
|
<FilterSelection
|
|
|
|
filters={issueFilters?.filters ?? {}}
|
|
|
|
handleFiltersUpdate={handleFiltersUpdate}
|
|
|
|
layoutDisplayFiltersOptions={
|
|
|
|
activeLayout ? ISSUE_DISPLAY_FILTERS_BY_LAYOUT.issues[activeLayout] : undefined
|
|
|
|
}
|
|
|
|
labels={projectLabels}
|
|
|
|
memberIds={projectMemberIds ?? undefined}
|
|
|
|
states={projectStates}
|
2024-04-03 15:19:02 +00:00
|
|
|
cycleViewDisabled={!currentProjectDetails?.cycle_view}
|
|
|
|
moduleViewDisabled={!currentProjectDetails?.module_view}
|
2024-02-07 08:14:03 +00:00
|
|
|
/>
|
2024-02-29 10:01:03 +00:00
|
|
|
</FiltersDropdown>
|
2024-02-07 18:46:00 +00:00
|
|
|
</div>
|
2024-03-06 13:09:14 +00:00
|
|
|
<div className="flex flex-grow items-center justify-center border-l border-custom-border-200 text-sm text-custom-text-200">
|
2024-02-29 10:01:03 +00:00
|
|
|
<FiltersDropdown
|
|
|
|
title="Display"
|
|
|
|
placement="bottom-end"
|
|
|
|
menuButton={
|
2024-03-06 13:09:14 +00:00
|
|
|
<span className="flex items-center text-sm text-custom-text-200">
|
2024-02-29 10:01:03 +00:00
|
|
|
Display
|
2024-03-06 13:09:14 +00:00
|
|
|
<ChevronDown className="ml-2 h-4 w-4 text-custom-text-200" />
|
2024-02-29 10:01:03 +00:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<DisplayFiltersSelection
|
|
|
|
layoutDisplayFiltersOptions={
|
|
|
|
activeLayout ? ISSUE_DISPLAY_FILTERS_BY_LAYOUT.issues[activeLayout] : undefined
|
|
|
|
}
|
|
|
|
displayFilters={issueFilters?.displayFilters ?? {}}
|
|
|
|
handleDisplayFiltersUpdate={handleDisplayFilters}
|
|
|
|
displayProperties={issueFilters?.displayProperties ?? {}}
|
|
|
|
handleDisplayPropertiesUpdate={handleDisplayProperties}
|
|
|
|
ignoreGroupedFilters={["module"]}
|
2024-04-03 15:19:02 +00:00
|
|
|
cycleViewDisabled={!currentProjectDetails?.cycle_view}
|
|
|
|
moduleViewDisabled={!currentProjectDetails?.module_view}
|
2024-02-29 10:01:03 +00:00
|
|
|
/>
|
|
|
|
</FiltersDropdown>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
onClick={() => setAnalyticsModal(true)}
|
2024-03-06 13:09:14 +00:00
|
|
|
className="flex flex-grow justify-center border-l border-custom-border-200 text-sm text-custom-text-200"
|
2024-02-29 10:01:03 +00:00
|
|
|
>
|
|
|
|
Analytics
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2024-03-18 07:20:33 +00:00
|
|
|
});
|