mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
* add event collection ui, queries, routing * fix alignment issue * renaming * wip * feat: initial data hooks and integration with feature flagging * update with naming, correct mocks, etc * feat: add source crud integration * mock data, fix form, add motion to drawer * feat: optimize warehouse fetch behaviour * feat: add in valid query * chore: ermove collection mocks * feat: optimize tenant fetching * cleanup + update openapi client + fix fetch calls * cleanup imporst * on delete success, redirect to main logs page * fix dropdown event propagating to link and opening page * Refactor code to use useParams and useRouter in CreateWarehouseCollection.tsx, WarehouseCollectionDetail.tsx, and LogsLayout.tsx * clean warehouse query * warehouse access tokens create, list * add warehouse access token revokal * fix access tokens table, fix access tokens revoke feature * format date in access tokens table * fix some state issues and warnings in access tokens forms * warehouse/feat: introduction when creating event collections (#23244) feat: add introduction for event collections * warehouse/feat: rename headers and nav items (#23243) * feat: rename headers * feat: use feature flag for navigation bar * move header name flag to component * fix typeerror in create collection query --------- Co-authored-by: Jordi Enric <jordi.err@gmail.com> * ui fixes, rm deprecated icons * render table with events * fix typeerror results arr * add pagination * some ui fixes * fix loading states, format dates, test connection dialog * patch type errors * Fix access token selection in TestCollectionDialog and update column name in WarehouseAccessTokens * rm unused querytype * rm unused querytype in logtable * patch type errors in warhouse collection mutations * rm unused component * mr unused import * show connection dialog in staging * fix Run btn now showing up * fix undef argument * show pagination only when there are results * fix issues in connection dialog, improve ux * Update apps/studio/components/interfaces/DataWarehouse/CreateWarehouseAccessToken.tsx Co-authored-by: Ziinc <Ziinc@users.noreply.github.com> * Update apps/studio/components/interfaces/DataWarehouse/CreateWarehouseAccessToken.tsx Co-authored-by: Ziinc <Ziinc@users.noreply.github.com> * fix infinite render loop, adapt component to render log metadata on log selection * rm unused import, prevent ui from breaking when some data may be missing from an event * update WAT create mutation to use template * follow mutation template in delete access token mutation * refactor naming, improve code in some areas * rm unused mocks for msw * skip tests - this will get fixed on the vitest PR * Update apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx Co-authored-by: Joshen Lim <joshenlimek@gmail.com> * fix loading compo * rm unused import * use correct alert title * rm unnecessary div * fix layout in projectpaused alert * fix type err, refactor to new method * rm observer * rm observer * refactor warehouse collections update * use correct get method, comment out so it doesnt err * use correct method * fix formatting issues * ref imports * ref imports * clean up imports * clean imports * clean imports * rename props * destructure props * cleanup imports * Update apps/studio/components/interfaces/DataWarehouse/CreateWarehouseCollection.tsx Co-authored-by: Ziinc <Ziinc@users.noreply.github.com> * ref scale class * cleanup divs * Update apps/studio/components/interfaces/DataWarehouse/TestCollectionDialog.tsx Co-authored-by: Ziinc <Ziinc@users.noreply.github.com> * refactor to rhf * reuse types, cleanup, refactor to react query hooks instead of el events * refactor table component to handle empty state * Update TestCollectionDialog to use unique keys for SelectItem components * Update TestCollectionDialog to use unique keys for SelectItem components * Update TestCollectionDialog to use unique keys for SelectItem components * fix empty state ui * use destructured queries * rename query types * Update apps/studio/components/interfaces/DataWarehouse/WarehouseAccessTokens.tsx Co-authored-by: Ziinc <Ziinc@users.noreply.github.com> * chore: Refactor WarehouseCollectionDetail component * rm unused imports * rename loadolder * rm typcast * rhf in create token * improve err handling * refactor to rhf, refactor queries, use cn utils, cleanup * fix loading logselection * add correct type to warehouse access tokens query * use correct types in err & clean unused types * toggle token in curl exampel * use product empty state component in warehouse * add client side validation of collection name, temp fix * add New badge * update testcolldialog * cleanup unnecessary div and rm double border * code style fixes * handle err * code style fix * add correct type * add correct err type * fix type error * fix type err * fix missing type --------- Co-authored-by: TzeYiing <ty@tzeyiing.com> Co-authored-by: Ziinc <Ziinc@users.noreply.github.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
323 lines
11 KiB
TypeScript
323 lines
11 KiB
TypeScript
import * as Tooltip from '@radix-ui/react-tooltip'
|
|
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import {
|
|
Alert,
|
|
Badge,
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
IconBookOpen,
|
|
IconCheck,
|
|
IconChevronDown,
|
|
IconClipboard,
|
|
IconExternalLink,
|
|
IconX,
|
|
Popover,
|
|
SidePanel,
|
|
Tabs,
|
|
} from 'ui'
|
|
|
|
import { useCheckPermissions, useIsFeatureEnabled } from 'hooks'
|
|
import { useProfile } from 'lib/profile'
|
|
import Link from 'next/link'
|
|
import React, { useState } from 'react'
|
|
import {
|
|
EXPLORER_DATEPICKER_HELPERS,
|
|
LogsTableName,
|
|
LogsWarning,
|
|
LOGS_SOURCE_DESCRIPTION,
|
|
LogTemplate,
|
|
} from '.'
|
|
import DatePickers from './Logs.DatePickers'
|
|
import Table from 'components/to-be-cleaned/Table'
|
|
import { logConstants } from 'shared-data'
|
|
import { copyToClipboard } from 'lib/helpers'
|
|
|
|
export interface LogsQueryPanelProps {
|
|
templates?: LogTemplate[]
|
|
onSelectTemplate: (template: LogTemplate) => void
|
|
onSelectSource: (source: LogsTableName) => void
|
|
onClear: () => void
|
|
onSave?: () => void
|
|
hasEditorValue: boolean
|
|
isLoading: boolean
|
|
onDateChange: React.ComponentProps<typeof DatePickers>['onChange']
|
|
defaultTo: string
|
|
defaultFrom: string
|
|
warnings: LogsWarning[]
|
|
}
|
|
|
|
const LogsQueryPanel = ({
|
|
templates = [],
|
|
onSelectTemplate,
|
|
onSelectSource,
|
|
defaultFrom,
|
|
defaultTo,
|
|
onDateChange,
|
|
warnings,
|
|
}: LogsQueryPanelProps) => {
|
|
const [showReference, setShowReference] = React.useState(false)
|
|
|
|
const {
|
|
projectAuthAll: authEnabled,
|
|
projectStorageAll: storageEnabled,
|
|
projectEdgeFunctionAll: edgeFunctionsEnabled,
|
|
} = useIsFeatureEnabled(['project_auth:all', 'project_storage:all', 'project_edge_function:all'])
|
|
|
|
const logsTableNames = Object.entries(LogsTableName)
|
|
.filter(([key]) => {
|
|
if (key === 'AUTH') return authEnabled
|
|
if (key === 'STORAGE') return storageEnabled
|
|
if (key === 'FN_EDGE') return edgeFunctionsEnabled
|
|
return true
|
|
})
|
|
.map(([, value]) => value)
|
|
|
|
return (
|
|
<div className="rounded rounded-bl-none rounded-br-none border border-overlay bg-surface-100">
|
|
<div className="flex w-full items-center justify-between px-5 py-2">
|
|
<div className="flex w-full flex-row items-center justify-between gap-x-4">
|
|
<div className="flex items-center gap-2">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button type="default" iconRight={<IconChevronDown />}>
|
|
Insert source
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="bottom" align="start">
|
|
{logsTableNames
|
|
.sort((a, b) => a.localeCompare(b))
|
|
.map((source) => (
|
|
<DropdownMenuItem key={source} onClick={() => onSelectSource(source)}>
|
|
<div className="flex flex-col gap-1">
|
|
<span className="font-mono font-bold">{source}</span>
|
|
<span className="text-foreground-light">
|
|
{LOGS_SOURCE_DESCRIPTION[source]}
|
|
</span>
|
|
</div>
|
|
</DropdownMenuItem>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button type="default" iconRight={<IconChevronDown />}>
|
|
Templates
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="bottom" align="start">
|
|
{templates
|
|
.sort((a, b) => a.label!.localeCompare(b.label!))
|
|
.map((template) => (
|
|
<DropdownMenuItem
|
|
key={template.label}
|
|
onClick={() => onSelectTemplate(template)}
|
|
>
|
|
<p>{template.label}</p>
|
|
</DropdownMenuItem>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
<DatePickers
|
|
to={defaultTo}
|
|
from={defaultFrom}
|
|
onChange={onDateChange}
|
|
helpers={EXPLORER_DATEPICKER_HELPERS}
|
|
/>
|
|
<div className="overflow-hidden">
|
|
<div
|
|
className={` transition-all duration-300 ${
|
|
warnings.length > 0 ? 'opacity-100' : 'invisible h-0 w-0 opacity-0'
|
|
}`}
|
|
>
|
|
<Popover
|
|
overlay={
|
|
<Alert variant="warning" title="">
|
|
<div className="flex flex-col gap-3">
|
|
{warnings.map((warning, index) => (
|
|
<p key={index}>
|
|
{warning.text}{' '}
|
|
{warning.link && (
|
|
<Link href={warning.link}>{warning.linkText || 'View'}</Link>
|
|
)}
|
|
</p>
|
|
))}
|
|
</div>
|
|
</Alert>
|
|
}
|
|
>
|
|
<Badge variant="warning">
|
|
{warnings.length} {warnings.length > 1 ? 'warnings' : 'warning'}
|
|
</Badge>
|
|
</Popover>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div className="flex items-center gap-4">
|
|
<div className="flex items-center gap-2">
|
|
<SidePanel
|
|
size="large"
|
|
header={
|
|
<div className="flex flex-row justify-between items-center">
|
|
<h3>Field Reference</h3>
|
|
<Button
|
|
type="text"
|
|
className="px-1"
|
|
onClick={() => setShowReference(false)}
|
|
icon={<IconX size={18} strokeWidth={1.5} />}
|
|
/>
|
|
</div>
|
|
}
|
|
visible={showReference}
|
|
cancelText="Close"
|
|
onCancel={() => setShowReference(false)}
|
|
hideFooter
|
|
triggerElement={
|
|
<Button
|
|
asChild // ?: we don't want a button inside a button
|
|
type="default"
|
|
onClick={() => setShowReference(true)}
|
|
icon={<IconBookOpen strokeWidth={1.5} />}
|
|
>
|
|
<span>Field Reference</span>
|
|
</Button>
|
|
}
|
|
>
|
|
<SidePanel.Content>
|
|
<div className="pt-4 pb-2 space-y-1">
|
|
<p className="text-sm">
|
|
The following table shows all the available paths that can be queried from
|
|
each respective source. Do note that to access nested keys, you would need
|
|
to perform the necessary{' '}
|
|
<Link
|
|
href="https://supabase.com/docs/guides/platform/logs#unnesting-arrays"
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="text-brand"
|
|
>
|
|
unnesting joins
|
|
<IconExternalLink
|
|
size="tiny"
|
|
className="ml-1 inline -translate-y-[2px]"
|
|
strokeWidth={1.5}
|
|
/>
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</SidePanel.Content>
|
|
<SidePanel.Separator />
|
|
<Tabs
|
|
scrollable
|
|
size="small"
|
|
type="underlined"
|
|
defaultActiveId="edge_logs"
|
|
listClassNames="px-2"
|
|
>
|
|
{logConstants.schemas.map((schema) => (
|
|
<Tabs.Panel
|
|
key={schema.reference}
|
|
id={schema.reference}
|
|
label={schema.name}
|
|
className="px-4 pb-4"
|
|
>
|
|
<Table
|
|
head={[
|
|
<Table.th className="text-xs !p-2" key="path">
|
|
Path
|
|
</Table.th>,
|
|
<Table.th key="type" className="text-xs !p-2">
|
|
Type
|
|
</Table.th>,
|
|
]}
|
|
body={schema.fields
|
|
.sort((a: any, b: any) => a.path - b.path)
|
|
.map((field) => (
|
|
<Field key={field.path} field={field} />
|
|
))}
|
|
/>
|
|
</Tabs.Panel>
|
|
))}
|
|
</Tabs>
|
|
</SidePanel>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const Field = ({
|
|
field,
|
|
}: {
|
|
field: {
|
|
path: string
|
|
type: string
|
|
}
|
|
}) => {
|
|
const [isCopied, setIsCopied] = useState(false)
|
|
|
|
return (
|
|
<Table.tr>
|
|
<Table.td
|
|
className="font-mono text-xs !p-2 cursor-pointer hover:text-foreground transition flex items-center space-x-2"
|
|
onClick={() =>
|
|
copyToClipboard(field.path, () => {
|
|
setIsCopied(true)
|
|
setTimeout(() => setIsCopied(false), 3000)
|
|
})
|
|
}
|
|
>
|
|
<span>{field.path}</span>
|
|
{isCopied ? (
|
|
<Tooltip.Root delayDuration={0}>
|
|
<Tooltip.Trigger>
|
|
<IconCheck size={14} strokeWidth={3} className="text-brand" />
|
|
</Tooltip.Trigger>
|
|
<Tooltip.Portal>
|
|
<Tooltip.Content side="bottom">
|
|
<Tooltip.Arrow className="radix-tooltip-arrow" />
|
|
<div
|
|
className={[
|
|
'rounded bg-alternative py-1 px-2 leading-none shadow',
|
|
'border border-background',
|
|
].join(' ')}
|
|
>
|
|
<span className="text-xs text-foreground">Copied</span>
|
|
</div>
|
|
</Tooltip.Content>
|
|
</Tooltip.Portal>
|
|
</Tooltip.Root>
|
|
) : (
|
|
<Tooltip.Root delayDuration={0}>
|
|
<Tooltip.Trigger>
|
|
<IconClipboard size="tiny" strokeWidth={1.5} />
|
|
</Tooltip.Trigger>
|
|
<Tooltip.Portal>
|
|
<Tooltip.Content side="bottom">
|
|
<Tooltip.Arrow className="radix-tooltip-arrow" />
|
|
<div
|
|
className={[
|
|
'rounded bg-alternative py-1 px-2 leading-none shadow',
|
|
'border border-background',
|
|
].join(' ')}
|
|
>
|
|
<span className="text-xs text-foreground">Copy value</span>
|
|
</div>
|
|
</Tooltip.Content>
|
|
</Tooltip.Portal>
|
|
</Tooltip.Root>
|
|
)}
|
|
</Table.td>
|
|
<Table.td className="font-mono text-xs !p-2">{field.type}</Table.td>
|
|
</Table.tr>
|
|
)
|
|
}
|
|
|
|
export default LogsQueryPanel
|