fix(api,dashboard): use correct id with formula
This commit is contained in:
@@ -3,6 +3,10 @@
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { useDispatch, useSelector } from '@/redux';
|
import { useDispatch, useSelector } from '@/redux';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
|
import { RefreshCcwIcon } from 'lucide-react';
|
||||||
|
import { type InputHTMLAttributes, useEffect, useState } from 'react';
|
||||||
import { changeFormula } from '../reportSlice';
|
import { changeFormula } from '../reportSlice';
|
||||||
|
|
||||||
export function ReportFormula() {
|
export function ReportFormula() {
|
||||||
@@ -13,14 +17,65 @@ export function ReportFormula() {
|
|||||||
<div>
|
<div>
|
||||||
<h3 className="mb-2 font-medium">Formula</h3>
|
<h3 className="mb-2 font-medium">Formula</h3>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<Input
|
<InputFormula
|
||||||
placeholder="eg: A/B"
|
placeholder="eg: A/B"
|
||||||
value={formula}
|
value={formula ?? ''}
|
||||||
onChange={(event) => {
|
onChangeValue={(value) => {
|
||||||
dispatch(changeFormula(event.target.value));
|
dispatch(changeFormula(value));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function InputFormula({
|
||||||
|
value,
|
||||||
|
onChangeValue,
|
||||||
|
...props
|
||||||
|
}: {
|
||||||
|
value: string | undefined;
|
||||||
|
onChangeValue: (value: string) => void;
|
||||||
|
} & InputHTMLAttributes<HTMLInputElement>) {
|
||||||
|
const [internalValue, setInternalValue] = useState(value ?? '');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (value !== internalValue) {
|
||||||
|
setInternalValue(value ?? '');
|
||||||
|
}
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative w-full">
|
||||||
|
<Input
|
||||||
|
{...props}
|
||||||
|
value={internalValue}
|
||||||
|
onChange={(e) => setInternalValue(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
onChangeValue(internalValue);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
size="default"
|
||||||
|
/>
|
||||||
|
<div className="absolute right-2 top-1/2 -translate-y-1/2">
|
||||||
|
<AnimatePresence>
|
||||||
|
{internalValue !== value && (
|
||||||
|
<motion.button
|
||||||
|
key="refresh"
|
||||||
|
initial={{ opacity: 0, scale: 0.8 }}
|
||||||
|
animate={{ opacity: 1, scale: 1 }}
|
||||||
|
exit={{ opacity: 0, scale: 0.8 }}
|
||||||
|
onClick={() => onChangeValue(internalValue)}
|
||||||
|
>
|
||||||
|
<Badge variant="muted">
|
||||||
|
Press enter
|
||||||
|
<RefreshCcwIcon className="ml-1 h-3 w-3" />
|
||||||
|
</Badge>
|
||||||
|
</motion.button>
|
||||||
|
)}
|
||||||
|
</AnimatePresence>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -99,19 +99,20 @@ export function withFormula(
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
...series[0],
|
...series[0],
|
||||||
data: series[0].data.map((item, dIndex) => {
|
data: series[0].data.map((item, dIndex) => {
|
||||||
const scope = series.reduce((acc, item) => {
|
const scope = series.reduce((acc, item, index) => {
|
||||||
if (!item.event.id) {
|
const readableId = alphabetIds[index];
|
||||||
return acc;
|
|
||||||
|
if (!readableId) {
|
||||||
|
throw new Error('no alphabet id for serie in withFormula');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
[item.event.id]: item.data[dIndex]?.count ?? 0,
|
[readableId]: item.data[dIndex]?.count ?? 0,
|
||||||
};
|
};
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user