2023-05-11 12:08:46 +00:00
|
|
|
// nivo
|
|
|
|
import { BarTooltipProps } from "@nivo/bar";
|
2023-05-15 05:52:06 +00:00
|
|
|
import { DATE_KEYS } from "constants/analytics";
|
|
|
|
import { renderMonthAndYear } from "helpers/analytics.helper";
|
2023-05-11 12:08:46 +00:00
|
|
|
// types
|
2023-05-19 11:38:32 +00:00
|
|
|
import { IAnalyticsParams, IAnalyticsResponse } from "types";
|
2023-05-11 12:08:46 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
datum: BarTooltipProps<any>;
|
2023-05-19 11:38:32 +00:00
|
|
|
analytics: IAnalyticsResponse;
|
2023-05-11 12:08:46 +00:00
|
|
|
params: IAnalyticsParams;
|
|
|
|
};
|
|
|
|
|
2023-05-19 11:38:32 +00:00
|
|
|
export const CustomTooltip: React.FC<Props> = ({ datum, analytics, params }) => {
|
2023-05-15 05:52:06 +00:00
|
|
|
let tooltipValue: string | number = "";
|
|
|
|
|
2023-08-09 09:50:29 +00:00
|
|
|
const renderAssigneeName = (assigneeId: string): string => {
|
|
|
|
const assignee = analytics.extras.assignee_details.find((a) => a.assignees__id === assigneeId);
|
|
|
|
|
|
|
|
if (!assignee) return "No assignee";
|
|
|
|
|
|
|
|
return assignee.assignees__display_name || "No assignee";
|
|
|
|
};
|
|
|
|
|
2023-05-15 05:52:06 +00:00
|
|
|
if (params.segment) {
|
|
|
|
if (DATE_KEYS.includes(params.segment)) tooltipValue = renderMonthAndYear(datum.id);
|
2023-12-06 13:45:07 +00:00
|
|
|
else if (params.segment === "labels__id") {
|
|
|
|
const label = analytics.extras.label_details.find((l) => l.labels__id === datum.id);
|
|
|
|
tooltipValue = label && label.labels__name ? label.labels__name : "None";
|
|
|
|
} else if (params.segment === "state_id") {
|
|
|
|
const state = analytics.extras.state_details.find((s) => s.state_id === datum.id);
|
|
|
|
tooltipValue = state && state.state__name ? state.state__name : "None";
|
|
|
|
} else if (params.segment === "issue_cycle__cycle_id") {
|
|
|
|
const cycle = analytics.extras.cycle_details.find((c) => c.issue_cycle__cycle_id === datum.id);
|
|
|
|
tooltipValue = cycle && cycle.issue_cycle__cycle__name ? cycle.issue_cycle__cycle__name : "None";
|
|
|
|
} else if (params.segment === "issue_module__module_id") {
|
|
|
|
const selectedModule = analytics.extras.module_details.find((m) => m.issue_module__module_id === datum.id);
|
|
|
|
tooltipValue =
|
|
|
|
selectedModule && selectedModule.issue_module__module__name
|
|
|
|
? selectedModule.issue_module__module__name
|
|
|
|
: "None";
|
|
|
|
} else tooltipValue = datum.id;
|
2023-05-15 05:52:06 +00:00
|
|
|
} else {
|
|
|
|
if (DATE_KEYS.includes(params.x_axis)) tooltipValue = datum.indexValue;
|
2023-05-16 05:11:37 +00:00
|
|
|
else tooltipValue = datum.id === "count" ? "Issue count" : "Estimate";
|
2023-05-15 05:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center gap-2 rounded-md border border-custom-border-200 bg-custom-background-80 p-2 text-xs">
|
2023-05-15 05:52:06 +00:00
|
|
|
<span
|
|
|
|
className="h-3 w-3 rounded"
|
|
|
|
style={{
|
|
|
|
backgroundColor: datum.color,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<span
|
2023-07-10 07:17:00 +00:00
|
|
|
className={`font-medium text-custom-text-200 ${
|
2023-05-15 05:52:06 +00:00
|
|
|
params.segment
|
|
|
|
? params.segment === "priority" || params.segment === "state__group"
|
|
|
|
? "capitalize"
|
|
|
|
: ""
|
|
|
|
: params.x_axis === "priority" || params.x_axis === "state__group"
|
2023-05-11 12:08:46 +00:00
|
|
|
? "capitalize"
|
|
|
|
: ""
|
2023-05-15 05:52:06 +00:00
|
|
|
}`}
|
|
|
|
>
|
2023-11-08 15:01:46 +00:00
|
|
|
{params.segment === "assignees__id" ? renderAssigneeName(tooltipValue.toString()) : tooltipValue}:
|
2023-05-15 05:52:06 +00:00
|
|
|
</span>
|
|
|
|
<span>{datum.value}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|