The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: copy button for log selection
TzeYiingadc49fec0e34
diff --git a/studio/components/interfaces/Settings/Logs/LogSelection.tsx b/studio/components/interfaces/Settings/Logs/LogSelection.tsxindex 01cc5473042..b814789d926 100644--- a/studio/components/interfaces/Settings/Logs/LogSelection.tsx+++ b/studio/components/interfaces/Settings/Logs/LogSelection.tsx@@ -1,5 +1,5 @@import { FC } from 'react'-import { IconX } from 'ui'+import { Button, Divider, IconX } from 'ui'import { LogData, QueryType } from './Logs.types'@@ -9,9 +9,15 @@ import FunctionInvocationSelectionRender from './LogSelectionRenderers/FunctionIimport FunctionLogsSelectionRender from './LogSelectionRenderers/FunctionLogsSelectionRender'import DefaultExplorerSelectionRenderer from './LogSelectionRenderers/DefaultExplorerSelectionRenderer'import DefaultPreviewSelectionRenderer from './LogSelectionRenderers/DefaultPreviewSelectionRenderer'-import { isDefaultLogPreviewFormat, LogsEndpointParams } from '.'+import {+ isDefaultLogPreviewFormat,+ isUnixMicro,+ LogsEndpointParams,+ unixMicroToIsoTimestamp,+} from '.'import useSingleLog from 'hooks/analytics/useSingleLog'import Connecting from 'components/ui/Loading/Loading'+import CopyButton from 'components/ui/CopyButton'export interface LogSelectionProps {log: LogData | null@@ -64,6 +70,23 @@ const LogSelection: FC<LogSelectionProps> = ({}}+ const selectionText = () => {+ if (!fullLog) return ''+ if (queryType) {+ return `Log ID+${fullLog.id}\n+Log Timestamp (UTC)+${isUnixMicro(fullLog.timestamp) ? unixMicroToIsoTimestamp(fullLog.timestamp) : fullLog.timestamp}\n+Log Event Message+${fullLog.event_message}\n+Log Metadata+${JSON.stringify(fullLog.metadata, null, 2)}+`+ }++ return JSON.stringify(fullLog, null, 2)+ }+return (<divclassName={[@@ -123,22 +146,22 @@ const LogSelection: FC<LogSelectionProps> = ({</div></div></div>- <div- className="- relative- h-px- flex-grow- bg-scale-300- "- >- <div- className="absolute top-6 right-6 cursor-pointer text-scale-900 transition hover:text-scale-1200"- onClick={onClose}- >- <IconX size={14} strokeWidth={2} />+ <div className="relative h-px flex-grow bg-scale-300">+ <div className="pt-4 px-4 flex flex-col gap-4">+ <div className="flex flex-row justify-between items-center">+ <CopyButton text={selectionText()} type="default" />+ <Button+ type="text"+ className="cursor-pointer transition hover:text-scale-1200 h-8 w-8 px-0 py-0 flex items-center justify-center"+ onClick={onClose}+ >+ <IconX size={14} strokeWidth={2} className="text-scale-900" />+ </Button>+ </div>+ <div className="h-px w-full bg-scale-600 rounded " /></div>{isLoading && <Connecting />}- <div className="flex flex-col space-y-6 bg-scale-300 py-8">+ <div className="flex flex-col space-y-6 bg-scale-300 py-4">{!isLoading && <Formatter />}</div></div>diff --git a/studio/components/ui/CopyButton.tsx b/studio/components/ui/CopyButton.tsxnew file mode 100644index 00000000000..294a0cdb179--- /dev/null+++ b/studio/components/ui/CopyButton.tsx@@ -0,0 +1,32 @@+import { Button, ButtonProps } from 'ui'+import { copyToClipboard } from 'lib/helpers'+import { IconClipboard } from 'ui'+import { useEffect, useState } from 'react'++export interface CopyButtonProps extends ButtonProps {+ text: string+}+const CopyButton: React.FC<CopyButtonProps> = ({ text, children, onClick, ...props }) => {+ const [showCopied, setShowCopied] = useState(false)++ useEffect(() => {+ if (!showCopied) return+ const timer = setTimeout(() => setShowCopied(false), 2000)+ return () => clearTimeout(timer)+ }, [showCopied])++ return (+ <Button+ onClick={(e) => {+ setShowCopied(true)+ copyToClipboard(text)+ onClick?.(e)+ }}+ icon={<IconClipboard size="tiny" />}+ {...props}+ >+ {children ?? (showCopied ? 'Copied' : 'Copy')}+ </Button>+ )+}+export default CopyButtondiff --git a/studio/tests/components/CopyButton.test.tsx b/studio/tests/components/CopyButton.test.tsxnew file mode 100644index 00000000000..d8db3fc667e--- /dev/null+++ b/studio/tests/components/CopyButton.test.tsx@@ -0,0 +1,12 @@+import { screen } from '@testing-library/dom'+import userEvent from '@testing-library/user-event'+import CopyButton from 'components/ui/CopyButton'+import { render } from 'tests/helpers'++test('shows copied text', async () => {+ const callback = jest.fn()+ render(<CopyButton text="some text" onClick={callback} />)+ userEvent.click(await screen.findByText('Copy'))+ await screen.findByText('Copied')+ expect(callback).toBeCalled()+})diff --git a/studio/tests/pages/projects/LogTable.test.js b/studio/tests/pages/projects/LogTable.test.jsindex 804bfdbe685..94624e0b891 100644--- a/studio/tests/pages/projects/LogTable.test.js+++ b/studio/tests/pages/projects/LogTable.test.js@@ -23,6 +23,10 @@ test('can display log data', async () => {userEvent.click(row)await screen.findByText(/my_key/)await screen.findByText(/something_value/)++ // render copy button+ userEvent.click(await screen.findByText(/Copy/))+ await screen.findByText(/Copied/)})test('dedupes log lines with exact id', async () => {