The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Shift SpreadsheetImport
Joshen Lim93543c548683
diff --git a/studio/components/grid/components/header/Header.tsx b/studio/components/grid/components/header/Header.tsxindex 9b513d889f9..fbe92a1ff67 100644--- a/studio/components/grid/components/header/Header.tsx+++ b/studio/components/grid/components/header/Header.tsx@@ -27,6 +27,7 @@ import { useTableRowTruncateMutation } from 'data/table-rows/table-row-truncate-import { useTableRowsCountQuery } from 'data/table-rows/table-rows-count-query'import { useTableRowsQuery } from 'data/table-rows/table-rows-query'import RLSBannerWarning from './RLSBannerWarning'+import clsx from 'clsx'// [Joshen] CSV exports require this guard as a fail-safe if the table is// just too large for a browser to keep all the rows in memory before@@ -187,20 +188,13 @@ const DefaultHeader = ({className="group"onClick={onImportData}icon={- // <div className="-mt-2 pr-1.5">- // <div className="border border-scale-1000 w-[15px] h-[4px]" />- // <div className="border border-scale-1000 w-[15px] h-[4px] my-[2px]" />- // <div- // className={[- // 'border border-scale-1100 w-[15px] h-[4px] translate-x-0.5',- // 'transition duration-200 group-hover:border-brand-900 group-hover:translate-x-0',- // ].join(' ')}- // />- // </div><div className="relative -mt-2"><IconFileText className="-translate-x-[2px]" /><IconArrowUp- className="absolute bottom-0 right-1 translate-y-0.5"+ className={clsx(+ 'transition duration-200 absolute bottom-0 right-0 translate-y-1 opacity-0 bg-brand-700 rounded-full',+ 'group-hover:translate-y-0 group-hover:text-brand-900 group-hover:opacity-100'+ )}strokeWidth={3}size={12}/>diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsxindex 99ce84b03f4..8b506c86bd3 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx@@ -9,7 +9,7 @@ import { useStore } from 'hooks'import { entityTypeKeys } from 'data/entity-types/keys'import { useTableRowCreateMutation } from 'data/table-rows/table-row-create-mutation'import { useTableRowUpdateMutation } from 'data/table-rows/table-row-update-mutation'-import { RowEditor, ColumnEditor, TableEditor } from '.'+import { RowEditor, ColumnEditor, TableEditor, SpreadsheetImport } from '.'import { ImportContent } from './TableEditor/TableEditor.types'import {ColumnField,@@ -38,7 +38,7 @@ export interface SidePanelEditorProps {row: anycolumn: any}- sidePanelKey?: 'row' | 'column' | 'table' | 'json' | 'foreign-row-selector'+ sidePanelKey?: 'row' | 'column' | 'table' | 'json' | 'foreign-row-selector' | 'csv-import'isDuplicating?: booleanclosePanel: () => voidonRowCreated?: (row: Dictionary<any>) => void@@ -449,6 +449,12 @@ const SidePanelEditor = ({closePanel={onClosePanel}onSelect={onSaveForeignRow}/>+ <SpreadsheetImport+ visible={sidePanelKey === 'csv-import'}+ selectedTable={selectedTableToEdit}+ saveContent={() => {}}+ closePanel={onClosePanel}+ /><ConfirmationModalvisible={isClosingPanel}header="Confirm to close"diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadSheetFileUpload.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadSheetFileUpload.tsxsimilarity index 94%rename from studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadSheetFileUpload.tsxrename to studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadSheetFileUpload.tsxindex e687346f53a..b83ad4a916f 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadSheetFileUpload.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadSheetFileUpload.tsx@@ -42,7 +42,7 @@ const SpreadSheetFileUpload: FC<Props> = ({<span className="text-code">-</span>) or underscores (<span className="text-code">_</span>).</p>- <p className="text-xs text-scale-900">+ <p className="text-sm text-scale-1000">Tip: Datetime columns should be formatted as YYYY-MM-DD HH:mm:ss</p></div>@@ -56,8 +56,8 @@ const SpreadSheetFileUpload: FC<Props> = ({onDrop={onDrop}onClick={() => (uploadButtonRef.current as any)?.click()}>- <p>- Drag and drop, or <span className="text-green-1000">browse</span> your files+ <p className="text-sm">+ Drag and drop, or <span className="text-brand-900">browse</span> your files</p></div>) : (diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadSheetTextInput.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadSheetTextInput.tsxsimilarity index 100%rename from studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadSheetTextInput.tsxrename to studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadSheetTextInput.tsxdiff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.constants.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.constants.tssimilarity index 100%rename from studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.constants.tsrename to studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.constants.tsdiff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.tsxsimilarity index 93%rename from studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.tsxrename to studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.tsxindex 5720920afbb..93b2bfa71dd 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.tsx@@ -3,7 +3,7 @@ import { debounce, includes } from 'lodash'import { SidePanel, Tabs, IconArrowRight, IconChevronRight } from 'ui'import { useStore } from 'hooks'-import ActionBar from '../../ActionBar'+import ActionBar from '../ActionBar'import SpreadSheetTextInput from './SpreadSheetTextInput'import SpreadSheetFileUpload from './SpreadSheetFileUpload'import SpreadsheetPreview from './SpreadsheetPreview'@@ -20,6 +20,7 @@ interface Props {headers?: string[]rows?: any[]visible: boolean+ selectedTable?: anysaveContent: (prefillData: any) => voidclosePanel: () => void}@@ -28,6 +29,7 @@ const SpreadsheetImport: FC<Props> = ({debounceDuration = 250,headers = [],rows = [],+ selectedTable,saveContent,closePanel,visible = false,@@ -35,10 +37,8 @@ const SpreadsheetImport: FC<Props> = ({const { ui } = useStore()useEffect(() => {- if (visible) {- if (headers.length === 0) {- resetSpreadsheetImport()- }+ if (visible && headers.length === 0) {+ resetSpreadsheetImport()}}, [visible])@@ -133,7 +133,18 @@ const SpreadsheetImport: FC<Props> = ({size="large"visible={visible}align="right"- header="Add content to new table"+ header={+ selectedTable !== undefined ? (+ <>+ Add data to{' '}+ <code className="text-sm">+ {selectedTable.schema}.{selectedTable.name}+ </code>+ </>+ ) : (+ 'Add content to new table'+ )+ }onCancel={() => closePanel()}customFooter={<ActionBar@@ -150,7 +161,7 @@ const SpreadsheetImport: FC<Props> = ({}><SidePanel.Content>- <div className="flex flex-col">+ <div className="pt-6"><Tabs block type="pills"><Tabs.Panel id="fileUpload" label="Upload CSV"><SpreadSheetFileUpload@@ -209,7 +220,9 @@ const SpreadsheetImport: FC<Props> = ({<IconArrowRight size={14} /><p>Extra field(s):</p>{error.data?.__parsed_extra.map((value: any, i: number) => (- <code key={i} className="text-sm">{value}</code>+ <code key={i} className="text-sm">+ {value}+ </code>))}</>)}diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.types.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.types.tssimilarity index 100%rename from studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.types.tsrename to studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.types.tsdiff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.utils.tssimilarity index 100%rename from studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.tsrename to studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.utils.tsdiff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetPreview.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetPreview.tsxsimilarity index 100%rename from studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetPreview.tsxrename to studio/components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetPreview.tsxdiff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsxindex caec9de9950..7f0c9ad1464 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx@@ -1,3 +1,4 @@+import Link from 'next/link'import { FC, useEffect, useState } from 'react'import { isUndefined, isEmpty } from 'lodash'import { Badge, Checkbox, SidePanel, Input, Alert, IconBookOpen, Button } from 'ui'@@ -7,7 +8,7 @@ import { useStore } from 'hooks'import ActionBar from '../ActionBar'import HeaderTitle from './HeaderTitle'import ColumnManagement from './ColumnManagement'-import SpreadsheetImport from './SpreadsheetImport/SpreadsheetImport'+import { SpreadsheetImport } from '../'import { ColumnField, CreateTablePayload, UpdateTablePayload } from '../SidePanelEditor.types'import { DEFAULT_COLUMNS } from './TableEditor.constants'import { TableField, ImportContent } from './TableEditor.types'@@ -19,7 +20,6 @@ import {} from './TableEditor.utils'import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'-import Link from 'next/link'interface Props {table?: PostgresTablediff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/index.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/index.tsindex 373f44921dd..6b0602c7648 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/index.ts+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/index.ts@@ -2,7 +2,8 @@ import SidePanelEditor from './SidePanelEditor'import RowEditor from './RowEditor/RowEditor'import ColumnEditor from './ColumnEditor/ColumnEditor'import TableEditor from './TableEditor/TableEditor'+import SpreadsheetImport from './SpreadsheetImport/SpreadsheetImport'import ForeignKeySelector from './ForeignKeySelector/ForeignKeySelector'-export { RowEditor, ColumnEditor, TableEditor, ForeignKeySelector }+export { RowEditor, ColumnEditor, TableEditor, ForeignKeySelector, SpreadsheetImport }export default SidePanelEditordiff --git a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsxindex e55177b11b2..6139db369dd 100644--- a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx@@ -41,7 +41,7 @@ export interface TableGridEditorProps {selectedTable: any // PostgresTable | SchemaView/** Determines what side panel editor to show */- sidePanelKey?: 'row' | 'column' | 'table' | 'json' | 'foreign-row-selector'+ sidePanelKey?: 'row' | 'column' | 'table' | 'json' | 'foreign-row-selector' | 'csv-import'/** Toggles if we're duplicating a table */isDuplicating: boolean/** Selected entities if we're editing a row, column or table */@@ -67,6 +67,7 @@ export interface TableGridEditorProps {column: any}) => voidonClosePanel: () => void+ onImportData: () => void}const TableGridEditor = ({@@ -90,6 +91,7 @@ const TableGridEditor = ({onExpandJSONEditor = noop,onEditForeignKeyColumnValue = noop,onClosePanel = noop,+ onImportData = noop,}: TableGridEditorProps) => {const { meta, ui, vault } = useStore()const router = useRouter()@@ -361,7 +363,7 @@ const TableGridEditor = ({onAddRow={onAddRow}updateTableRow={updateTableRow}onEditRow={onEditRow}- onImportData={() => {}}+ onImportData={onImportData}onError={onError}onSqlQuery={onSqlQuery}onExpandJSONEditor={onExpandJSONEditor}diff --git a/studio/pages/project/[ref]/editor/[id].tsx b/studio/pages/project/[ref]/editor/[id].tsxindex 9fd9ca0e2dc..bfba20e458f 100644--- a/studio/pages/project/[ref]/editor/[id].tsx+++ b/studio/pages/project/[ref]/editor/[id].tsx@@ -37,7 +37,7 @@ const TableEditorPage: NextPageWithLayout = () => {const [selectedTableToDelete, setSelectedTableToDelete] = useState<PostgresTable>()const [sidePanelKey, setSidePanelKey] = useState<- 'row' | 'column' | 'table' | 'json' | 'foreign-row-selector'+ 'row' | 'column' | 'table' | 'json' | 'foreign-row-selector' | 'csv-import'>()const [selectedRowToEdit, setSelectedRowToEdit] = useState<Dictionary<any>>()const [selectedColumnToEdit, setSelectedColumnToEdit] = useState<PostgresColumn>()@@ -130,6 +130,16 @@ const TableEditorPage: NextPageWithLayout = () => {setSelectedValueForJsonEdit({ column, row, jsonString: JSON.stringify(row[column]) || '' })}+ const onImportData = () => {+ if (id) {+ setSidePanelKey('csv-import')+ const table = meta.tables.byId(id)+ setSelectedTableToEdit(table)+ } else {+ console.error('Table ID not found')+ }+ }+const onEditForeignKeyColumnValue = ({foreignKey,row,@@ -259,6 +269,7 @@ const TableEditorPage: NextPageWithLayout = () => {onEditForeignKeyColumnValue={onEditForeignKeyColumnValue}onClosePanel={onClosePanel}theme={ui.themeOption == 'dark' ? 'dark' : 'light'}+ onImportData={onImportData}/><ConfirmationModaldangerdiff --git a/studio/tests/components/Editor/SpreadsheetImport.utils.test.js b/studio/tests/components/Editor/SpreadsheetImport.utils.test.jsindex 061d2944b93..373da64a4e6 100644--- a/studio/tests/components/Editor/SpreadsheetImport.utils.test.js+++ b/studio/tests/components/Editor/SpreadsheetImport.utils.test.js@@ -1,4 +1,4 @@-import { inferColumnType } from 'components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils'+import { inferColumnType } from 'components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.utils'describe('SpreadsheedImport.utils: inferColumnType', () => {test('should default column type to text if no rows to infer from', () => {