Skip to content

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

Fix DateTimeEditor in Grid

Joshen Limc6019bbc8b39
diff --git a/studio/components/grid/components/editor/DateTimeEditor.tsx b/studio/components/grid/components/editor/DateTimeEditor.tsx
index 5ca91200406..642e58f9cf3 100644
--- a/studio/components/grid/components/editor/DateTimeEditor.tsx
+++ b/studio/components/grid/components/editor/DateTimeEditor.tsx
@@ -1,21 +1,20 @@
-import * as React from 'react';
-import { EditorProps } from '@supabase/react-data-grid';
-import dayjs from 'dayjs';
-import customParseFormat from 'dayjs/plugin/customParseFormat';
+import { ChangeEvent } from 'react'
+import { EditorProps } from '@supabase/react-data-grid'
+import dayjs from 'dayjs'
+import customParseFormat from 'dayjs/plugin/customParseFormat'
-dayjs.extend(customParseFormat);
+dayjs.extend(customParseFormat)
function autoFocusAndSelect(input: HTMLInputElement | null) {
- input?.focus();
- input?.select();
+ input?.focus()
+ input?.select()
}
-interface DateTimeEditorProps<TRow, TSummaryRow = unknown>
- extends EditorProps<TRow, TSummaryRow> {
- format: string;
+interface Props<TRow, TSummaryRow = unknown> extends EditorProps<TRow, TSummaryRow> {
+ format: string
}
-const INPUT_DATE_TIME_FORMAT = 'YYYY-MM-DDTHH:mm:ss';
+const INPUT_DATE_TIME_FORMAT = 'YYYY-MM-DDTHH:mm:ss'
function BaseEditor<TRow, TSummaryRow = unknown>({
row,
@@ -23,19 +22,17 @@ function BaseEditor<TRow, TSummaryRow = unknown>({
format,
onRowChange,
onClose,
-}: DateTimeEditorProps<TRow, TSummaryRow>) {
- const value = row[column.key as keyof TRow] as unknown as string;
- const timeValue = value
- ? dayjs(value, format).format(INPUT_DATE_TIME_FORMAT)
- : value;
-
- function onChange(event: React.ChangeEvent<HTMLInputElement>) {
- let _value = event.target.value;
- if (_value == '') {
- onRowChange({ ...row, [column.key]: null });
+}: Props<TRow, TSummaryRow>) {
+ const value = row[column.key as keyof TRow] as unknown as string
+ const timeValue = value ? dayjs(value, format).format(INPUT_DATE_TIME_FORMAT) : value
+
+ function onChange(event: ChangeEvent<HTMLInputElement>) {
+ const _value = event.target.value
+ if (_value.length === 0) {
+ onRowChange({ ...row, [column.key]: null })
} else {
- const _timeValue = dayjs(_value, INPUT_DATE_TIME_FORMAT).format(format);
- onRowChange({ ...row, [column.key]: _timeValue });
+ const _timeValue = dayjs(_value).format(format)
+ onRowChange({ ...row, [column.key]: _timeValue })
}
}
@@ -49,17 +46,15 @@ function BaseEditor<TRow, TSummaryRow = unknown>({
type="datetime-local"
step="1"
/>
- );
+ )
}
-export function DateTimeEditor<TRow, TSummaryRow = unknown>(
- props: EditorProps<TRow, TSummaryRow>
-) {
- return <BaseEditor {...props} format="YYYY-MM-DDTHH:mm:ss" />;
+export function DateTimeEditor<TRow, TSummaryRow = unknown>(props: EditorProps<TRow, TSummaryRow>) {
+ return <BaseEditor {...props} format="YYYY-MM-DDTHH:mm:ss" />
}
export function DateTimeWithTimezoneEditor<TRow, TSummaryRow = unknown>(
props: EditorProps<TRow, TSummaryRow>
) {
- return <BaseEditor {...props} format="YYYY-MM-DDTHH:mm:ssZ" />;
+ return <BaseEditor {...props} format="YYYY-MM-DDTHH:mm:ssZ" />
}
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsx
index 4a4e9994027..9f18c1856d5 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.tsx
@@ -21,6 +21,7 @@ const DateTimeInput: FC<Props> = ({ value, onChange, name, format, description }
function handleOnChange(e: any) {
const temp = e.target.value
+ console.log('DateTimeINput', temp)
if (temp.length === 0) return
onChange(temp)
}