Files
supabase/apps/studio/components/ui/QueryBlock/QueryBlock.utils.ts
Joshen Lim 0710d62665 ReportsV2 P1: Add Query block component (#32738)
* Create QueryBlock component which will be a shared component used in AI Assistant and Reports

* Deprecate AIAssistantPanel/SqlSnippet.ts

* Fix user messages not getting persisted, only assistant messages

* Add loading state to for query results in QueryBlock + hide block view configuration if query block is not chart

* Address feedback

* Fix TS

* fix double border

---------

Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
2025-01-15 13:08:26 +08:00

20 lines
551 B
TypeScript

import { ChartConfig } from 'components/interfaces/SQLEditor/UtilityPanel/ChartConfig'
// Add helper function for cumulative results
export const getCumulativeResults = (results: { rows: any[] }, config: ChartConfig) => {
if (!results?.rows?.length) {
return []
}
const cumulativeResults = results.rows.reduce((acc, row) => {
const prev = acc[acc.length - 1] || {}
const next = {
...row,
[config.yKey]: (prev[config.yKey] || 0) + row[config.yKey],
}
return [...acc, next]
}, [])
return cumulativeResults
}