mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
5a32d10f96
* chore: replaced marimekko graph with a bar graph * chore: add bar onClick handler * chore: custom date filter for widgets * style: priority graph * chore: workspace profile activity pagination * chore: profile activity pagination * chore: user profile activity pagination * chore: workspace user activity csv download * chore: download activity button added * chore: workspace user pagination * chore: collabrator pagination * chore: field change * chore: recent collaborators pagination * chore: changed the collabrators * chore: collabrators list changed * fix: distinct users * chore: search filter in collaborators * fix: import error * chore: update priority graph x-axis values * chore: admin and member request validation * chore: update csv download request method * chore: search implementation for the collaborators widget * refactor: priority distribution card * chore: add enum for duration filters * chore: update inbox types * chore: add todos for refactoring --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
111 lines
3.9 KiB
TypeScript
111 lines
3.9 KiB
TypeScript
import { useEffect } from "react";
|
|
import { useRouter } from "next/router";
|
|
import Link from "next/link";
|
|
import { observer } from "mobx-react-lite";
|
|
// hooks
|
|
import { useDashboard } from "hooks/store";
|
|
// components
|
|
import {
|
|
DurationFilterDropdown,
|
|
IssuesByPriorityEmptyState,
|
|
WidgetLoader,
|
|
WidgetProps,
|
|
} from "components/dashboard/widgets";
|
|
// helpers
|
|
import { getCustomDates } from "helpers/dashboard.helper";
|
|
// types
|
|
import { EDurationFilters, TIssuesByPriorityWidgetFilters, TIssuesByPriorityWidgetResponse } from "@plane/types";
|
|
// constants
|
|
import { IssuesByPriorityGraph } from "components/graphs";
|
|
|
|
const WIDGET_KEY = "issues_by_priority";
|
|
|
|
export const IssuesByPriorityWidget: React.FC<WidgetProps> = observer((props) => {
|
|
const { dashboardId, workspaceSlug } = props;
|
|
// router
|
|
const router = useRouter();
|
|
// store hooks
|
|
const { fetchWidgetStats, getWidgetDetails, getWidgetStats, updateDashboardWidgetFilters } = useDashboard();
|
|
// derived values
|
|
const widgetDetails = getWidgetDetails(workspaceSlug, dashboardId, WIDGET_KEY);
|
|
const widgetStats = getWidgetStats<TIssuesByPriorityWidgetResponse[]>(workspaceSlug, dashboardId, WIDGET_KEY);
|
|
const selectedDuration = widgetDetails?.widget_filters.duration ?? EDurationFilters.NONE;
|
|
const selectedCustomDates = widgetDetails?.widget_filters.custom_dates ?? [];
|
|
|
|
const handleUpdateFilters = async (filters: Partial<TIssuesByPriorityWidgetFilters>) => {
|
|
if (!widgetDetails) return;
|
|
|
|
await updateDashboardWidgetFilters(workspaceSlug, dashboardId, widgetDetails.id, {
|
|
widgetKey: WIDGET_KEY,
|
|
filters,
|
|
});
|
|
|
|
const filterDates = getCustomDates(
|
|
filters.duration ?? selectedDuration,
|
|
filters.custom_dates ?? selectedCustomDates
|
|
);
|
|
fetchWidgetStats(workspaceSlug, dashboardId, {
|
|
widget_key: WIDGET_KEY,
|
|
...(filterDates.trim() !== "" ? { target_date: filterDates } : {}),
|
|
});
|
|
};
|
|
|
|
useEffect(() => {
|
|
const filterDates = getCustomDates(selectedDuration, selectedCustomDates);
|
|
fetchWidgetStats(workspaceSlug, dashboardId, {
|
|
widget_key: WIDGET_KEY,
|
|
...(filterDates.trim() !== "" ? { target_date: filterDates } : {}),
|
|
});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
if (!widgetDetails || !widgetStats) return <WidgetLoader widgetKey={WIDGET_KEY} />;
|
|
|
|
const totalCount = widgetStats.reduce((acc, item) => acc + item?.count, 0);
|
|
const chartData = widgetStats.map((item) => ({
|
|
priority: item?.priority,
|
|
priority_count: item?.count,
|
|
}));
|
|
|
|
return (
|
|
<div className="bg-custom-background-100 rounded-xl border-[0.5px] border-custom-border-200 w-full py-6 hover:shadow-custom-shadow-4xl duration-300 overflow-hidden min-h-96 flex flex-col">
|
|
<div className="flex items-center justify-between gap-2 pl-7 pr-6">
|
|
<Link
|
|
href={`/${workspaceSlug}/workspace-views/assigned`}
|
|
className="text-lg font-semibold text-custom-text-300 hover:underline"
|
|
>
|
|
Assigned by priority
|
|
</Link>
|
|
<DurationFilterDropdown
|
|
customDates={selectedCustomDates}
|
|
value={selectedDuration}
|
|
onChange={(val, customDates) =>
|
|
handleUpdateFilters({
|
|
duration: val,
|
|
...(val === "custom" ? { custom_dates: customDates } : {}),
|
|
})
|
|
}
|
|
/>
|
|
</div>
|
|
{totalCount > 0 ? (
|
|
<div className="flex items-center h-full">
|
|
<div className="w-full -mt-[11px]">
|
|
<IssuesByPriorityGraph
|
|
data={chartData}
|
|
onBarClick={(datum) => {
|
|
router.push(
|
|
`/${workspaceSlug}/workspace-views/assigned?priority=${`${datum.data.priority}`.toLowerCase()}`
|
|
);
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="h-full grid place-items-center">
|
|
<IssuesByPriorityEmptyState />
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
});
|