Skip to content

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

Swap PATCH content to PUT (#32950)

Joshen Limcedcc5315f51
diff --git a/apps/studio/components/interfaces/Reports/Reports.tsx b/apps/studio/components/interfaces/Reports/Reports.tsx
index fae083468f3..cbd696758a2 100644
--- a/apps/studio/components/interfaces/Reports/Reports.tsx
+++ b/apps/studio/components/interfaces/Reports/Reports.tsx
@@ -14,7 +14,7 @@ import NoPermission from 'components/ui/NoPermission'
import { DEFAULT_CHART_CONFIG } from 'components/ui/QueryBlock/QueryBlock'
import { AnalyticsInterval } from 'data/analytics/constants'
import { useContentQuery } from 'data/content/content-query'
-import { useContentUpdateMutation } from 'data/content/content-update-mutation'
+import { useContentUpsertMutation } from 'data/content/content-upsert-mutation'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { Metric, TIME_PERIODS_REPORTS } from 'lib/constants/metrics'
import { uuidv4 } from 'lib/helpers'
@@ -46,7 +46,7 @@ const Reports = () => {
projectRef: ref,
type: 'report',
})
- const { mutate: saveReport, isLoading: isSaving } = useContentUpdateMutation({
+ const { mutate: upsertContent, isLoading: isSaving } = useContentUpsertMutation({
onSuccess: () => {
setHasEdits(false)
toast.success('Successfully saved report!')
@@ -220,8 +220,12 @@ const Reports = () => {
// Updates the report and reloads the report again
const onSaveReport = async () => {
if (ref === undefined) return console.error('Project ref is required')
- if (id === undefined) return console.error('Report ID is required')
- saveReport({ projectRef: ref, id, type: 'report', content: config })
+ if (currentReport === undefined) return console.error('Report is required')
+ if (config === undefined) return console.error('Config is required')
+ upsertContent({
+ projectRef: ref,
+ payload: { ...currentReport, content: config },
+ })
}
useEffect(() => {
diff --git a/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx b/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
index 9684b7553ca..ad37109f140 100644
--- a/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
@@ -4,7 +4,10 @@ import { toast } from 'sonner'
import { useParams } from 'common'
import { useSqlTitleGenerateMutation } from 'data/ai/sql-title-mutation'
import { getContentById } from 'data/content/content-id-query'
-import { useContentUpdateMutation } from 'data/content/content-update-mutation'
+import {
+ UpsertContentPayload,
+ useContentUpsertMutation,
+} from 'data/content/content-upsert-mutation'
import { Snippet } from 'data/content/sql-folders-query'
import type { SqlSnippet } from 'data/content/sql-snippets-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
@@ -73,7 +76,7 @@ const RenameQueryModal = ({
return errors
}
- const { mutateAsync: updateContent } = useContentUpdateMutation()
+ const { mutateAsync: upsertContent } = useContentUpsertMutation()
const onSubmit = async (values: any, { setSubmitting }: any) => {
if (!ref) return console.error('Project ref is required')
@@ -90,20 +93,16 @@ const RenameQueryModal = ({
snapV2.addSnippet({ projectRef: ref, snippet: localSnippet })
}
- const updatedSnippet = await updateContent({
+ await upsertContent({
projectRef: ref,
- id,
- type: localSnippet.type,
- content: (localSnippet as any).content,
- name: nameInput,
- description: descriptionInput,
+ payload: {
+ ...localSnippet,
+ name: nameInput,
+ description: descriptionInput,
+ } as UpsertContentPayload,
})
- snapV2.renameSnippet({
- id,
- name: updatedSnippet.name,
- description: updatedSnippet.description,
- })
+ snapV2.renameSnippet({ id, name: nameInput, description: descriptionInput })
toast.success('Successfully renamed snippet!')
if (onComplete) onComplete()
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx b/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
index c7c4cf89dbc..dbf6f674b69 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
@@ -2,10 +2,10 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { IS_PLATFORM } from 'common'
import { isEqual } from 'lodash'
import { ChevronDown, Clipboard, Download, Eye, EyeOff, Play } from 'lucide-react'
+import Papa from 'papaparse'
import { Key, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import DataGrid, { Column, RenderRowProps, Row } from 'react-data-grid'
import { toast } from 'sonner'
-import Papa from 'papaparse'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import CSVButton from 'components/ui/CSVButton'
@@ -14,6 +14,7 @@ import { copyToClipboard } from 'lib/helpers'
import { useProfile } from 'lib/profile'
import { Item, Menu, useContextMenu } from 'react-contexify'
import { createPortal } from 'react-dom'
+import { ResponseError } from 'types'
import {
Button,
DropdownMenu,
@@ -37,13 +38,13 @@ import { isDefaultLogPreviewFormat } from './Logs.utils'
import { DefaultErrorRenderer } from './LogsErrorRenderers/DefaultErrorRenderer'
import ResourcesExceededErrorRenderer from './LogsErrorRenderers/ResourcesExceededErrorRenderer'
import { LogsTableEmptyState } from './LogsTableEmptyState'
-import { ResponseError } from 'types'
interface Props {
data?: LogData[]
onHistogramToggle?: () => void
isHistogramShowing?: boolean
isLoading?: boolean
+ isSaving?: boolean
error?: LogQueryError | null
showDownload?: boolean
queryType?: QueryType
@@ -75,6 +76,7 @@ const LogTable = ({
onHistogramToggle,
isHistogramShowing,
isLoading,
+ isSaving,
error,
projectRef,
onRun,
@@ -308,6 +310,7 @@ const LogTable = ({
<ButtonTooltip
type="default"
onClick={onSave}
+ loading={isSaving}
disabled={!canCreateLogQuery || !hasEditorValue}
tooltip={{
content: {
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx b/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
index a9bb4992f9b..69509b6e587 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
@@ -36,19 +36,15 @@ export type SourceType = 'logs' | 'warehouse'
export interface LogsQueryPanelProps {
templates?: LogTemplate[]
warehouseTemplates?: WarehouseQueryTemplate[]
- onSelectTemplate: (template: LogTemplate) => void
- onSelectWarehouseTemplate: (template: WarehouseQueryTemplate) => void
- onSelectSource: (source: string) => void
- onClear: () => void
- onSave?: () => void
- hasEditorValue: boolean
- isLoading: boolean
- onDateChange: React.ComponentProps<typeof DatePickers>['onChange']
- defaultTo: string
defaultFrom: string
+ defaultTo: string
warnings: LogsWarning[]
warehouseCollections: WarehouseCollection[]
dataSource: SourceType
+ onSelectTemplate: (template: LogTemplate) => void
+ onSelectWarehouseTemplate: (template: WarehouseQueryTemplate) => void
+ onSelectSource: (source: string) => void
+ onDateChange: React.ComponentProps<typeof DatePickers>['onChange']
onDataSourceChange: (sourceType: SourceType) => void
}
@@ -64,15 +60,15 @@ function DropdownMenuItemContent({ name, desc }: { name: ReactNode; desc?: strin
const LogsQueryPanel = ({
templates = [],
warehouseTemplates = [],
- onSelectTemplate,
- onSelectWarehouseTemplate,
- onSelectSource,
defaultFrom,
defaultTo,
- onDateChange,
warnings,
warehouseCollections,
dataSource,
+ onSelectTemplate,
+ onSelectWarehouseTemplate,
+ onSelectSource,
+ onDateChange,
onDataSourceChange,
}: LogsQueryPanelProps) => {
const [showReference, setShowReference] = useState(false)
diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index a78a22c387f..5e20b846c21 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -5,11 +5,9 @@ import { useState } from 'react'
import { toast } from 'sonner'
import { useParams } from 'common'
-import { untitledSnippetTitle } from 'components/interfaces/SQLEditor/SQLEditor.constants'
-import { createSqlSnippetSkeletonV2 } from 'components/interfaces/SQLEditor/SQLEditor.utils'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { useLocalStorage } from 'hooks/misc/useLocalStorage'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
-import { uuidv4 } from 'lib/helpers'
import { useProfile } from 'lib/profile'
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
import {
@@ -27,7 +25,6 @@ import {
InnerSideMenuItem,
} from 'ui-patterns/InnerSideMenu'
import { SQLEditorNav as SQLEditorNavV2 } from './SQLEditorNavV2/SQLEditorNav'
-import { useLocalStorage } from 'hooks/misc/useLocalStorage'
interface SQLEditorMenuProps {
onViewOngoingQueries: () => void
diff --git a/apps/studio/data/content/content-update-mutation.ts b/apps/studio/data/content/content-update-mutation.ts
deleted file mode 100644
index e6b871acb3e..00000000000
--- a/apps/studio/data/content/content-update-mutation.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
-import { toast } from 'sonner'
-
-import { handleError, patch } from 'data/fetchers'
-import type { ResponseError } from 'types'
-import { contentKeys } from './keys'
-import { ContentType } from './content-query'
-
-type UpdateContentVariables = {
- projectRef: string
- id: string
- type: ContentType
- content: any
- name?: string
- description?: string
-}
-
-export async function updateContent(
- { projectRef, id, type, content, name, description }: UpdateContentVariables,
- signal?: AbortSignal
-) {
- const { data, error } = await patch('/platform/projects/{ref}/content', {
- params: {
- path: { ref: projectRef },
- query: { id },
- },
- body: { id, type, content, name, description },
- signal,
- })
-
- if (error) handleError(error)
- return data[0]
-}
-
-type UpdateContentData = Awaited<ReturnType<typeof updateContent>>
-
-export const useContentUpdateMutation = ({
- onSuccess,
- onError,
- ...options
-}: Omit<
- UseMutationOptions<UpdateContentData, ResponseError, UpdateContentVariables>,
- 'mutationFn'
-> = {}) => {
- const queryClient = useQueryClient()
-
- return useMutation<UpdateContentData, ResponseError, UpdateContentVariables>(
- (args) => updateContent(args),
- {
- async onSuccess(data, variables, context) {
- const { projectRef } = variables
- await queryClient.invalidateQueries(contentKeys.allContentLists(projectRef))
- await onSuccess?.(data, variables, context)
- },
- async onError(data, variables, context) {
- if (onError === undefined) {
- toast.error(`Failed to update content: ${data.message}`)
- } else {
- onError(data, variables, context)
- }
- },
- ...options,
- }
- )
-}
diff --git a/apps/studio/pages/project/[ref]/logs/explorer/index.tsx b/apps/studio/pages/project/[ref]/logs/explorer/index.tsx
index d06f6fabd4b..587768ab428 100644
--- a/apps/studio/pages/project/[ref]/logs/explorer/index.tsx
+++ b/apps/studio/pages/project/[ref]/logs/explorer/index.tsx
@@ -40,16 +40,19 @@ import LoadingOpacity from 'components/ui/LoadingOpacity'
import ShimmerLine from 'components/ui/ShimmerLine'
import { useWarehouseCollectionsQuery } from 'data/analytics/warehouse-collections-query'
import { useWarehouseQueryQuery } from 'data/analytics/warehouse-query'
-import { useContentInsertMutation } from 'data/content/content-insert-mutation'
+import { useContentQuery } from 'data/content/content-query'
+import {
+ UpsertContentPayload,
+ useContentUpsertMutation,
+} from 'data/content/content-upsert-mutation'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import useLogsQuery from 'hooks/analytics/useLogsQuery'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useUpgradePrompt } from 'hooks/misc/useUpgradePrompt'
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
import { uuidv4 } from 'lib/helpers'
+import { useProfile } from 'lib/profile'
import type { LogSqlSnippets, NextPageWithLayout } from 'types'
-import { useContentUpdateMutation } from 'data/content/content-update-mutation'
-import { useSelectedLog } from 'hooks/analytics/useSelectedLog'
const PLACEHOLDER_WAREHOUSE_QUERY =
'-- Fetch the last 10 logs in the last 7 days \nselect id, timestamp, event_message from `COLLECTION_NAME` \nwhere timestamp > timestamp_sub(current_timestamp(), interval 7 day) \norder by timestamp desc limit 10'
@@ -64,9 +67,11 @@ const PLACEHOLDER_QUERY = IS_PLATFORM ? PLATFORM_PLACEHOLDER_QUERY : LOCAL_PLACE
export const LogsExplorerPage: NextPageWithLayout = () => {
useEditorHints()
const router = useRouter()
- const { ref, q, ite, its } = useParams()
+ const { profile } = useProfile()
+ const { ref, q, ite, its, queryId, source: routerSource } = useParams()
const projectRef = ref as string
const organization = useSelectedOrganization()
+
const [editorId, setEditorId] = useState<string>(uuidv4())
const [warehouseEditorId, setWarehouseEditorId] = useState<string>(uuidv4())
const [editorValue, setEditorValue] = useState<string>(PLACEHOLDER_QUERY)
@@ -75,9 +80,19 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
)
const [saveModalOpen, setSaveModalOpen] = useState<boolean>(false)
const [warnings, setWarnings] = useState<LogsWarning[]>([])
+ const [sourceType, setSourceType] = useState<SourceType>((routerSource as SourceType) || 'logs')
+ const [selectedLog, setSelectedLog] = useState<any>(null)
- const routerSource = router.query.source as SourceType
- const [sourceType, setSourceType] = useState<SourceType>(routerSource || 'logs')
+ const [recentLogs, setRecentLogs] = useLocalStorage<LogSqlSnippets.Content[]>(
+ `project-content-${projectRef}-recent-log-sql`,
+ []
+ )
+
+ const { data: content } = useContentQuery({
+ projectRef: ref,
+ type: 'log_sql',
+ })
+ const query = content?.content.find((x) => x.id === queryId)
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
const {
@@ -108,22 +123,32 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
enabled: false,
}
)
-
- useEffect(() => {
- if (warehouseError) {
- toast.error(warehouseError.message)
- }
- }, [warehouseError])
-
+ const results = sourceType === 'warehouse' ? warehouseResults?.result : logData
const isLoading = logsLoading || warehouseFetching
- const [recentLogs, setRecentLogs] = useLocalStorage<LogSqlSnippets.Content[]>(
- `project-content-${projectRef}-recent-log-sql`,
- []
- )
-
const { data: warehouseCollections } = useWarehouseCollectionsQuery({ projectRef })
+ const { mutate: upsertContent, isLoading: isUpsertingContent } = useContentUpsertMutation({
+ onError: (e) => {
+ const error = e as { message: string }
+ console.error(error)
+ setSaveModalOpen(false)
+ if (queryId) {
+ toast.error(`Failed to update query: ${error.message}`)
+ } else {
+ toast.error(`Failed to save query: ${error.message}`)
+ }
+ },
+ onSuccess: (_data, vars) => {
+ setSaveModalOpen(false)
+ if (queryId) {
+ toast.success(`Updated "${vars.payload.name}" log query`)
+ } else {
+ toast.success(`Saved "${vars.payload.name}" log query`)
+ }
+ },
+ })
+
const addRecentLogSqlSnippet = (snippet: Partial<LogSqlSnippets.Content>) => {
const defaults: LogSqlSnippets.Content = {
schema_version: '1',
@@ -138,42 +163,6 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
params.iso_timestamp_start as string
)
- useEffect(() => {
- // on mount, set initial values
- if (q) {
- onSelectTemplate({
- mode: 'custom',
- searchString: q,
- })
- setWarehouseEditorValue(q)
- }
- }, [q])
-
- useEffect(() => {
- let newWarnings = []
- const start = params.iso_timestamp_start ? dayjs(params.iso_timestamp_start) : dayjs()
- const end = params.iso_timestamp_end ? dayjs(params.iso_timestamp_end) : dayjs()
- const daysDiff = Math.abs(start.diff(end, 'days'))
- if (
- editorValue &&
- !editorValue.includes('limit') &&
- daysDiff > LOGS_LARGE_DATE_RANGE_DAYS_THRESHOLD
- ) {
- newWarnings.push({ text: 'When querying large date ranges, include a LIMIT clause.' })
- }
- setWarnings(newWarnings)
- }, [editorValue, params.iso_timestamp_start, params.iso_timestamp_end])
-
- // Show the prompt on page load based on query params
- useEffect(() => {
- if (its) {
- const shouldShowUpgradePrompt = maybeShowUpgradePrompt(its as string, subscription?.plan?.id)
- if (shouldShowUpgradePrompt) {
- setShowUpgradePrompt(!showUpgradePrompt)
- }
- }
- }, [its, subscription])
-
const onSelectTemplate = (template: LogTemplate) => {
setEditorValue(template.searchString)
changeQuery(template.searchString)
@@ -216,16 +205,14 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
const logsSourceExists = logsSources.find((source) => whQuery.includes(source))
if (logsSourceExists) {
- toast.error('Cannot query logs tables from current query.')
- return
+ return toast.error('Cannot query logs tables from current query.')
}
runWarehouseQuery()
- router.push({
+ return router.push({
pathname: router.pathname,
query: { ...router.query, q: query },
})
- return
}
changeQuery(query)
@@ -237,20 +224,10 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
addRecentLogSqlSnippet({ sql: query })
}
- const handleClear = () => {
- setEditorValue('')
- setEditorId(uuidv4())
- setWarehouseEditorId(uuidv4())
- changeQuery('')
- }
-
const handleInsertSource = (source: string) => {
if (sourceType === 'warehouse') {
//TODO: Only one collection can be queried at a time, we need to replace the current collection from the query for the new one
-
- setWarehouseEditorId(uuidv4())
-
- return
+ return setWarehouseEditorId(uuidv4())
}
setEditorValue((prev) => {
@@ -261,16 +238,44 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
setEditorId(uuidv4())
}
+ const handleCreateQuery = async (values: any, { setSubmitting }: any) => {
+ if (!projectRef) return console.error('Project ref is required')
+ if (!profile) return console.error('Profile is required')
+ setSubmitting(true)
+
+ const id = uuidv4()
+ const payload: UpsertContentPayload = {
+ id,
+ name: values.name,
+ description: values.description || '',
+ type: 'log_sql' as const,
+ content: {
+ content_id: editorId,
+ sql: editorValue,
+ schema_version: '1',
+ favorite: false,
+ } as LogSqlSnippets.Content,
+ owner_id: profile.id,
+ visibility: 'user' as const,
+ }
+ upsertContent(
+ { projectRef, payload },
+ {
+ onSuccess: () => router.push(`/project/${projectRef}/logs/explorer?queryId=${id}`),
+ }
+ )
+ }
+
function handleOnSave() {
+ if (!projectRef) return console.error('Project ref is required')
+
// if we have a queryId, we are editing a saved query
- const queryId = router.query.queryId as string
- if (queryId) {
- updateContent({
+ if (queryId && query) {
+ upsertContent({
projectRef: projectRef!,
- id: queryId,
- type: 'log_sql',
- content: {
- sql: editorValue,
+ payload: {
+ ...query,
+ content: { ...(query.content as LogSqlSnippets.Content), sql: editorValue },
},
})
@@ -298,34 +303,45 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
}
}
- const { isLoading: isSubmitting, mutate: createContent } = useContentInsertMutation({
- onError: (e) => {
- const error = e as { message: string }
- console.error(error)
- setSaveModalOpen(false)
- toast.error(`Failed to save query: ${error.message}`)
- },
- onSuccess: (values) => {
- setSaveModalOpen(false)
- toast.success(`Saved "${values.name}" log query`)
- },
- })
+ useEffect(() => {
+ if (warehouseError) toast.error(warehouseError.message)
+ }, [warehouseError])
- const { mutate: updateContent } = useContentUpdateMutation({
- onError: (e) => {
- const error = e as { message: string }
- console.error(error)
- setSaveModalOpen(false)
- toast.error(`Failed to update query: ${error.message}`)
- },
- onSuccess: (values) => {
- setSaveModalOpen(false)
- toast.success(`Updated "${values.name}" log query`)
- },
- })
+ useEffect(() => {
+ // on mount, set initial values
+ if (q) {
+ onSelectTemplate({
+ mode: 'custom',
+ searchString: q,
+ })
+ setWarehouseEditorValue(q)
+ }
+ }, [q])
- const [selectedLog, setSelectedLog] = useState<any>(null)
- const results = sourceType === 'warehouse' ? warehouseResults?.result : logData
+ useEffect(() => {
+ let newWarnings = []
+ const start = params.iso_timestamp_start ? dayjs(params.iso_timestamp_start) : dayjs()
+ const end = params.iso_timestamp_end ? dayjs(params.iso_timestamp_end) : dayjs()
+ const daysDiff = Math.abs(start.diff(end, 'days'))
+ if (
+ editorValue &&
+ !editorValue.includes('limit') &&
+ daysDiff > LOGS_LARGE_DATE_RANGE_DAYS_THRESHOLD
+ ) {
+ newWarnings.push({ text: 'When querying large date ranges, include a LIMIT clause.' })
+ }
+ setWarnings(newWarnings)
+ }, [editorValue, params.iso_timestamp_start, params.iso_timestamp_end])
+
+ // Show the prompt on page load based on query params
+ useEffect(() => {
+ if (its) {
+ const shouldShowUpgradePrompt = maybeShowUpgradePrompt(its as string, subscription?.plan?.id)
+ if (shouldShowUpgradePrompt) {
+ setShowUpgradePrompt(!showUpgradePrompt)
+ }
+ }
+ }, [its, subscription])
return (
<div className="w-full h-full mx-auto">
@@ -340,8 +356,6 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
defaultTo={params.iso_timestamp_end || ''}
onDateChange={handleDateChange}
onSelectSource={handleInsertSource}
- onClear={handleClear}
- hasEditorValue={Boolean(editorValue)}
templates={TEMPLATES.filter((template) => template.mode === 'custom')}
warehouseCollections={warehouseCollections || []}
onSelectTemplate={onSelectTemplate}
@@ -350,8 +364,6 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
setWarehouseEditorValue(template.query)
setWarehouseEditorId(uuidv4())
}}
- onSave={handleOnSave}
- isLoading={isLoading}
warnings={warnings}
dataSource={sourceType}
onDataSourceChange={(srcType) => {
@@ -386,6 +398,7 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
<ResizablePanel collapsible minSize={5} className="overflow-auto">
<LoadingOpacity active={isLoading}>
<LogTable
+ isSaving={isUpsertingContent}
showHistogramToggle={false}
onRun={handleRun}
onSave={handleOnSave}
@@ -416,25 +429,7 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
name: '',
desdcription: '',
}}
- onSubmit={async (values: any, { setSubmitting }: any) => {
- setSubmitting(true)
-
- const payload = {
- id: uuidv4(),
- name: values.name,
- description: values.description || '',
- type: 'log_sql' as const,
- content: {
- content_id: editorId,
- sql: editorValue,
- schema_version: '1',
- favorite: false,
- },
- visibility: 'user' as const,
- }
-
- createContent({ projectRef: projectRef!, payload })
- }}
+ onSubmit={handleCreateQuery}
>
{() => (
<>
@@ -457,8 +452,8 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
</Button>
<Button
size="tiny"
- loading={isSubmitting}
- disabled={isSubmitting}
+ loading={isUpsertingContent}
+ disabled={isUpsertingContent}
htmlType="submit"
>
Save
diff --git a/apps/studio/pages/project/[ref]/logs/explorer/saved.tsx b/apps/studio/pages/project/[ref]/logs/explorer/saved.tsx
index 0c4e52837f0..5f772d240d7 100644
--- a/apps/studio/pages/project/[ref]/logs/explorer/saved.tsx
+++ b/apps/studio/pages/project/[ref]/logs/explorer/saved.tsx
@@ -10,6 +10,7 @@ import { useContentQuery } from 'data/content/content-query'
import type { NextPageWithLayout } from 'types'
import { Loading } from 'ui'
+// [Joshen] This page looks like its not longer in use from a UI POV - double checking and deprecate + add redirects
export const LogsSavedPage: NextPageWithLayout = () => {
const { ref } = useParams()
const { data, isLoading } = useContentQuery({
diff --git a/apps/studio/tests/pages/projects/LogsQueryPanel.test.tsx b/apps/studio/tests/pages/projects/LogsQueryPanel.test.tsx
index c6b1138b9bd..df741c9a2e6 100644
--- a/apps/studio/tests/pages/projects/LogsQueryPanel.test.tsx
+++ b/apps/studio/tests/pages/projects/LogsQueryPanel.test.tsx
@@ -1,23 +1,18 @@
import { screen } from '@testing-library/react'
-import { expect, test, vi } from 'vitest'
+import { expect, test } from 'vitest'
import LogsQueryPanel from 'components/interfaces/Settings/Logs/LogsQueryPanel'
import { render } from 'tests/helpers'
test('run and clear', async () => {
- const mockRun = vi.fn()
- const mockClear = vi.fn()
render(
<LogsQueryPanel
defaultFrom=""
defaultTo=""
- isLoading={false}
onDateChange={() => {}}
onSelectSource={() => {}}
onSelectTemplate={() => {}}
warnings={[]}
- onClear={mockClear}
- hasEditorValue
warehouseCollections={[]}
dataSource="logs"
onDataSourceChange={() => {}}