Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

warehouse ui/ux fixes (#29057)

Jordi Enric6e6910f82ba2
diff --git a/apps/studio/components/grid/components/common/Hooks.tsx b/apps/studio/components/grid/components/common/Hooks.tsx
index 1d52d6524ba..2e081fa49cc 100644
--- a/apps/studio/components/grid/components/common/Hooks.tsx
+++ b/apps/studio/components/grid/components/common/Hooks.tsx
@@ -15,7 +15,7 @@ function includes(array: string[], element: string) {
* trigger shortcut event
*/
export function useKeyboardShortcuts(
- keyMap: { [id: string]: (event: KeyboardEvent) => void },
+ keyMap: { [id: KeyboardEvent['key']]: (event: KeyboardEvent) => void },
whitelistNodes: string[] = [],
whitelistClasses: string[] = []
) {
diff --git a/apps/studio/components/interfaces/DataWarehouse/CreateWarehouseCollection.tsx b/apps/studio/components/interfaces/DataWarehouse/CreateWarehouseCollection.tsx
index 132d76a1297..86886d0f2e8 100644
--- a/apps/studio/components/interfaces/DataWarehouse/CreateWarehouseCollection.tsx
+++ b/apps/studio/components/interfaces/DataWarehouse/CreateWarehouseCollection.tsx
@@ -25,9 +25,9 @@ export const CreateWarehouseCollectionModal = () => {
const { mutate: createCollection, isLoading } = useCreateCollection({
onSuccess: (data) => {
- // todo: remove typecast once api types are fixed
setIsOpen(false)
- router.push(`/project/${ref}/logs/collections/${(data as any).token}`)
+ toast.success('Collection created successfully')
+ router.push(`/project/${ref}/logs/collections/${data.token}`)
},
onError: (error) => {
toast.error(error.message)
@@ -76,7 +76,6 @@ export const CreateWarehouseCollectionModal = () => {
>
New collection
</ButtonTooltip>
- {/* <Button onClick={() => setIsOpen(!isOpen)}>Create collection</Button> */}
<Modal
size="medium"
onCancel={() => setIsOpen(!isOpen)}
@@ -88,9 +87,9 @@ export const CreateWarehouseCollectionModal = () => {
<form onSubmit={onSubmit}>
<Modal.Content className="py-4">
<p className="pb-5 text-foreground-light text-sm">
- An event collection stores generic timeseries events and metadata in
- Supabase-managed analytics infrastructure. Events can be then be queried using SQL,
- without impacting transactional workloads.
+ An event collection stores time-based data and related information in Supabase's
+ analytics system. You can use SQL to analyze this data without affecting the
+ performance of your main database operations.
</p>
<FormField_Shadcn_
@@ -113,7 +112,7 @@ export const CreateWarehouseCollectionModal = () => {
Cancel
</Button>
<Button size="tiny" loading={isLoading} disabled={isLoading} htmlType="submit">
- Create table
+ Create collection
</Button>
</Modal.Content>
</form>
diff --git a/apps/studio/components/interfaces/DataWarehouse/TestCollectionDialog.tsx b/apps/studio/components/interfaces/DataWarehouse/TestCollectionDialog.tsx
index 4911e46a208..c71b73de2da 100644
--- a/apps/studio/components/interfaces/DataWarehouse/TestCollectionDialog.tsx
+++ b/apps/studio/components/interfaces/DataWarehouse/TestCollectionDialog.tsx
@@ -2,21 +2,25 @@ import { Select, SelectContent, SelectItem, SelectTrigger } from '@ui/components
import CopyButton from 'components/ui/CopyButton'
import type { WarehouseAccessTokensData } from 'data/analytics/warehouse-access-tokens-query'
import type { WarehouseCollectionsData } from 'data/analytics/warehouse-collections-query'
+import { Code } from 'lucide-react'
+import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import {
Button,
Checkbox_Shadcn_,
CodeBlock,
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogSection,
DialogSectionSeparator,
- DialogTitle,
- DialogTrigger,
- Input,
+ Input_Shadcn_,
Label_Shadcn_,
+ Separator,
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetSection,
+ SheetTitle,
+ SheetTrigger,
TooltipContent_Shadcn_,
TooltipTrigger_Shadcn_,
Tooltip_Shadcn_,
@@ -29,6 +33,7 @@ export function TestCollectionDialog({
collections,
open,
onOpenChange,
+ onSubmit,
}: {
accessTokens: WarehouseAccessTokensData['data']
collections: WarehouseCollectionsData
@@ -36,7 +41,9 @@ export function TestCollectionDialog({
projectRef: string
open: boolean
onOpenChange: (open: boolean) => void
+ onSubmit: () => void
}) {
+ const router = useRouter()
const BASE_WAREHOUSE_URL = `https://api.warehouse.tech/api/events`
const [testAccessToken, setTestAccessToken] = useState('')
const [selectedCollection, setSelectedCollection] = useState(collectionToken || '')
@@ -58,7 +65,7 @@ export function TestCollectionDialog({
function getcURL(accessToken: string) {
return `curl -X "POST" "${BASE_WAREHOUSE_URL}?source=${selectedCollection}" \\
-H 'Content-Type: application/json' \\
- -H 'X-API-KEY: ${accessToken}' \\
+ -H 'Authorization: Bearer ${accessToken}' \\
-d $'{
"event_message": "Test event message",
"metadata": {
@@ -78,14 +85,14 @@ export function TestCollectionDialog({
}
return (
- <Dialog open={open} onOpenChange={onOpenChange}>
+ <Sheet open={open} onOpenChange={onOpenChange}>
<Tooltip_Shadcn_>
<TooltipTrigger_Shadcn_ asChild>
- <DialogTrigger asChild>
+ <SheetTrigger asChild>
<Button disabled={accessTokens.length === 0} type="outline">
Connect
</Button>
- </DialogTrigger>
+ </SheetTrigger>
</TooltipTrigger_Shadcn_>
{accessTokens.length === 0 && (
<TooltipContent_Shadcn_>
@@ -94,83 +101,90 @@ export function TestCollectionDialog({
)}
</Tooltip_Shadcn_>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Send events to this collection</DialogTitle>
- <DialogDescription>
+ <SheetContent size="lg" className="h-screen overflow-auto flex flex-col">
+ <SheetHeader>
+ <SheetTitle>Send events to this collection</SheetTitle>
+ <SheetDescription>
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>
+ </SheetDescription>
+ </SheetHeader>
+
+ <SheetSection className="flex flex-col gap-4 overflow-auto">
+ <FormItemLayout label="Collection" isReactForm={false} layout="horizontal">
+ <Select value={selectedCollection} onValueChange={setSelectedCollection}>
+ <SelectTrigger size="tiny">
+ <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} layout="horizontal">
+ <Select value={testAccessToken} onValueChange={setTestAccessToken}>
+ <SelectTrigger size="tiny">
+ <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>
- <FormItemLayout label="Ingest URL" isReactForm={false}>
- <Input
- className="font-mono tracking-tighter"
- value={BASE_WAREHOUSE_URL}
- readOnly
- copy
- />
+ <FormItemLayout layout="horizontal" label="Ingest API URL" isReactForm={false}>
+ <Input_Shadcn_ size="tiny" className="font-mono" value={BASE_WAREHOUSE_URL} readOnly />
</FormItemLayout>
+ <FormItemLayout layout="horizontal" label="Collection ID" isReactForm={false}>
+ <Input_Shadcn_ size="tiny" className="font-mono" value={selectedCollection} readOnly />
+ </FormItemLayout>
+ </SheetSection>
+
+ <Separator />
- <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_>
+ <SheetSection className="flex-1">
+ <div className="flex justify-between items-center">
+ <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>
+ <CopyButton type="default" text={getcURL(testAccessToken)} />
</div>
- <div className="relative">
+ <div className="mt-4 relative">
<CodeBlock
hideCopy
- className={'p-1 language-bash prose transition-colors'}
+ className={'p-1 language-bash prose max-w-full transition-colors'}
language="bash"
>
{getcURL(showAccessToken ? testAccessToken : '********************')}
</CodeBlock>
- <CopyButton
- type="default"
- text={getcURL(testAccessToken)}
- className="absolute top-2 right-2"
- />
</div>
- </DialogSection>
- </DialogContent>
- </Dialog>
+ </SheetSection>
+
+ <SheetFooter className="mt-auto">
+ <p className="text-sm text-foreground-light mr-auto">
+ Once you send an event, refresh the page to see it in the collection.
+ </p>
+ <div className="flex justify-end">
+ <Button onClick={onSubmit}>Refresh results</Button>
+ </div>
+ </SheetFooter>
+ </SheetContent>
+ </Sheet>
)
}
diff --git a/apps/studio/components/interfaces/DataWarehouse/WarehouseAccessTokens.tsx b/apps/studio/components/interfaces/DataWarehouse/WarehouseAccessTokens.tsx
index d323dd4787e..2adc9909edc 100644
--- a/apps/studio/components/interfaces/DataWarehouse/WarehouseAccessTokens.tsx
+++ b/apps/studio/components/interfaces/DataWarehouse/WarehouseAccessTokens.tsx
@@ -143,7 +143,7 @@ export const WarehouseAccessTokens = () => {
<FormHeader
className="!mb-0"
title="Access tokens"
- description="Manage your warehouse access tokens for this project."
+ description="Manage your analytics access tokens for this project."
actions={
<CreateWarehouseAccessToken
open={open}
@@ -160,13 +160,13 @@ export const WarehouseAccessTokens = () => {
/>
{!canReadAccessTokens ? (
- <NoPermission resourceText="view warehouse access tokens" />
+ <NoPermission resourceText="view analytics access tokens" />
) : (
<div className={cn(['bg-surface-100', 'overflow-hidden', 'rounded-md shadow'])}>
{!isProjectActive ? (
<ProjectPausedAlert
projectRef={projectRef}
- description="Restore your project to manage your warehouse access tokens"
+ description="Restore your project to manage your analytics access tokens"
/>
) : (
<>
diff --git a/apps/studio/components/interfaces/DataWarehouse/WarehouseCollectionDetail.tsx b/apps/studio/components/interfaces/DataWarehouse/WarehouseCollectionDetail.tsx
index e4df2c07209..3311e761247 100644
--- a/apps/studio/components/interfaces/DataWarehouse/WarehouseCollectionDetail.tsx
+++ b/apps/studio/components/interfaces/DataWarehouse/WarehouseCollectionDetail.tsx
@@ -1,8 +1,7 @@
-import { RefreshCcw, Rewind } from 'lucide-react'
+import { RefreshCcw, Rewind, Terminal } from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
-
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
import AlertError from 'components/ui/AlertError'
import LoadingOpacity from 'components/ui/LoadingOpacity'
@@ -14,6 +13,37 @@ import { useFlag } from 'hooks/ui/useFlag'
import { Button } from 'ui'
import LogTable from '../Settings/Logs/LogTable'
import { TestCollectionDialog } from './TestCollectionDialog'
+import { Tooltip, TooltipContent, TooltipTrigger } from '@ui/components/shadcn/ui/tooltip'
+import { Input } from '@ui/components/shadcn/ui/input'
+import DatePickers from '../Settings/Logs/Logs.DatePickers'
+import { DatetimeHelper } from '../Settings/Logs/Logs.types'
+import dayjs from 'dayjs'
+import { useKeyboardShortcuts } from 'components/grid/components/common/Hooks'
+
+const djs = dayjs()
+const INTERVALS: DatetimeHelper[] = [
+ {
+ text: 'Last hour',
+ calcFrom: () => djs.subtract(1, 'hour').toISOString(),
+ calcTo: () => djs.toISOString(),
+ default: true,
+ },
+ {
+ text: 'Last 12 hours',
+ calcFrom: () => djs.subtract(12, 'hour').toISOString(),
+ calcTo: () => djs.toISOString(),
+ },
+ {
+ text: 'Last day',
+ calcFrom: () => djs.subtract(1, 'day').toISOString(),
+ calcTo: () => djs.toISOString(),
+ },
+ {
+ text: 'Last 7 days',
+ calcFrom: () => djs.subtract(7, 'day').toISOString(),
+ calcTo: () => djs.toISOString(),
+ },
+]
export const WarehouseCollectionDetail = () => {
const router = useRouter()
@@ -29,26 +59,38 @@ export const WarehouseCollectionDetail = () => {
)
const collection = (collections || []).find((c) => c.token === collectionToken)
const [params, setParams] = useState({
- sql: `select current_timestamp() as 'time'`,
+ sql: ``,
})
+ const [search, setSearch] = useState('')
- const [pagination, setPagination] = useState({
+ const [filters, setFilters] = useState({
limit: 100,
offset: 0,
+ search: '',
+ interval: {
+ to: INTERVALS[0].calcTo(),
+ from: INTERVALS[0].calcFrom(),
+ },
})
useEffect(() => {
if (collection) {
+ const from = filters.interval?.from
+ const to = filters.interval?.to
+
+ const sql = `select id, timestamp, event_message from \`${collection.name}\`
+where timestamp >= TIMESTAMP('${from}')
+${to ? `and timestamp <= TIMESTAMP('${to}')` : ''}
+and event_message like '%${filters.search}%'
+order by timestamp desc limit ${filters.limit} offset ${filters.offset}
+ `
+
setParams((prevParams) => ({
...prevParams,
- sql: `
- select id, timestamp, event_message from \`${collection.name}\`
- where timestamp > timestamp_sub(current_timestamp(), interval 7 day)
- order by timestamp desc limit ${pagination.limit} offset ${pagination.offset}
- `,
+ sql,
}))
}
- }, [collection, pagination])
+ }, [collection, filters])
const {
isLoading: queryLoading,
@@ -81,23 +123,106 @@ export const WarehouseCollectionDetail = () => {
const results = formatResults(queryData?.result)
function loadMore() {
- setPagination({ ...pagination, offset: pagination.offset + pagination.limit })
+ setFilters({ ...filters, offset: filters.offset + filters.limit })
}
const isLoading = queryLoading || collectionsLoading || isRefetching
+ function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
+ e.preventDefault()
+ setFilters({ ...filters, search })
+ refetch()
+ }
+
+ const queryUrl = `/project/${projectRef}/logs/explorer?q=${encodeURIComponent(
+ params.sql || ''
+ )}&source=warehouse`
+
+ useKeyboardShortcuts(
+ {
+ r: () => {
+ document.getElementById('refresh-button')?.focus()
+ },
+ s: () => {
+ document.getElementById('search-input')?.focus()
+ },
+ },
+ ['INPUT', 'BUTTON', 'TEXTAREA']
+ )
+
+ function KeyboardShortcut({ children }: { children: React.ReactNode }) {
+ return (
+ <span className="flex items-center gap-2 font-medium text-xs font-mono text-foreground-light border rounded-md px-1.5 py-0.5 border-b-2">
+ {children}
+ </span>
+ )
+ }
return (
<div className="relative flex flex-col flex-grow h-full">
<ShimmerLine active={isLoading} />
<LoadingOpacity active={isLoading}>
<div className="flex flex-col w-full">
- <div className="flex justify-between items-center pr-3">
- <h2 className="p-3">{collection?.name}</h2>
+ <div className="flex justify-between items-center h-12 px-5">
+ <form onSubmit={handleSubmit} className="flex items-center gap-2">
+ <h2 className="text-foreground-light max-w-60 truncate" title={collection?.name}>
+ {collection?.name}
+ </h2>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ id="refresh-button"
+ htmlType="submit"
+ icon={<RefreshCcw />}
+ type="text"
+ loading={isLoading}
+ disabled={isLoading}
+ className="px-1.5"
+ />
+ </TooltipTrigger>
+ <TooltipContent className="flex items-center gap-2">
+ Refresh <KeyboardShortcut>R</KeyboardShortcut>
+ </TooltipContent>
+ </Tooltip>
+ <Input
+ type="search"
+ id="search-input"
+ className="w-52"
+ size="tiny"
+ placeholder="Search by event message"
+ value={search}
+ onChange={(e) => setSearch(e.target.value)}
+ />
+ <DatePickers
+ to={filters.interval?.to}
+ from={filters.interval?.from}
+ helpers={INTERVALS}
+ onChange={(e) =>
+ setFilters({
+ ...filters,
+ interval: {
+ to: e.to || '',
+ from: e.from || '',
+ },
+ })
+ }
+ />
+ </form>
<div className="flex items-center gap-2">
<Button asChild type={'text'}>
<Link href={`/project/${projectRef}/settings/warehouse`}>Access tokens</Link>
</Button>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button asChild className="px-1.5" type="outline" icon={<Terminal />}>
+ <Link href={queryUrl} />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="text-xs">
+ Open query in Collections Explorer
+ </TooltipContent>
+ </Tooltip>
+
<TestCollectionDialog
accessTokens={accessTokens.data?.data || []}
collectionToken={collectionToken}
@@ -105,6 +230,10 @@ export const WarehouseCollectionDetail = () => {
collections={collections || []}
open={testDialogOpen}
onOpenChange={setTestDialogOpen}
+ onSubmit={() => {
+ refetch()
+ setTestDialogOpen(false)
+ }}
/>
</div>
</div>
@@ -128,15 +257,15 @@ export const WarehouseCollectionDetail = () => {
showHeader={false}
emptyState={
<ProductEmptyState
- title="Send your first event"
+ title="No events found"
size="large"
- ctaButtonLabel="Send first event"
- infoButtonLabel="What Warehouse?"
+ ctaButtonLabel="Send test event"
onClickCta={() => setTestDialogOpen(true)}
>
<>
<p>
- No data available for this collection. Send your first event to see data here.
+ No events match your current search criteria. <br />
+ Try adjusting your filters or send a test event to populate this collection.
</p>
</>
</ProductEmptyState>
@@ -162,10 +291,10 @@ export const WarehouseCollectionDetail = () => {
</Button>
</>
)}
- {pagination.offset !== 0 && (
+ {filters.offset !== 0 && (
<>
<Button
- onClick={() => setPagination({ ...pagination, offset: 0 })}
+ onClick={() => setFilters({ ...filters, offset: 0 })}
type="default"
loading={isLoading}
disabled={isLoading}
@@ -175,15 +304,6 @@ export const WarehouseCollectionDetail = () => {
</>
)}
</div>
- <Button
- onClick={() => refetch()}
- icon={<RefreshCcw />}
- type="default"
- loading={isLoading}
- disabled={isLoading}
- >
- Refresh
- </Button>
</div>
)}
</div>
diff --git a/apps/studio/components/interfaces/DataWarehouse/WarehouseMenuItem.tsx b/apps/studio/components/interfaces/DataWarehouse/WarehouseMenuItem.tsx
index 2e7202cda37..ad8bbf2e638 100644
--- a/apps/studio/components/interfaces/DataWarehouse/WarehouseMenuItem.tsx
+++ b/apps/studio/components/interfaces/DataWarehouse/WarehouseMenuItem.tsx
@@ -94,7 +94,7 @@ export const WarehouseMenuItem = ({ item }: Props) => {
key={item.token + '-collection-item'}
href={`/project/${projectRef}/logs/collections/${item.token}`}
>
- <div>{item.name}</div>
+ <div className="truncate">{item.name}</div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
@@ -221,8 +221,9 @@ export const WarehouseMenuItem = ({ item }: Props) => {
>
<div className="p-3 px-6 space-y-4">
<p className="text-sm text-foreground-light">
- Are you sure you want to delete the selected collection?
- <br /> This action cannot be undone.
+ All data in this collection will be deleted.
+ <br />
+ <div className="mt-2">This action cannot be undone.</div>
</p>
</div>
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx b/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx
index 163d60b401f..a1018adcc0d 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx
@@ -23,6 +23,7 @@ import FunctionInvocationSelectionRender from './LogSelectionRenderers/FunctionI
import FunctionLogsSelectionRender from './LogSelectionRenderers/FunctionLogsSelectionRender'
import type { LogData, LogsEndpointParams, QueryType } from './Logs.types'
import { isDefaultLogPreviewFormat, isUnixMicro, unixMicroToIsoTimestamp } from './Logs.utils'
+import { GenericSkeletonLoader } from 'ui-patterns'
export interface LogSelectionProps {
log: LogData | null
@@ -49,10 +50,11 @@ const LogSelection = ({
)
const [sql, setSql] = useState('')
+ const warehouseQueryEnabled = queryType === 'warehouse'
const {
refetch: refetchWarehouseData,
data: warehouseQueryData,
- isFetching: warehouseQueryFetching,
+ isLoading: warehouseQueryLoading,
} = useWarehouseQueryQuery(
{
ref: projectRef,
@@ -144,6 +146,13 @@ const LogSelection = ({
return JSON.stringify(fullLog || partialLog, null, 2)
}, [fullLog, partialLog, queryType])
+ const rawLog = useMemo(() => {
+ if (queryType === 'warehouse') {
+ return warehouseQueryData?.result[0]
+ }
+ return fullLog || partialLog
+ }, [queryType, warehouseQueryData, fullLog, partialLog])
+
return (
<div
className={cn(
@@ -210,9 +219,9 @@ const LogSelection = ({
</Button>
</TabsList_Shadcn_>
<div className="flex-grow">
- {isLoading || warehouseQueryFetching ? (
- <div className="py-44">
- <Loading />
+ {isLoading || (warehouseQueryEnabled && warehouseQueryLoading) ? (
+ <div className="p-4">
+ <GenericSkeletonLoader />
</div>
) : (
<>
@@ -220,12 +229,13 @@ const LogSelection = ({
<Formatter />
</TabsContent_Shadcn_>
<TabsContent_Shadcn_ value="raw">
+ {isLoading && 'Loading...'}
<CodeBlock
hideLineNumbers
language="json"
className="prose w-full pt-0 max-w-full border-none"
>
- {JSON.stringify(fullLog || partialLog, null, 2)}
+ {JSON.stringify(rawLog, null, 2)}
</CodeBlock>
</TabsContent_Shadcn_>
</>
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx b/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
index e89cae84b40..bb2b0e33270 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
@@ -130,7 +130,6 @@ const LogTable = ({
return <div className="flex items-center">{v}</div>
},
minWidth: 128,
- maxWidth: v === 'timestamp' ? 240 : 2400, // Without this, the column flickers on first render
}
return result
@@ -402,7 +401,7 @@ const LogTable = ({
renderers={{
renderRow: RowRenderer,
noRowsFallback: !isLoading ? (
- <div className="mx-auto flex h-full w-full items-center justify-center space-y-12 py-4 transition-all delay-200 duration-500">
+ <div className="mx-auto flex h-full items-center justify-center space-y-12 py-4 transition-all delay-200 duration-500">
{!error && renderNoResultAlert()}
{error && renderErrorAlert()}
</div>
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx b/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
index 89236427e6f..14e6a972a19 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
@@ -102,7 +102,10 @@ const LogsQueryPanel = ({
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button type="default" iconRight={<ChevronDown />}>
- Data source <span className="ml-2 font-mono opacity-50">{dataSource}</span>
+ Data source{' '}
+ <span className="ml-2 font-mono opacity-50">
+ {dataSource === 'warehouse' ? 'collections' : 'logs'}
+ </span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="start">
@@ -113,10 +116,10 @@ const LogsQueryPanel = ({
<DropdownMenuItemContent
name={
<span>
- Warehouse <Badge variant="warning">NEW</Badge>
+ Collections <Badge variant="warning">NEW</Badge>
</span>
}
- desc="Query your data warehouse collections"
+ desc="Query your collections"
/>
</DropdownMenuItem>
</DropdownMenuContent>
@@ -238,97 +241,93 @@ const LogsQueryPanel = ({
</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={<X 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={<BookOpen />}
- className="px-2"
- >
- <span>Field Reference</span>
- </Button>
- }
+ {dataSource === 'logs' && (
+ <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={<X />}
+ />
+ </div>
+ }
+ visible={showReference}
+ cancelText="Close"
+ onCancel={() => setShowReference(false)}
+ hideFooter
+ triggerElement={
+ <Button
+ asChild // ?: we don't want a button inside a button
+ type="text"
+ onClick={() => setShowReference(true)}
+ icon={<BookOpen />}
+ className="px-2"
>
- <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
- <ExternalLink
- size="14"
- 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"
+ <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
+ <ExternalLink
+ size="14"
+ 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"
>
- {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>
+ <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>
diff --git a/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx b/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
index 0f2158192b2..04be1d56724 100644
--- a/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
@@ -214,7 +214,7 @@ const PreviewFilterPanel = ({
<div className="flex items-center justify-center gap-x-2">
<Tooltip_Shadcn_ delayDuration={100}>
<TooltipTrigger_Shadcn_ asChild>
- <Button asChild className="px-1" type="default" icon={<Terminal />}>
+ <Button asChild className="px-1.5" type="default" icon={<Terminal />}>
<Link href={queryUrl} />
</Button>
</TooltipTrigger_Shadcn_>
diff --git a/apps/studio/components/interfaces/Settings/Logs/Warehouse.utils.ts b/apps/studio/components/interfaces/Settings/Logs/Warehouse.utils.ts
index a891844d514..fdb60183e09 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Warehouse.utils.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Warehouse.utils.ts
@@ -7,12 +7,20 @@ export type WarehouseQueryTemplate = {
export function createWarehouseQueryTemplates(
collections: { name: string }[]
): WarehouseQueryTemplate[] {
- return collections.map((collection) => ({
- query:
- 'select id, timestamp, event_message from `' +
- collection.name +
- '`\nwhere timestamp > timestamp_sub(current_timestamp(), interval 7 day)\norder by timestamp desc limit 10',
- name: `${collection.name}`,
- description: `Select last 10 events from ${collection.name} collection`,
- }))
+ return collections.flatMap((collection) => [
+ {
+ query: `select count(*) as event_count from \`${collection.name}\`
+where timestamp > timestamp_sub(current_timestamp(), interval 1 day)`,
+ name: `${collection.name} - Daily Event Count`,
+ description: `Count events in the last 24 hours from ${collection.name} collection`,
+ },
+ {
+ query: `select id, timestamp, event_message from \`${collection.name}\`
+ where timestamp > timestamp_sub(current_timestamp(), interval 1 day)
+ and event_message like '%YOUR_TEXT_HERE%'
+ order by timestamp desc limit 10`,
+ name: `${collection.name} - Filter by text`,
+ description: `Select last 10 events from ${collection.name} collection`,
+ },
+ ])
}
diff --git a/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx b/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
index e27e9bcc79f..8063866d5fc 100644
--- a/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
+++ b/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
@@ -46,11 +46,12 @@ const LogsLayout = ({ title, children }: PropsWithChildren<LogsLayoutProps>) =>
enabled: showWarehouse,
}
)
+ const collectionQueryEnabled = !!tenant
const { data: collections, isLoading: collectionsLoading } = useWarehouseCollectionsQuery(
{
projectRef,
},
- { enabled: !!tenant }
+ { enabled: collectionQueryEnabled }
)
const canUseLogsExplorer = useCheckPermissions(PermissionAction.ANALYTICS_READ, 'logflare')
@@ -87,7 +88,7 @@ const LogsLayout = ({ title, children }: PropsWithChildren<LogsLayoutProps>) =>
<Menu.Group
title={
<div>
- Warehouse Events
+ Collections
<Badge variant="warning" size="small" className="ml-2">
New
</Badge>
@@ -99,7 +100,7 @@ const LogsLayout = ({ title, children }: PropsWithChildren<LogsLayoutProps>) =>
<div className="space-y-1">
<CreateWarehouseCollectionModal />
<div className="pt-3">
- {collectionsLoading ? (
+ {collectionQueryEnabled && collectionsLoading ? (
<GenericSkeletonLoader />
) : (
collections?.map((item) => (
@@ -119,7 +120,7 @@ const LogsLayout = ({ title, children }: PropsWithChildren<LogsLayoutProps>) =>
<Link href={`/project/${ref}/settings/warehouse`}>
<Menu.Item rounded>
<div className="flex px-3 items-center justify-between">
- <p className="truncate">Warehouse Settings</p>
+ <p className="truncate">Analytics Settings</p>
<ArrowUpRight strokeWidth={1} className="h-4 w-4" />
</div>
</Menu.Item>
diff --git a/apps/studio/pages/project/[ref]/logs/explorer/index.tsx b/apps/studio/pages/project/[ref]/logs/explorer/index.tsx
index 2d45651735a..0e37034b135 100644
--- a/apps/studio/pages/project/[ref]/logs/explorer/index.tsx
+++ b/apps/studio/pages/project/[ref]/logs/explorer/index.tsx
@@ -141,8 +141,9 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
if (q) {
onSelectTemplate({
mode: 'custom',
- searchString: q as string,
+ searchString: q,
})
+ setWarehouseEditorValue(q)
}
}, [])
@@ -193,7 +194,7 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
const whQuery = warehouseEditorValue
if (!warehouseCollections?.length) {
- toast.error('You do not have any collections in your warehouse yet.')
+ toast.error('You do not have any collections yet.')
return
}
@@ -213,9 +214,7 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
const logsSourceExists = logsSources.find((source) => whQuery.includes(source))
if (logsSourceExists) {
- toast.error(
- 'Cannot query logs tables from a warehouse query. Please remove the logs table from the query.'
- )
+ toast.error('Cannot query logs tables from current query.')
return
}
diff --git a/apps/studio/pages/project/[ref]/settings/warehouse.tsx b/apps/studio/pages/project/[ref]/settings/warehouse.tsx
index e84d3bc9cfc..4fd0e7d1741 100644
--- a/apps/studio/pages/project/[ref]/settings/warehouse.tsx
+++ b/apps/studio/pages/project/[ref]/settings/warehouse.tsx
@@ -13,8 +13,8 @@ const WarehouseSettings: NextPageWithLayout = () => {
<>
<ScaffoldContainer>
<ScaffoldHeader>
- <ScaffoldTitle>Warehouse Settings</ScaffoldTitle>
- <ScaffoldDescription>Configure your warehouse settings</ScaffoldDescription>
+ <ScaffoldTitle>Analytics Settings</ScaffoldTitle>
+ <ScaffoldDescription>Configure your analytics settings</ScaffoldDescription>
</ScaffoldHeader>
</ScaffoldContainer>
<ScaffoldContainer className="flex flex-col gap-10" bottomPadding>
diff --git a/apps/studio/styles/react-data-grid-logs.scss b/apps/studio/styles/react-data-grid-logs.scss
index b97db2db7f3..936cc413c18 100644
--- a/apps/studio/styles/react-data-grid-logs.scss
+++ b/apps/studio/styles/react-data-grid-logs.scss
@@ -21,7 +21,7 @@
&.rdg-row--focused .rdg-cell,
&.rdg-row--focused .rdg-cell span {
- @apply text-foreground font-semibold #{!important};
+ @apply text-foreground #{!important};
}
}
}
diff --git a/packages/ui/src/components/CodeBlock/CodeBlock.tsx b/packages/ui/src/components/CodeBlock/CodeBlock.tsx
index f24f7be439a..1682f3eb6dc 100644
--- a/packages/ui/src/components/CodeBlock/CodeBlock.tsx
+++ b/packages/ui/src/components/CodeBlock/CodeBlock.tsx
@@ -51,8 +51,26 @@ export interface CodeBlockProps {
theme?: any
children?: string
renderer?: SyntaxHighlighterProps['renderer']
+ focusable?: boolean
}
+/**
+ * CodeBlock component for displaying syntax-highlighted code.
+ * @param {ReactNode} [props.title] - Optional title for the code block.
+ * @param {string} [props.language] - The programming language of the code.
+ * @param {number[]} [props.linesToHighlight=[]] - Array of line numbers to highlight.
+ * @param {boolean} [props.highlightBorder] - Whether to show a border on highlighted lines.
+ * @param {Object} [props.styleConfig] - Custom style configurations.
+ * @param {string} [props.className] - Additional CSS classes for the code block.
+ * @param {string} [props.wrapperClassName] - CSS classes for the wrapper div.
+ * @param {string} [props.value] - The code content as a string.
+ * @param {any} [props.theme] - Custom theme for syntax highlighting.
+ * @param {string} [props.children] - The code content as children.
+ * @param {boolean} [props.hideCopy=false] - Whether to hide the copy button.
+ * @param {boolean} [props.hideLineNumbers=false] - Whether to hide line numbers.
+ * @param {SyntaxHighlighterProps['renderer']} [props.renderer] - Custom renderer for syntax highlighting.
+ * @param {boolean} [props.focusable=true] - Whether the code block is focusable. When true, users can focus the code block to select text or use ⌘A (Cmd+A) to select all. This is so we don't need to load Monaco Editor.
+ */
export const CodeBlock = ({
title,
language,
@@ -67,6 +85,7 @@ export const CodeBlock = ({
hideCopy = false,
hideLineNumbers = false,
renderer,
+ focusable = true,
}: CodeBlockProps) => {
const { resolvedTheme } = useTheme()
const isDarkTheme = resolvedTheme?.includes('dark')!
@@ -135,7 +154,7 @@ export const CodeBlock = ({
// @ts-ignore
style={monokaiTheme}
className={cn(
- 'code-block border border-surface p-4 w-full !my-0 !bg-surface-100',
+ 'code-block border border-surface p-4 w-full !my-0 !bg-surface-100 outline-none focus:border-foreground-lighter/50',
`${!title ? '!rounded-md' : '!rounded-t-none !rounded-b-md'}`,
`${!showLineNumbers ? 'pl-6' : ''}`,
className
@@ -177,6 +196,11 @@ export const CodeBlock = ({
paddingBottom: '4px',
}}
renderer={renderer}
+ contentEditable={focusable}
+ onBeforeInput={(e: any) => {
+ e.preventDefault()
+ return false
+ }}
>
{codeValue}
</SyntaxHighlighter>