From da9df800799bf3e371637e2786b01bfe1e1bfac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Mon, 30 Sep 2024 22:28:06 +0200 Subject: [PATCH] fix(api,dashboard): use correct id with formula --- .../report/sidebar/ReportFormula.tsx | 63 +++++++++++++++++-- packages/trpc/src/routers/chart.helpers.ts | 11 ++-- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/apps/dashboard/src/components/report/sidebar/ReportFormula.tsx b/apps/dashboard/src/components/report/sidebar/ReportFormula.tsx index 8e181726..727b1b14 100644 --- a/apps/dashboard/src/components/report/sidebar/ReportFormula.tsx +++ b/apps/dashboard/src/components/report/sidebar/ReportFormula.tsx @@ -3,6 +3,10 @@ import { Input } from '@/components/ui/input'; 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'; export function ReportFormula() { @@ -13,14 +17,65 @@ export function ReportFormula() {

Formula

- { - dispatch(changeFormula(event.target.value)); + value={formula ?? ''} + onChangeValue={(value) => { + dispatch(changeFormula(value)); }} />
); } + +function InputFormula({ + value, + onChangeValue, + ...props +}: { + value: string | undefined; + onChangeValue: (value: string) => void; +} & InputHTMLAttributes) { + const [internalValue, setInternalValue] = useState(value ?? ''); + + useEffect(() => { + if (value !== internalValue) { + setInternalValue(value ?? ''); + } + }, [value]); + + return ( +
+ setInternalValue(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') { + onChangeValue(internalValue); + } + }} + size="default" + /> +
+ + {internalValue !== value && ( + onChangeValue(internalValue)} + > + + Press enter + + + + )} + +
+
+ ); +} diff --git a/packages/trpc/src/routers/chart.helpers.ts b/packages/trpc/src/routers/chart.helpers.ts index 5477f3dd..7afc7d7d 100644 --- a/packages/trpc/src/routers/chart.helpers.ts +++ b/packages/trpc/src/routers/chart.helpers.ts @@ -99,19 +99,20 @@ export function withFormula( }; }); } - return [ { ...series[0], data: series[0].data.map((item, dIndex) => { - const scope = series.reduce((acc, item) => { - if (!item.event.id) { - return acc; + const scope = series.reduce((acc, item, index) => { + const readableId = alphabetIds[index]; + + if (!readableId) { + throw new Error('no alphabet id for serie in withFormula'); } return { ...acc, - [item.event.id]: item.data[dIndex]?.count ?? 0, + [readableId]: item.data[dIndex]?.count ?? 0, }; }, {});