mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 15:44:23 +08:00
* Midway implementation notifications v2 * Some updates to Tab component * Midway implementation notifications v2 again * implement infinite scrolling and loading for notification sv2 * Add button actions * Implement archive notifications * Add filter dropdown for notifications * Update date format * Small style fix * Update * Update API codegen * Add empt state * Add empty state for archived notifications * Fix type * Final changes to notifications v2 * Small style fix * Small fix * Only mark notifications that come into view as read * Update package lock
141 lines
4.9 KiB
TypeScript
141 lines
4.9 KiB
TypeScript
import { useParams } from 'common'
|
|
import Link from 'next/link'
|
|
import { useMemo } from 'react'
|
|
import { Badge } from 'ui'
|
|
|
|
import BranchDropdown from 'components/layouts/AppLayout/BranchDropdown'
|
|
import EnableBranchingButton from 'components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton'
|
|
import OrganizationDropdown from 'components/layouts/AppLayout/OrganizationDropdown'
|
|
import ProjectDropdown from 'components/layouts/AppLayout/ProjectDropdown'
|
|
import { getResourcesExceededLimitsOrg } from 'components/ui/OveragesBanner/OveragesBanner.utils'
|
|
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
|
|
import { useOrgUsageQuery } from 'data/usage/org-usage-query'
|
|
import { useFlag, useSelectedOrganization, useSelectedProject } from 'hooks'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import BreadcrumbsView from './BreadcrumbsView'
|
|
import FeedbackDropdown from './FeedbackDropdown'
|
|
import HelpPopover from './HelpPopover'
|
|
import NotificationsPopover from './NotificationsPopover'
|
|
import NotificationsPopoverV2 from './NotificationsPopoverV2/NotificationsPopover'
|
|
|
|
const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder = true }: any) => {
|
|
const { ref: projectRef } = useParams()
|
|
const selectedProject = useSelectedProject()
|
|
const selectedOrganization = useSelectedOrganization()
|
|
|
|
const enableBranchManagement = useFlag('branchManagement')
|
|
const notificationsV2 = useFlag('notificationsV2')
|
|
|
|
const isBranchingEnabled =
|
|
selectedProject?.is_branch_enabled === true || selectedProject?.parent_project_ref !== undefined
|
|
|
|
const { data: orgUsage } = useOrgUsageQuery({ orgSlug: selectedOrganization?.slug })
|
|
|
|
const exceedingLimits = useMemo(() => {
|
|
if (orgUsage) {
|
|
return getResourcesExceededLimitsOrg(orgUsage?.usages || []).length > 0
|
|
} else {
|
|
return false
|
|
}
|
|
}, [orgUsage])
|
|
|
|
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: selectedOrganization?.slug })
|
|
|
|
const projectHasNoLimits = subscription?.usage_billing_enabled === true
|
|
|
|
const showOverUsageBadge =
|
|
useFlag('overusageBadge') &&
|
|
subscription !== undefined &&
|
|
(subscription.plan.id === 'free' || subscription.plan.id === 'pro') &&
|
|
!projectHasNoLimits &&
|
|
exceedingLimits
|
|
|
|
return (
|
|
<div
|
|
className={`flex h-12 max-h-12 items-center justify-between py-2 px-5 ${
|
|
headerBorder ? 'border-b border-default' : ''
|
|
}`}
|
|
>
|
|
<div className="-ml-2 flex items-center text-sm">
|
|
{/* Organization is selected */}
|
|
{projectRef && (
|
|
<>
|
|
<OrganizationDropdown />
|
|
|
|
{projectRef && (
|
|
<>
|
|
<span className="text-border-stronger">
|
|
<svg
|
|
viewBox="0 0 24 24"
|
|
width="16"
|
|
height="16"
|
|
stroke="currentColor"
|
|
strokeWidth="1"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
fill="none"
|
|
shapeRendering="geometricPrecision"
|
|
>
|
|
<path d="M16 3.549L7.12 20.600"></path>
|
|
</svg>
|
|
</span>
|
|
|
|
<ProjectDropdown />
|
|
|
|
{showOverUsageBadge && (
|
|
<div className="ml-2">
|
|
<Link href={`/org/${selectedOrganization?.slug}/usage`}>
|
|
<Badge color="red">Exceeding usage limits</Badge>
|
|
</Link>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
|
|
{selectedProject && enableBranchManagement && (
|
|
<>
|
|
<span className="text-border-stronger">
|
|
<svg
|
|
viewBox="0 0 24 24"
|
|
width="16"
|
|
height="16"
|
|
stroke="currentColor"
|
|
strokeWidth="1"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
fill="none"
|
|
shapeRendering="geometricPrecision"
|
|
>
|
|
<path d="M16 3.549L7.12 20.600"></path>
|
|
</svg>
|
|
</span>
|
|
{isBranchingEnabled ? <BranchDropdown /> : <EnableBranchingButton />}
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
|
|
{/* Additional breadcrumbs are supplied */}
|
|
<BreadcrumbsView defaultValue={breadcrumbs} />
|
|
</div>
|
|
<div className="flex items-center space-x-2">
|
|
{customHeaderComponents && customHeaderComponents}
|
|
{IS_PLATFORM && <FeedbackDropdown alt={notificationsV2} />}
|
|
{IS_PLATFORM && !notificationsV2 && (
|
|
<>
|
|
<HelpPopover />
|
|
<NotificationsPopover />
|
|
</>
|
|
)}
|
|
{IS_PLATFORM && notificationsV2 && (
|
|
<>
|
|
<NotificationsPopoverV2 />
|
|
<HelpPopover alt />
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
export default LayoutHeader
|