mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## What
The incident banner links to the status page, but the in-progress and
upcoming maintenance banners had no link.
The maintenance banner titles ("Scheduled maintenance in progress",
"Upcoming scheduled maintenance") now link to that maintenance's own
status page entry (`item.url`).
To support this, `HeaderBanner`'s `title` prop now accepts `ReactNode`
instead of only `string`.
114 lines
2.9 KiB
TypeScript
114 lines
2.9 KiB
TypeScript
import dayjs from 'dayjs'
|
||
import type { ReactNode } from 'react'
|
||
import { TimestampInfo } from 'ui-patterns/TimestampInfo'
|
||
|
||
import { getBannerCopy, type BannerSelection } from './StatusBanner.utils'
|
||
import { useStatusBanner } from './useStatusBanner'
|
||
import { HeaderBanner } from '@/components/interfaces/Organization/HeaderBanner'
|
||
import { InlineLink } from '@/components/ui/InlineLink'
|
||
|
||
const OVERRIDE_TITLE = 'We are investigating a technical issue'
|
||
|
||
const TIMESTAMP_FORMAT = 'DD MMM, HH:mm'
|
||
|
||
function formatTimestampLabel(value: string): string {
|
||
return dayjs(value).format(TIMESTAMP_FORMAT)
|
||
}
|
||
|
||
function getBannerDescription({
|
||
selection,
|
||
description,
|
||
pageUrl,
|
||
}: {
|
||
selection: BannerSelection
|
||
description: string
|
||
pageUrl: string
|
||
}): ReactNode {
|
||
if (selection.kind === 'incident') {
|
||
return (
|
||
<>
|
||
Follow the <InlineLink href={pageUrl}>status page</InlineLink> for updates
|
||
</>
|
||
)
|
||
}
|
||
|
||
if (selection.kind === 'maintenance') {
|
||
const { scheduledEndAt } = selection.item
|
||
const hasFutureEnd = scheduledEndAt !== null && new Date(scheduledEndAt).getTime() > Date.now()
|
||
return (
|
||
<>
|
||
{description}
|
||
{hasFutureEnd && (
|
||
<>
|
||
{' '}
|
||
(
|
||
<TimestampInfo
|
||
utcTimestamp={scheduledEndAt}
|
||
label={formatTimestampLabel(scheduledEndAt)}
|
||
/>
|
||
)
|
||
</>
|
||
)}
|
||
</>
|
||
)
|
||
}
|
||
|
||
const { startsAt, endsAt } = selection.item
|
||
return (
|
||
<>
|
||
{description}
|
||
{startsAt !== null && endsAt !== null && (
|
||
<>
|
||
{' '}
|
||
(<TimestampInfo utcTimestamp={startsAt} label={formatTimestampLabel(startsAt)} />
|
||
{' – '}
|
||
<TimestampInfo utcTimestamp={endsAt} label={formatTimestampLabel(endsAt)} />)
|
||
</>
|
||
)}
|
||
</>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* Global banner for incident.io status page items — a relevant active incident,
|
||
* in-progress maintenance, or upcoming maintenance, in that priority order.
|
||
*/
|
||
export const StatusBanner = ({ signedOut = false }: { signedOut?: boolean } = {}) => {
|
||
const state = useStatusBanner({ signedOut })
|
||
|
||
if (state.type === 'hidden') return null
|
||
|
||
if (state.type === 'override') {
|
||
return (
|
||
<HeaderBanner
|
||
variant="warning"
|
||
title={OVERRIDE_TITLE}
|
||
description={
|
||
<>
|
||
Follow the <InlineLink href="https://status.supabase.com">status page</InlineLink> for
|
||
updates
|
||
</>
|
||
}
|
||
/>
|
||
)
|
||
}
|
||
|
||
const { selection, pageUrl, onDismiss } = state
|
||
const { title, description } = getBannerCopy(selection)
|
||
|
||
return (
|
||
<HeaderBanner
|
||
variant={selection.kind === 'incident' ? 'warning' : 'note'}
|
||
title={
|
||
selection.kind === 'incident' ? (
|
||
title
|
||
) : (
|
||
<InlineLink href={selection.item.url}>{title}</InlineLink>
|
||
)
|
||
}
|
||
description={getBannerDescription({ selection, description, pageUrl })}
|
||
onDismiss={onDismiss}
|
||
/>
|
||
)
|
||
}
|