plane/web/components/analytics/custom-analytics/select/y-axis.tsx

55 lines
1.5 KiB
TypeScript
Raw Normal View History

import { observer } from "mobx-react";
2024-03-19 14:38:35 +00:00
import { TYAxisValues } from "@plane/types";
import { CustomSelect } from "@plane/ui";
2023-05-16 05:11:37 +00:00
// constants
import { ANALYTICS_Y_AXIS_VALUES } from "@/constants/analytics";
import { EEstimateSystem } from "@/constants/estimates";
// hooks
import { useAppRouter, useProjectEstimates } from "@/hooks/store";
2023-05-16 05:11:37 +00:00
type Props = {
value: TYAxisValues;
onChange: () => void;
};
export const SelectYAxis: React.FC<Props> = observer(({ value, onChange }) => {
// hooks
const { projectId } = useAppRouter();
const { areEstimateEnabledByProjectId, currentActiveEstimateId, estimateById } = useProjectEstimates();
const isEstimateEnabled = (analyticsOption: string) => {
if (analyticsOption === "estimate") {
if (
projectId &&
currentActiveEstimateId &&
areEstimateEnabledByProjectId(projectId) &&
estimateById(currentActiveEstimateId)?.type === EEstimateSystem.POINTS
) {
return true;
} else {
return false;
}
}
return true;
};
return (
<CustomSelect
value={value}
label={<span>{ANALYTICS_Y_AXIS_VALUES.find((v) => v.value === value)?.label ?? "None"}</span>}
onChange={onChange}
maxHeight="lg"
>
{ANALYTICS_Y_AXIS_VALUES.map(
(item) =>
isEstimateEnabled(item.value) && (
<CustomSelect.Option key={item.value} value={item.value}>
{item.label}
</CustomSelect.Option>
)
)}
</CustomSelect>
);
});