Files
supabase/apps/studio/hooks/analytics/useFillTimeseriesSorted.ts
Ivan Vasilov 436bdb10ae chore: Move the studio app to apps/studio (#18915)
* Move all studio files from /studio to /apps/studio.

* Move studio specific prettier ignores.

* Fix the ui references from studio.

* Fix the css imports.

* Fix all package.json issues.

* Fix the prettier setup for the studio app.

* Add .turbo folder to prettierignore.

* Fix the github workflows.
2023-11-15 12:38:55 +01:00

19 lines
605 B
TypeScript

import { fillTimeseries } from 'components/interfaces/Settings/Logs'
import { useMemo } from 'react'
/**
* Convenience hook for memoized filling of timeseries data.
*/
const useFillTimeseriesSorted = (...args: Parameters<typeof fillTimeseries>) => {
return useMemo(() => {
const [data, timestampKey] = args
if (!data[0]?.[timestampKey]) return data
const filled = fillTimeseries(...args)
return filled.sort((a, b) => {
return (new Date(a[args[1]]) as any) - (new Date(b[args[1]]) as any)
})
}, [JSON.stringify(args[0]), ...args])
}
export default useFillTimeseriesSorted