The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: Added date range picker warning, added stricter typings for datepicker callbacks
TzeYiing8a462028ec64
diff --git a/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx b/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsxindex caedcc44732..b0316e2cf7e 100644--- a/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx+++ b/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx@@ -1,13 +1,13 @@-import { Button, Dropdown, IconClock } from '@supabase/ui'+import { Alert, Button, Dropdown, IconClock } from '@supabase/ui'import { DatePicker } from 'components/ui/DatePicker'+import dayjs from 'dayjs'import { useEffect, useState } from 'react'import { DatetimeHelper, getDefaultHelper } from '.'-type ToFrom = { to: string; from: string }interface Props {to: stringfrom: string- onChange: ({ to, from }: ToFrom) => void+ onChange: React.ComponentProps<typeof DatePicker>["onChange"]helpers: DatetimeHelper[]}const DatePickers: React.FC<Props> = ({ to, from, onChange, helpers }) => {@@ -67,12 +67,21 @@ const DatePickers: React.FC<Props> = ({ to, from, onChange, helpers }) => {<DatePickertriggerButtonClassName="rounded-l-none"triggerButtonType={selectedHelper ? 'default' : 'secondary'}- onChange={(value: ToFrom) => {+ onChange={(value) => {setHelperValue('')if (onChange) onChange(value)}}to={!helperValue ? to : undefined}from={!helperValue ? from : undefined}+ renderFooter={({ to, from }) => {+ if (to && from && Math.abs(dayjs(from).diff(dayjs(to), 'day')) > 50) {+ return (+ <Alert title="Large date range detected" variant="warning" className="mx-3 pl-2 pr-2 pt-2 pb-2">+ Large ranges may result in memory errors for big projects.+ </Alert>+ )+ }+ }}/></div>)diff --git a/studio/components/interfaces/Settings/Logs/Logs.types.ts b/studio/components/interfaces/Settings/Logs/Logs.types.tsindex 4ea671797b3..0a20cdcf132 100644--- a/studio/components/interfaces/Settings/Logs/Logs.types.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.types.ts@@ -1,13 +1,14 @@interface Metadata {[key: string]: string | number | Object | Object[]}-export type LogSearchCallback = (filters: {- query: string- to?: string- from?: string- fromMicro?: number- toMicro?: number-}) => void++export type DatePickerToFrom = { to: string | null; from: string | null }++export type LogSearchCallback = (+ filters: {+ query: string+ } & DatePickerToFrom+) => voidexport interface LogsEndpointParams {// project refdiff --git a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsxindex 4088e86e1e9..1c857fc7324 100644--- a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx+++ b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx@@ -83,8 +83,8 @@ export const LogsPreviewer: React.FC<Props> = ({})}- const handleSearch: LogSearchCallback = async ({ query = '', to = '', from = '' }) => {- setParams((prev) => ({ ...prev, iso_timestamp_start: from, iso_timestamp_end: to }))+ const handleSearch: LogSearchCallback = async ({ query = '', to, from }) => {+ setParams((prev) => ({ ...prev, iso_timestamp_start: from || '', iso_timestamp_end: to || '' }))setFilters((prev) => ({ ...prev, search_query: query }))router.push({pathname: router.pathname,@@ -141,7 +141,7 @@ export const LogsPreviewer: React.FC<Props> = ({data={!isLoading ? logData : undefined}onBarClick={(timestampMicro) => {const to = unixMicroToIsoTimestamp(timestampMicro)- handleSearch({ query: filters.search_query as string, to })+ handleSearch({ query: filters.search_query as string, to, from: null })}}/>)}diff --git a/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx b/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsxindex 25f1a7d1fc7..297ce0bbdd4 100644--- a/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx+++ b/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx@@ -1,6 +1,5 @@import { Button, Dropdown, Typography, IconChevronDown, IconPlay } from '@supabase/ui'import Flag from 'components/ui/Flag/Flag'-import dayjs from 'dayjs'import { EXPLORER_DATEPICKER_HELPERS, LogsTableName, LOGS_SOURCE_DESCRIPTION, LogTemplate } from '.'import DatePickers from './Logs.DatePickers'interface Props {@@ -12,7 +11,7 @@ interface Props {onSave?: () => voidhasEditorValue: booleanisLoading: boolean- onDateChange: (time: { to: string; from: string }) => void+ onDateChange: React.ComponentProps<typeof DatePickers>['onChange']defaultTo: stringdefaultFrom: string}diff --git a/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx b/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsxindex ee26120b1e1..ccb80f13030 100644--- a/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx+++ b/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx@@ -101,9 +101,8 @@ const PreviewFilterPanel: FC<Props> = ({Refresh</Button>)-- const handleSearch = (partial: Partial<{ query: string; to: string; from: string }>) =>- onSearch({ query: search, ...partial })+ const handleSearch = (partial: Partial<Parameters<LogSearchCallback>[0]>) =>+ onSearch({ query: search, to: partial?.to || null, from: partial?.from || null })return (<div@@ -147,9 +146,7 @@ const PreviewFilterPanel: FC<Props> = ({</form><DatePickers- onChange={async (e: { to: string; from: string }) => {- handleSearch(e)- }}+ onChange={handleSearch}to={defaultToValue}from={defaultFromValue}helpers={PREVIEWER_DATEPICKER_HELPERS}diff --git a/studio/components/ui/DatePicker/DatePicker.tsx b/studio/components/ui/DatePicker/DatePicker.tsxindex 3b53c88c482..cb32a0f8d68 100644--- a/studio/components/ui/DatePicker/DatePicker.tsx+++ b/studio/components/ui/DatePicker/DatePicker.tsx@@ -1,9 +1,5 @@-import React, { useState, forwardRef, useEffect } from 'react'-+import React, { useState, useEffect } from 'react'import DatePicker from 'react-datepicker'--// import dayjs from 'dayjs'-import {Button,Popover,@@ -11,40 +7,30 @@ import {IconChevronRight,IconArrowRight,IconCalendar,- IconGlobe,- Input,- Toggle,- Select,} from '@supabase/ui'import { format } from 'date-fns'-import TimeSplitInput from './TimeSplitInput'-// import DateSplitInput from './DateSplitInput'-import DividerSlash from './DividerSlash'-import dayjs from 'dayjs'import { ButtonProps } from '@supabase/ui/dist/cjs/components/Button/Button'+import { DatePickerToFrom } from 'components/interfaces/Settings/Logs'var utc = require('dayjs/plugin/utc')var timezone = require('dayjs/plugin/timezone') // dependent on utc plugin-dayjs.extend(utc)dayjs.extend(timezone)-interface RootProps {- onChange?: ({ to, from }: { to: string; from: string }) => void+export interface DatePickerProps {+ onChange?: (args: DatePickerToFrom) => voidto?: stringfrom?: stringtriggerButtonType?: ButtonProps['type']triggerButtonClassName?: string+ renderFooter?: (args: DatePickerToFrom) => React.ReactNode | void}const START_DATE_DEFAULT = new Date()const END_DATE_DEFAULT = new Date()--// console.log('START_DATE_DEFAULT', START_DATE_DEFAULT)-const START_TIME_DEFAULT = { HH: '00', mm: '00', ss: '00' }const END_TIME_DEFAULT = { HH: '23', mm: '59', ss: '59' }@@ -54,24 +40,31 @@ function _DatePicker({onChange,triggerButtonType = 'default',triggerButtonClassName = '',-}: RootProps) {+ renderFooter = () => null,+}: DatePickerProps) {const [open, setOpen] = useState<boolean>(false)-- const [showTime, setShowTime] = useState<boolean>(true)-- const [appliedStartDate, setAppliedStartDate] = useState<any>(null)- const [appliedEndDate, setAppliedEndDate] = useState<any>(null)-- const [startDate, setStartDate] = useState<any>(START_DATE_DEFAULT)- const [endDate, setEndDate] = useState<any>(END_DATE_DEFAULT)-+ const [appliedStartDate, setAppliedStartDate] = useState<null | Date>(null)+ const [appliedEndDate, setAppliedEndDate] = useState<null | Date>(null)+ const [startDate, setStartDate] = useState<Date | null>(START_DATE_DEFAULT)+ const [endDate, setEndDate] = useState<Date | null>(END_DATE_DEFAULT)const [startTime, setStartTime] = useState<any>(START_TIME_DEFAULT)const [endTime, setEndTime] = useState<any>(END_TIME_DEFAULT)useEffect(() => {- if (!to || !from) {+ if (!from) {setAppliedStartDate(null)+ } else if (from !== appliedStartDate?.toISOString()) {+ const start = dayjs(from).toDate()+ setAppliedStartDate(start)+ setStartDate(start)+ }++ if (!to) {setAppliedEndDate(null)+ } else if (to !== appliedEndDate?.toISOString()) {+ const end = dayjs(to).toDate()+ setAppliedEndDate(end)+ setEndDate(end)}}, [to, from])@@ -115,168 +108,77 @@ function _DatePicker({setAppliedStartDate(null)setAppliedEndDate(null)}-- const DEFAULT_DATE_FORMAT = 'ddd MMM YYYY HH:mm:ss'-return (- <>- <Popover- open={open}- onOpenChange={(e) => setOpen(e)}- size="small"- align="center"- side="bottom"- header={- <>- <div className="flex justify-between items-stretch py-2">- <div className="grow flex flex-col gap-1">- <TimeSplitInput- type="start"- startTime={startTime}- endTime={endTime}- time={startTime}- setTime={setStartTime}- setStartTime={setStartTime}- setEndTime={setEndTime}- startDate={startDate}- endDate={endDate}- />- </div>- <div- className={`+ <Popover+ open={open}+ onOpenChange={(e) => setOpen(e)}+ size="small"+ align="center"+ side="bottom"+ header={+ <>+ <div className="flex justify-between items-stretch py-2">+ <div className="grow flex flex-col gap-1">+ <TimeSplitInput+ type="start"+ startTime={startTime}+ endTime={endTime}+ time={startTime}+ setTime={setStartTime}+ setStartTime={setStartTime}+ setEndTime={setEndTime}+ startDate={startDate}+ endDate={endDate}+ />+ </div>+ <div+ className={`w-12flexitems-centerjustify-centertext-scale-900`}- >- <IconArrowRight strokeWidth={1.5} size={14} />- </div>- <div className="grow flex flex-col gap-1">- <TimeSplitInput- type="end"- startTime={startTime}- endTime={endTime}- time={endTime}- setTime={setEndTime}- setStartTime={setStartTime}- setEndTime={setEndTime}- startDate={startDate}- endDate={endDate}- />- </div>+ >+ <IconArrowRight strokeWidth={1.5} size={14} /></div>- </>- }- overlay={- <>- <div className="px-3 py-4">- <DatePicker- selected={startDate}- onChange={(dates) => {- handleDatePickerChange(dates)- }}- dateFormat="MMMM d, yyyy h:mm aa"+ <div className="grow flex flex-col gap-1">+ <TimeSplitInput+ type="end"+ startTime={startTime}+ endTime={endTime}+ time={endTime}+ setTime={setEndTime}+ setStartTime={setStartTime}+ setEndTime={setEndTime}startDate={startDate}endDate={endDate}- selectsRange- // showTimeSelect- // nextMonthButtonLabel=">"- // previousMonthButtonLabel="<"- // popperClassName="react-datepicker-left"- // customInput={<ButtonInput />}- // dateFormat={DEFAULT_DATE_FORMAT}- // dateFormat={(locale, date) => dayjs(date).format('MM-YYYY')}- inline- dayClassName={() => 'cursor-pointer'}- renderCustomHeader={({- date,- decreaseMonth,- increaseMonth,- prevMonthButtonDisabled,- nextMonthButtonDisabled,- }) => (- <div className="flex items-center justify-between px-2 py-2">- <div className="flex items-center justify-between w-full">- <button- onClick={decreaseMonth}- disabled={prevMonthButtonDisabled}- type="button"- className={`- ${prevMonthButtonDisabled && 'cursor-not-allowed opacity-50'}- text-scale-1100 hover:text-scale-1200 focus:outline-none- `}- >- <IconChevronLeft size={16} strokeWidth={2} />- </button>- <span className="text-sm text-scale-1100">{format(date, 'MMMM yyyy')}</span>- <button- onClick={increaseMonth}- disabled={nextMonthButtonDisabled}- type="button"- className={`- ${nextMonthButtonDisabled && 'cursor-not-allowed opacity-50'}- text-scale-1100 hover:text-scale-1200 focus:outline-none- `}- >- <IconChevronRight size={16} strokeWidth={2} />- </button>- </div>- </div>- )}/></div>-- <Popover.Seperator />- <div className="flex items-center justify-end gap-2 py-2 pb-4 px-3">- <Button type="default" onClick={() => handleClear()}>- Clear- </Button>- <Button onClick={() => handleSubmit()}>Apply</Button>- </div>- </>- }- >- <Button- type={triggerButtonType}- as="span"- icon={<IconCalendar />}- className={triggerButtonClassName}- >- {/* Custom */}- {appliedStartDate && appliedEndDate && appliedStartDate !== appliedEndDate ? (- <>- {format(new Date(appliedStartDate), 'dd MMM')} -{' '}- {format(new Date(appliedEndDate), 'dd MMM')}- </>- ) : appliedStartDate || appliedEndDate ? (- format(new Date(appliedStartDate || appliedEndDate), 'dd MMM')- ) : (- 'Custom'- )}- </Button>- </Popover>-- {/* <div className="relative w-40">- <DatePicker- selected={endDate}- onChange={(date) => setEndDate(date)}- selectsEnd- startDate={startDate}- endDate={endDate}- nextMonthButtonLabel=">"- previousMonthButtonLabel="<"- popperClassName="react-datepicker-right"- customInput={<ButtonInput />}- renderCustomHeader={({- date,- decreaseMonth,- increaseMonth,- prevMonthButtonDisabled,- nextMonthButtonDisabled,- }) => (- <>+ </div>+ </>+ }+ overlay={+ <>+ <div className="px-3 py-4">+ <DatePicker+ selected={startDate}+ onChange={(dates) => {+ handleDatePickerChange(dates)+ }}+ dateFormat="MMMM d, yyyy h:mm aa"+ startDate={startDate}+ endDate={endDate}+ selectsRange+ inline+ dayClassName={() => 'cursor-pointer'}+ renderCustomHeader={({+ date,+ decreaseMonth,+ increaseMonth,+ prevMonthButtonDisabled,+ nextMonthButtonDisabled,+ }) => (<div className="flex items-center justify-between px-2 py-2"><div className="flex items-center justify-between w-full"><button@@ -284,27 +186,19 @@ function _DatePicker({disabled={prevMonthButtonDisabled}type="button"className={`- ${- prevMonthButtonDisabled &&- 'cursor-not-allowed opacity-50'- }+ ${prevMonthButtonDisabled && 'cursor-not-allowed opacity-50'}text-scale-1100 hover:text-scale-1200 focus:outline-none`}><IconChevronLeft size={16} strokeWidth={2} /></button>- <span className="text-sm text-scale-1100">- {format(date, 'MMMM yyyy')}- </span>+ <span className="text-sm text-scale-1100">{format(date, 'MMMM yyyy')}</span><buttononClick={increaseMonth}disabled={nextMonthButtonDisabled}type="button"className={`- ${- nextMonthButtonDisabled &&- 'cursor-not-allowed opacity-50'- }+ ${nextMonthButtonDisabled && 'cursor-not-allowed opacity-50'}text-scale-1100 hover:text-scale-1200 focus:outline-none`}>@@ -312,51 +206,43 @@ function _DatePicker({</button></div></div>- </>- )}- />- </div>- </div>- <div className="flex items-center justify-center max-w-2xl py-20 mx-auto space-x-4">- <span className="font-medium text-gray-900">Default Components:</span>- <div className="relative w-40">- <DatePicker- selected={startDate}- onChange={(date) => setStartDate(date)}- selectsStart- startDate={startDate}- endDate={endDate}- nextMonthButtonLabel=">"- previousMonthButtonLabel="<"- popperClassName="react-datepicker-left"- />- </div>- <div className="relative w-40">- <DatePicker- selected={endDate}- onChange={(date) => setEndDate(date)}- selectsEnd- startDate={startDate}- endDate={endDate}- nextMonthButtonLabel=">"- previousMonthButtonLabel="<"- popperClassName="react-datepicker-right"- />- </div> */}- </>+ )}+ />+ </div>+ {renderFooter({+ from: startDate?.toISOString() || null,+ to: endDate?.toISOString() || null,+ })}+ <Popover.Seperator />+ <div className="flex items-center justify-end gap-2 py-2 pb-4 px-3">+ <Button type="default" onClick={() => handleClear()}>+ Clear+ </Button>+ <Button onClick={() => handleSubmit()}>Apply</Button>+ </div>+ </>+ }+ >+ <Button+ type={triggerButtonType}+ as="span"+ icon={<IconCalendar />}+ className={triggerButtonClassName}+ >+ {/* Custom */}+ {appliedStartDate && appliedEndDate && appliedStartDate !== appliedEndDate ? (+ <>+ {format(new Date(appliedStartDate), 'dd MMM')} -{' '}+ {format(new Date(appliedEndDate), 'dd MMM')}+ </>+ ) : appliedStartDate || appliedEndDate ? (+ format(new Date((appliedStartDate || appliedEndDate)!), 'dd MMM')+ ) : (+ 'Custom'+ )}+ </Button>+ </Popover>)}-const ButtonInput = forwardRef(({ value, onClick }: any, ref): any => (- <button- onClick={onClick}- // @ts-ignore- ref={ref}- type="button"- className="inline-flex justify-start w-full px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-0 focus:ring-blue-500"- >- {value}- </button>-))-export default _DatePickerdiff --git a/studio/components/ui/DatePicker/index.tsx b/studio/components/ui/DatePicker/index.tsxindex 25865361516..cb250378e19 100644--- a/studio/components/ui/DatePicker/index.tsx+++ b/studio/components/ui/DatePicker/index.tsx@@ -1 +1,2 @@export { default as DatePicker } from './DatePicker'+export type {DatePickerProps} from "./DatePicker"\ No newline at end of filediff --git a/studio/pages/project/[ref]/logs-explorer/index.tsx b/studio/pages/project/[ref]/logs-explorer/index.tsxindex 5f022a91455..f06a351ef99 100644--- a/studio/pages/project/[ref]/logs-explorer/index.tsx+++ b/studio/pages/project/[ref]/logs-explorer/index.tsx@@ -2,10 +2,11 @@ import React, { useEffect, useState } from 'react'import { NextPage } from 'next'import { useRouter } from 'next/router'import { observer } from 'mobx-react-lite'-import { Typography, IconAlertCircle, Card, Input, Alert, Modal, Form, Button } from '@supabase/ui'+import { Input, Modal, Form, Button } from '@supabase/ui'import { useStore, withAuth } from 'hooks'import CodeEditor from 'components/ui/CodeEditor'import {+ DatePickerToFrom,LogsQueryPanel,LogsTableName,LogTable,@@ -79,15 +80,15 @@ export const LogsExplorerPage: NextPage = () => {setSaveModalOpen(!saveModalOpen)}- const handleDateChange = ({ to = '', from = '' }: { to: string; from: string }) => {+ const handleDateChange = ({ to, from }: DatePickerToFrom) => {setParams((prev) => ({...prev,- iso_timestamp_start: from,- iso_timestamp_end: to,+ iso_timestamp_start: from || '',+ iso_timestamp_end: to || '',}))router.push({pathname: router.pathname,- query: { ...router.query, its: from, ite: to },+ query: { ...router.query, its: from || '', ite: to || '' },})}diff --git a/studio/tests/pages/projects/Logs.Datepickers.test.js b/studio/tests/pages/projects/Logs.Datepickers.test.jsnew file mode 100644index 00000000000..2a578d480fb--- /dev/null+++ b/studio/tests/pages/projects/Logs.Datepickers.test.js@@ -0,0 +1,19 @@+import { render, screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { PREVIEWER_DATEPICKER_HELPERS } from 'components/interfaces/Settings/Logs'+import DatePickers from 'components/interfaces/Settings/Logs/Logs.DatePickers'+import dayjs from 'dayjs'++test('renders warning', async () => {+ const from = dayjs().subtract(60, 'days')+ const to = dayjs()+ render(+ <DatePickers+ helpers={PREVIEWER_DATEPICKER_HELPERS}+ to={to.toISOString()}+ from={from.toISOString()}+ />+ )+ userEvent.click(await screen.findByText(RegExp(from.format('DD MMM'))))+ await screen.findByText(/memory errors/)+})