The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix edge functions logs refresh button (#35194)
Joshen Limf81387de90ba
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx b/apps/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsxindex 1f6f6221287..76f8b95560c 100644--- a/apps/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx+++ b/apps/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx@@ -18,7 +18,13 @@ import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'import { Button } from 'ui'import { LogsBarChart } from 'ui-patterns/LogsBarChart'import LogTable from './LogTable'-import { LOGS_TABLES, LOG_ROUTES_WITH_REPLICA_SUPPORT, LogsTableName } from './Logs.constants'+import { DatePickerValue } from './Logs.DatePickers'+import {+ LOGS_TABLES,+ LOG_ROUTES_WITH_REPLICA_SUPPORT,+ LogsTableName,+ PREVIEWER_DATEPICKER_HELPERS,+} from './Logs.constants'import type { Filters, LogSearchCallback, LogTemplate, QueryType } from './Logs.types'import { maybeShowUpgradePrompt } from './Logs.utils'import UpgradePrompt from './UpgradePrompt'@@ -54,17 +60,42 @@ export const LogsPreviewer = ({}: PropsWithChildren<LogsPreviewerProps>) => {const router = useRouter()const { db } = useParams()- const [showChart, setShowChart] = useState(true)-const organization = useSelectedOrganization()const state = useDatabaseSelectorStateSnapshot()++ const [showChart, setShowChart] = useState(true)+ const [selectedDatePickerValue, setSelectedDatePickerValue] = useState<DatePickerValue>(+ getDefaultDatePickerValue()+ )+const { search, setSearch, timestampStart, timestampEnd, setTimeRange, filters, setFilters } =useLogsUrlState()-const [selectedLogId, setSelectedLogId] = useSelectedLog()-const { data: databases, isSuccess } = useReadReplicasQuery({ projectRef })+ // TODO: Move this to useLogsUrlState to simplify LogsPreviewer. - Jordi+ function getDefaultDatePickerValue() {+ const iso_timestamp_start = router.query.iso_timestamp_start as string+ const iso_timestamp_end = router.query.iso_timestamp_end as string++ if (iso_timestamp_start && iso_timestamp_end) {+ return {+ to: iso_timestamp_end,+ from: iso_timestamp_start,+ text: `${dayjs(iso_timestamp_start).format('DD MMM, HH:mm')} - ${dayjs(iso_timestamp_end).format('DD MMM, HH:mm')}`,+ isHelper: false,+ }+ }++ const defaultDatePickerValue = PREVIEWER_DATEPICKER_HELPERS.find((x) => x.default)+ return {+ to: defaultDatePickerValue!.calcTo(),+ from: defaultDatePickerValue!.calcFrom(),+ text: defaultDatePickerValue!.text,+ isHelper: true,+ }+ }+const table = !tableName ? LOGS_TABLES[queryType] : tableNameconst {@@ -96,13 +127,18 @@ export const LogsPreviewer = ({setFilters({ ...filters, search_query: template.searchString })}- // [Joshen 180425] This logic here all seems unnecessary IMO? handleRefresh just should call refresh?+ // [Joshen] For helper date picker values, reset the timestamp start to prevent data caching+ // Since the helpers are "Last n minutes" -> hitting refresh, you'd expect to see the latest result+ // Whereas if a specific range is selected, you'd not expect new data to show upconst handleRefresh = () => {- if (timestampStart) {- const newTimestampStart = dayjs(timestampStart).toISOString()- setTimeRange(newTimestampStart, timestampEnd)- } else {- setTimeRange('', '')+ if (selectedDatePickerValue.isHelper) {+ const helper = PREVIEWER_DATEPICKER_HELPERS.find(+ (x) => x.text === selectedDatePickerValue.text+ )+ if (helper) {+ const newTimestampStart = helper.calcFrom()+ setTimeRange(newTimestampStart, timestampEnd)+ }}refresh()}@@ -180,6 +216,8 @@ export const LogsPreviewer = ({query: id !== projectRef ? { ...router.query, db: id } : params,})}}+ selectedDatePickerValue={selectedDatePickerValue}+ setSelectedDatePickerValue={setSelectedDatePickerValue}/>{children}<divdiff --git a/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx b/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsxindex fd76f15aaeb..292a316cd93 100644--- a/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx+++ b/apps/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx@@ -1,4 +1,3 @@-import dayjs from 'dayjs'import { Eye, EyeOff, RefreshCw, Search, Terminal, X } from 'lucide-react'import Link from 'next/link'import { useRouter } from 'next/router'@@ -42,6 +41,8 @@ interface PreviewFilterPanelProps {filters: FiltersonSelectedDatabaseChange: (id: string) => voidclassName?: string+ selectedDatePickerValue: DatePickerValue+ setSelectedDatePickerValue: (value: DatePickerValue) => void}/**@@ -64,6 +65,8 @@ const PreviewFilterPanel = ({table,onSelectedDatabaseChange,className,+ selectedDatePickerValue,+ setSelectedDatePickerValue,}: PreviewFilterPanelProps) => {const router = useRouter()const { ref } = useParams()@@ -79,30 +82,6 @@ const PreviewFilterPanel = ({const hasEdits = search !== defaultSearchValue- function getDefaultDatePickerValue() {- // if we have values in the URL, use them- const iso_timestamp_start = router.query.iso_timestamp_start as string- const iso_timestamp_end = router.query.iso_timestamp_end as string- if (iso_timestamp_start && iso_timestamp_end) {- return {- to: iso_timestamp_end,- from: iso_timestamp_start,- text: `${dayjs(iso_timestamp_start).format('DD MMM, HH:mm')} - ${dayjs(iso_timestamp_end).format('DD MMM, HH:mm')}`,- isHelper: false,- }- }- return {- to: PREVIEWER_DATEPICKER_HELPERS[2].calcTo(),- from: PREVIEWER_DATEPICKER_HELPERS[2].calcFrom(),- text: 'Last hour',- isHelper: true,- }- }-- const [selectedDatePickerValue, setSelectedDatePickerValue] = useState<DatePickerValue>(- getDefaultDatePickerValue()- )-const handleInputSearch = (query: string) => onSearch('search-input-change', { query })// Sync local state with provided default value