mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 18:35:07 +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>
176 lines
5.7 KiB
TypeScript
176 lines
5.7 KiB
TypeScript
import { SelectContent, SelectItem, SelectTrigger, Select } from '@ui/components/shadcn/ui/select'
|
|
import CopyButton from 'components/ui/CopyButton'
|
|
import { WarehouseAccessTokensData, WarehouseCollectionsData } from 'data/analytics'
|
|
import { useEffect, useState } from 'react'
|
|
import {
|
|
Button,
|
|
Checkbox_Shadcn_,
|
|
CodeBlock,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
Input,
|
|
Label_Shadcn_,
|
|
TooltipContent_Shadcn_,
|
|
TooltipTrigger_Shadcn_,
|
|
Tooltip_Shadcn_,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
|
|
export function TestCollectionDialog({
|
|
accessTokens,
|
|
collectionToken,
|
|
collections,
|
|
open,
|
|
onOpenChange,
|
|
}: {
|
|
accessTokens: WarehouseAccessTokensData['data']
|
|
collections: WarehouseCollectionsData
|
|
collectionToken: string
|
|
projectRef: string
|
|
open: boolean
|
|
onOpenChange: (open: boolean) => void
|
|
}) {
|
|
const BASE_WAREHOUSE_URL = `https://api.warehouse.tech/api/events`
|
|
const [testAccessToken, setTestAccessToken] = useState('')
|
|
const [selectedCollection, setSelectedCollection] = useState(collectionToken || '')
|
|
const [showAccessToken, setShowAccessToken] = useState(false)
|
|
|
|
useEffect(() => {
|
|
setSelectedCollection(collectionToken)
|
|
}, [collectionToken])
|
|
|
|
useEffect(() => {
|
|
if (accessTokens.length > 0) {
|
|
setTestAccessToken(accessTokens[0].token)
|
|
}
|
|
}, [accessTokens])
|
|
|
|
const selectedAccessToken = accessTokens.find((token) => token.token === testAccessToken)
|
|
const selectedCollectionName = collections?.find((col) => col.token === selectedCollection)?.name
|
|
|
|
function getcURL(accessToken: string) {
|
|
return `curl -X "POST" "${BASE_WAREHOUSE_URL}?source=${selectedCollection}" \\
|
|
-H 'Content-Type: application/json' \\
|
|
-H 'X-API-KEY: ${accessToken}' \\
|
|
-d $'{
|
|
"event_message": "Test event message",
|
|
"metadata": {
|
|
"ip_address": "100.100.100.100",
|
|
"request_method": "POST",
|
|
"custom_user_data": {
|
|
"foo": "bar"
|
|
},
|
|
"datacenter": "aws",
|
|
"request_headers": {
|
|
"connection": "close",
|
|
"user_agent": "chrome"
|
|
}
|
|
}
|
|
}'
|
|
`
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<Tooltip_Shadcn_>
|
|
<TooltipTrigger_Shadcn_ asChild>
|
|
<DialogTrigger asChild>
|
|
<Button disabled={accessTokens.length === 0} type="outline">
|
|
Connect
|
|
</Button>
|
|
</DialogTrigger>
|
|
</TooltipTrigger_Shadcn_>
|
|
{accessTokens.length === 0 && (
|
|
<TooltipContent_Shadcn_>
|
|
Create an access token to connect to your collection
|
|
</TooltipContent_Shadcn_>
|
|
)}
|
|
</Tooltip_Shadcn_>
|
|
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Send events to this collection</DialogTitle>
|
|
<DialogDescription>
|
|
Use the following cURL command to send events to this collection
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<DialogSection className="flex flex-col gap-4 overflow-auto">
|
|
<div className="flex gap-2 *:flex-1">
|
|
<FormItemLayout label="Collection" isReactForm={false}>
|
|
<Select value={selectedCollection} onValueChange={setSelectedCollection}>
|
|
<SelectTrigger>
|
|
<span className="truncate">{selectedCollectionName || 'Collection'}</span>
|
|
</SelectTrigger>
|
|
<SelectContent className="max-h-[260px]">
|
|
{collections?.map((col) => (
|
|
<SelectItem key={col.id} value={col.token}>
|
|
{col.name}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</FormItemLayout>
|
|
<FormItemLayout label="Token" isReactForm={false}>
|
|
<Select value={testAccessToken} onValueChange={setTestAccessToken}>
|
|
<SelectTrigger>
|
|
<span className="truncate">
|
|
{selectedAccessToken?.description || 'Access token'}
|
|
</span>
|
|
</SelectTrigger>
|
|
<SelectContent className="max-h-[260px]">
|
|
{accessTokens?.map((token: any) => (
|
|
<SelectItem key={token.id + '-token'} value={token.token}>
|
|
{token.description || 'No description'}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</FormItemLayout>
|
|
</div>
|
|
|
|
<FormItemLayout label="Ingest URL" isReactForm={false}>
|
|
<Input
|
|
className="font-mono tracking-tighter"
|
|
value={BASE_WAREHOUSE_URL}
|
|
readOnly
|
|
copy
|
|
/>
|
|
</FormItemLayout>
|
|
|
|
<div className="flex gap-2 items-center">
|
|
<Checkbox_Shadcn_
|
|
name="showAccessToken"
|
|
id="showAccessToken"
|
|
checked={showAccessToken}
|
|
onCheckedChange={() => setShowAccessToken(!showAccessToken)}
|
|
/>
|
|
<Label_Shadcn_ htmlFor="showAccessToken">Show access token</Label_Shadcn_>
|
|
</div>
|
|
|
|
<div className="relative">
|
|
<CodeBlock
|
|
hideCopy
|
|
className={'p-1 language-bash prose transition-colors'}
|
|
language="bash"
|
|
>
|
|
{getcURL(showAccessToken ? testAccessToken : '********************')}
|
|
</CodeBlock>
|
|
<CopyButton
|
|
type="default"
|
|
text={getcURL(testAccessToken)}
|
|
className="absolute top-2 right-2"
|
|
/>
|
|
</div>
|
|
</DialogSection>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|