The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Chore/improvements to datetime editing in table editor (#29660)
Joshen Limc2608f837dac
diff --git a/apps/studio/components/grid/components/editor/DateEditor.tsx b/apps/studio/components/grid/components/editor/DateEditor.tsxindex a32acca76c0..de0d0547adc 100644--- a/apps/studio/components/grid/components/editor/DateEditor.tsx+++ b/apps/studio/components/grid/components/editor/DateEditor.tsx@@ -1,33 +1,36 @@-import * as React from 'react'+import { ChangeEvent, useEffect, useRef } from 'react'import type { RenderEditCellProps } from 'react-data-grid'-function autoFocusAndSelect(input: HTMLInputElement | null) {- input?.focus()- input?.select()-}-export function DateEditor<TRow, TSummaryRow = unknown>({row,column,onRowChange,onClose,}: RenderEditCellProps<TRow, TSummaryRow>) {+ const ref = useRef<HTMLInputElement>(null)const value = row[column.key as keyof TRow] as unknown as string- function onChange(event: React.ChangeEvent<HTMLInputElement>) {+ function onChange(event: ChangeEvent<HTMLInputElement>) {let _value = event.target.valueif (_value == '') onRowChange({ ...row, [column.key]: null })else onRowChange({ ...row, [column.key]: _value })}+ useEffect(() => {+ if (ref.current) {+ ref.current.focus()+ ref.current.showPicker()+ }+ }, [])+return (<input- className="sb-grid-date-editor"- ref={autoFocusAndSelect}+ ref={ref}+ type="date"+ className="h-full w-full px-2 text-sm"value={value ?? ''}onChange={onChange}onBlur={() => onClose(true)}- type="date"/>)}diff --git a/apps/studio/components/grid/components/editor/DateTimeEditor.tsx b/apps/studio/components/grid/components/editor/DateTimeEditor.tsxindex aa6cfc69cbe..ae4f97a068b 100644--- a/apps/studio/components/grid/components/editor/DateTimeEditor.tsx+++ b/apps/studio/components/grid/components/editor/DateTimeEditor.tsx@@ -1,30 +1,22 @@-import type { ChangeEvent } from 'react'-import type { RenderEditCellProps } from 'react-data-grid'import dayjs from 'dayjs'-import customParseFormat from 'dayjs/plugin/customParseFormat'--dayjs.extend(customParseFormat)--function autoFocusAndSelect(input: HTMLInputElement | null) {- input?.focus()- input?.select()-}+import { useEffect, useRef, type ChangeEvent } from 'react'+import type { RenderEditCellProps } from 'react-data-grid'-interface Props<TRow, TSummaryRow = unknown> extends RenderEditCellProps<TRow, TSummaryRow> {+interface BaseEditorProps<TRow, TSummaryRow = unknown>+ extends RenderEditCellProps<TRow, TSummaryRow> {format: string}-const INPUT_DATE_TIME_FORMAT = 'YYYY-MM-DDTHH:mm:ss'-function BaseEditor<TRow, TSummaryRow = unknown>({row,column,format,onRowChange,onClose,-}: Props<TRow, TSummaryRow>) {+}: BaseEditorProps<TRow, TSummaryRow>) {+ const ref = useRef<HTMLInputElement>(null)const value = row[column.key as keyof TRow] as unknown as string- const timeValue = value ? dayjs(value, format).format(INPUT_DATE_TIME_FORMAT) : value+ const timeValue = value ? dayjs(value, format).format('YYYY-MM-DDTHH:mm:ss') : valuefunction onChange(event: ChangeEvent<HTMLInputElement>) {const _value = event.target.value@@ -36,15 +28,22 @@ function BaseEditor<TRow, TSummaryRow = unknown>({}}+ useEffect(() => {+ if (ref.current) {+ ref.current.focus()+ ref.current.showPicker()+ }+ }, [])+return (<input- className="sb-grid-datetime-editor"- ref={autoFocusAndSelect}+ ref={ref}+ step="1"+ type="datetime-local"+ className="h-full w-full px-2 text-sm"value={timeValue ?? ''}onChange={onChange}onBlur={() => onClose(true)}- type="datetime-local"- step="1"/>)}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsxindex 1fc45ab16f5..43afef86ec2 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsx@@ -278,7 +278,7 @@ const ColumnType = ({</Popover_Shadcn_>{showRecommendation && recommendation !== undefined && (- <Alert_Shadcn_ variant="warning">+ <Alert_Shadcn_ variant="warning" className="mt-2"><CriticalIcon /><AlertTitle_Shadcn_>{' '}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsxindex 7dc200b0dfe..743eb8004d3 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsx@@ -1,13 +1,23 @@import dayjs from 'dayjs'+import { Edit } from 'lucide-react'import { ReactNode } from 'react'-import { Input } from 'ui'+import {+ Button,+ cn,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+ Input,+} from 'ui'import { getColumnType } from './DateTimeInput.utils'interface DateTimeInputProps {name: stringformat: stringvalue: string+ isNullable: booleandescription: string | ReactNodeonChange: (value: string) => void}@@ -17,19 +27,20 @@ interface DateTimeInputProps {* e.g Yes: 2022-05-13T14:29:03* No: 2022-05-13T14:29:03+0800*/-const DateTimeInput = ({ value, onChange, name, format, description }: DateTimeInputProps) => {+const DateTimeInput = ({+ value,+ onChange,+ name,+ isNullable,+ format,+ description,+}: DateTimeInputProps) => {const inputType = getColumnType(format)- function handleOnChange(e: any) {- const temp = e.target.value- if (temp.length === 0 && temp !== '') return- onChange(temp)- }-return (<Inputlayout="horizontal"- className="w-full"+ className={cn('w-full [&>div>div>div>input]:pr-10')}label={name}descriptionText={<div className="space-y-1">@@ -43,8 +54,35 @@ const DateTimeInput = ({ value, onChange, name, format, description }: DateTimeIsize="small"value={value}type={inputType}- onChange={handleOnChange}step={inputType == 'datetime-local' || inputType == 'time' ? '1' : undefined}+ actions={+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button type="default" icon={<Edit />} className="px-1.5" />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="w-28">+ {isNullable && (+ <DropdownMenuItem onClick={() => onChange('')}>Set to NULL</DropdownMenuItem>+ )}+ <DropdownMenuItem+ onClick={() =>+ onChange(+ dayjs().format(+ format === 'date'+ ? 'YYYY-MM-DD'+ : ['time', 'timetz'].includes(format)+ ? 'HH:mm:ss'+ : 'YYYY-MM-DDTHH:mm:ss'+ )+ )+ }+ >+ Set to now+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ }+ onChange={(e) => onChange(e.target.value)}/>)}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsxindex 2ed80b405d2..d4f5db3b2ec 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/InputField.tsx@@ -168,7 +168,7 @@ const InputField = ({<DropdownMenuTrigger asChild><Button type="default" icon={<Edit />} className="px-1.5" /></DropdownMenuTrigger>- <DropdownMenuContent align="end" className="w-40">+ <DropdownMenuContent align="end" className="w-28"><DropdownMenuItem onClick={() => onUpdateField({ [field.name]: null })}>Set to NULL</DropdownMenuItem>@@ -231,6 +231,7 @@ const InputField = ({name={field.name}format={field.format}value={field.value ?? ''}+ isNullable={field.isNullable}description={<>{field.defaultValue && <p>Default: {field.defaultValue}</p>}diff --git a/apps/studio/pages/project/[ref]/database/functions.tsx b/apps/studio/pages/project/[ref]/database/functions.tsxindex 91fd0fff6a9..35e1d3b726b 100644--- a/apps/studio/pages/project/[ref]/database/functions.tsx+++ b/apps/studio/pages/project/[ref]/database/functions.tsx@@ -43,7 +43,10 @@ const FunctionsPage: NextPageWithLayout = () => {<ScaffoldContainer><ScaffoldSection><div className="col-span-12">- <FormHeader title="Database Functions" />+ <FormHeader+ title="Database Functions"+ docsUrl="https://supabase.com/docs/guides/database/functions"+ /><FunctionsListcreateFunction={createFunction}editFunction={editFunction}diff --git a/apps/studio/pages/project/[ref]/database/tables/index.tsx b/apps/studio/pages/project/[ref]/database/tables/index.tsxindex 2caf1fc4c00..cb4473b09e4 100644--- a/apps/studio/pages/project/[ref]/database/tables/index.tsx+++ b/apps/studio/pages/project/[ref]/database/tables/index.tsx@@ -18,7 +18,7 @@ const DatabaseTables: NextPageWithLayout = () => {<><ScaffoldContainer><ScaffoldSection>- <div className="col-span-12 space-x-2">+ <div className="col-span-12"><FormHeader title="Database Tables" /><TableListonAddTable={snap.onAddTable}diff --git a/apps/studio/pages/project/[ref]/database/triggers.tsx b/apps/studio/pages/project/[ref]/database/triggers.tsxindex 845fd86b6f8..c11b3877c1c 100644--- a/apps/studio/pages/project/[ref]/database/triggers.tsx+++ b/apps/studio/pages/project/[ref]/database/triggers.tsx@@ -42,7 +42,11 @@ const TriggersPage: NextPageWithLayout = () => {<ScaffoldContainer><ScaffoldSection><div className="col-span-12">- <FormHeader title="Database Triggers" />+ <FormHeader+ title="Database Triggers"+ description="Execute a set of actions automatically on specified table events"+ docsUrl="https://supabase.com/docs/guides/database/postgres/triggers"+ /><TriggersListcreateTrigger={createTrigger}editTrigger={editTrigger}diff --git a/apps/studio/styles/grid.scss b/apps/studio/styles/grid.scssindex ee028edd924..3b4c378004e 100644--- a/apps/studio/styles/grid.scss+++ b/apps/studio/styles/grid.scss@@ -338,22 +338,6 @@outline: 4px auto -webkit-focus-ring-color;}-/*- DateEditor-*/--.sb-grid-date-editor {- @apply h-full w-full px-2;-}--/*- DateTimeEditor-*/--.sb-grid-datetime-editor {- @apply h-full w-full px-2;-}-/*JsonEditor*/