Files
supabase/apps/studio/components/ui/Panel.tsx
f65884f341 Reports consolidation 1: Edge Functions (#38129)
* wip

* add formatTimestamp for reports

* add tests for formatTimestamp

* fix type err

* rm old chart logic

* do not retry replication sources

* update report config schema

* use report config

* fix charts, simplify config

* sync charts

* rm comment

* usefilltimeseries

* move chart upsell to its own component

* cleanup v2 chart component

* fix chartheader function format bug

* make attributes dynamic

* move types to its own file

* update reportv2chart types

* update reportv2 chart type

* use new edgefn report

* rm mock

* rm old code

* fix type err

* fix type err

* rename hook

* return sql in dataprovider

* add button to open in log explorer in chart header

* fix type

* fix chart type toggle

* fix type error

* export data transformation for testing

* add tests for data transformation

* rm dupped code

* add report settings to edge fn report

* rm mocked data

* rename

* fix type err

* Apply suggestion from @joshenlim

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* rm unnecessary div

* rm unnecessary props from report upsell

* cleaner query keys

* move loadin/error/empty states to inside panel content to prevent layout shift

* use card instead of panel

* use buttontooltip in chartheader

* use buttontooltips in buttons with tooltips

* rm export default

* rm export defualt

* rm i from key

* fix status code transformation

* fix filltimeseries

* add tests for filltimeseries

* fix data transform

* pass xaxis key to chart

* refactor hover state to use timestamp not index

* fix tests

* fix areachart

* fix barchart

* fix chartheader

* fix composedchart

* fix stacked

* fix type missing xaxiskey

* type fix

* Revert "refactor hover state to use timestamp not index"

This reverts commit cfd7886460.

* undo charthover changes, fix data aggregation

* Revert "fix tests"

This reverts commit e5200a2035.

* move transforms to testable functions, add tests

* nit refactors and clean up

* feat: add aws nimbus cloud provider (#38312)

* feat: add aws nimbus cloud provider

* Fix return type of useCustomContent hook

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* add utc plugin to dayjs

* move plugins to vitest setup

* rm customparser plugin

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
2025-09-01 11:10:30 +02:00

154 lines
4.4 KiB
TypeScript

import { Megaphone } from 'lucide-react'
import { forwardRef, PropsWithChildren, ReactNode } from 'react'
import { Badge, Button, cn, Loading } from 'ui'
interface PanelProps {
className?: string
id?: string
footer?: JSX.Element | false
loading?: boolean
noMargin?: boolean
title?: ReactNode | false
wrapWithLoading?: boolean
noHideOverflow?: boolean
titleClasses?: string
}
/**
* @deprecated Use Card component from ui package instead
*/
function Panel(props: PropsWithChildren<PanelProps>) {
const content = (
<div
className={cn(
'bg-surface-100',
'rounded-md border shadow-sm',
props.noHideOverflow ? '' : 'overflow-hidden',
props.noMargin ? '' : 'mb-4 md:mb-8',
props.className
)}
id={props.id}
>
{props.title && (
<div
className={cn(
'bg-surface-100 border-b border-default flex items-center px-4 py-4',
props.titleClasses
)}
>
{props.title}
</div>
)}
{props.children}
{props.footer && <Footer>{props.footer}</Footer>}
</div>
)
if (props.wrapWithLoading === false) {
return content
}
return <Loading active={Boolean(props.loading)}>{content}</Loading>
}
function Content({ children, className }: { children: ReactNode; className?: string | false }) {
return <div className={cn('px-4 py-4', className)}>{children}</div>
}
function Footer({ children }: { children: ReactNode; className?: string }) {
return (
<div className="bg-surface-100 border-t border-default">
<div className="flex h-12 items-center px-4">{children}</div>
</div>
)
}
const PanelNotice = forwardRef<
HTMLDivElement,
{
className?: string | false
title?: string
description?: string
href?: string
buttonText?: string
layout?: 'horizontal' | 'vertical'
badgeLabel?: string
}
>(
(
{
className,
title,
description,
href,
buttonText,
layout = 'horizontal',
badgeLabel,
...props
},
ref
) => {
return (
<div
ref={ref}
{...props}
className={cn(
'relative px-4 py-5 bg-studio flex flex-col lg:flex-row lg:justify-between gap-6 overflow-hidden lg:items-center',
layout === 'vertical' && '!flex-col !items-start gap-y-2',
className
)}
>
<div
className="absolute inset-0 -mt-[5px]"
style={{
backgroundImage: `
linear-gradient(to right, hsl(var(--background-200)/1) 0%, hsl(var(--background-200)/1) 30%, hsl(var(--background-200)/0) 100%),
linear-gradient(to right, hsl(var(--border-default)/0.33) 1px, transparent 1px),
linear-gradient(to bottom, hsl(var(--border-default)/0.33) 1px, transparent 1px)
`,
backgroundSize: '100% 100%, 15px 15px, 15px 15px',
backgroundPosition: '0 0, 0 0, 0 0',
}}
/>
<div className="relative flex flex-col gap-y-2">
<div className="flex flex-row items-center -space-x-px">
<Badge
variant={'default'}
className="rounded-r-none pr-2 flex-shrink-0 gap-1.5 border-dashed bg-opacity-0 bg-surface-400 text-foreground-lighter"
>
<Megaphone size={16} strokeWidth={1.2} />
<span className="text-foreground-lighter">{badgeLabel ?? 'Upcoming change'}</span>
</Badge>
<Badge
variant="default"
className="rounded-l-none flex-shrink-0 gap-1.5 bg-opacity-0 bg-surface-400 text-foreground-lighter border-l-0"
>
<span className="text-foreground text-xs">{title}</span>
</Badge>
</div>
{description && (
<div className="text-foreground-light text-sm flex flex-col gap-0">
<div className="prose text-xs max-w-none [&_p]:mt-2 [&_p]:mb-0">{description}</div>
</div>
)}
</div>
{href && (
<Button size="tiny" type="default" className="text-xs" asChild>
<a href={href} target="_blank" rel="noreferrer noopener">
{buttonText ?? 'Read the accouncement'}
</a>
</Button>
)}
</div>
)
}
)
PanelNotice.displayName = 'PanelNotice'
Panel.Content = Content
Panel.Footer = Footer
Panel.Notice = PanelNotice
export default Panel