The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Implement progress bar for loading toasts
Joshen Lim850b085bc39f
diff --git a/studio/components/ui/SparkBar.tsx b/studio/components/ui/SparkBar.tsxindex 1331b8f2ac9..e6b6e43665c 100644--- a/studio/components/ui/SparkBar.tsx+++ b/studio/components/ui/SparkBar.tsx@@ -29,11 +29,11 @@ const SparkBar: FC<Props> = ({return (<div className="flex flex-col w-full">{hasLabels && (- <div className="flex justify-between pb-1">- <span className="text-typography-body-light dark:text-typography-body-dark text-sm">+ <div className="flex justify-between pb-1 space-x-8">+ <span className="text-typography-body-light dark:text-typography-body-dark text-sm truncate">{labelBottom}</span>- <span className="text-typography-body-light dark:text-typography-body-dark text-sm">+ <span className="text-typography-body-light dark:text-typography-body-dark text-sm tabular-nums">{labelTop}</span></div>diff --git a/studio/hooks/misc/useStore.tsx b/studio/hooks/misc/useStore.tsxindex ecbec86bad3..e0eb5fb3542 100644--- a/studio/hooks/misc/useStore.tsx+++ b/studio/hooks/misc/useStore.tsx@@ -1,9 +1,11 @@import { useMonaco } from '@monaco-editor/react'-import { getTheme } from 'components/ui/CodeEditor'import { autorun } from 'mobx'import { createContext, FC, useContext, useEffect } from 'react'import toast from 'react-hot-toast'+import { IRootStore } from 'stores'+import { getTheme } from 'components/ui/CodeEditor'+import SparkBar from 'components/ui/SparkBar'const StoreContext = createContext<IRootStore>(undefined!)@@ -47,7 +49,22 @@ export const StoreProvider: FC<StoreProvider> = ({ children, rootStore }) => {return toast.error(message, { id })case 'loading':if (progress) {- return toast.loading(message, { id })+ return toast.loading(+ <div+ className="flex flex-col space-y-1"+ style={{ minWidth: '200px', maxWidth: '267px' }}+ >+ <SparkBar+ value={progress}+ max={100}+ type="horizontal"+ barClass="bg-green-500"+ labelBottom={message}+ labelTop={`${progress.toFixed(2)}%`}+ />+ </div>,+ { id }+ )} else {return toast.loading(message, { id })}diff --git a/studio/pages/project/[ref]/index.tsx b/studio/pages/project/[ref]/index.tsxindex aee6a5b3043..cf6e38cecc5 100644--- a/studio/pages/project/[ref]/index.tsx+++ b/studio/pages/project/[ref]/index.tsx@@ -47,34 +47,6 @@ const Home: NextPage = () => {{projectName}</Typography.Title></div>- <button- onClick={() => {- ui.setNotification({ category: 'success', message: 'Oh yes' })- }}- >- Success- </button>- <button- onClick={() => {- ui.setNotification({ category: 'error', message: 'Oh no' })- }}- >- Error- </button>- <button- onClick={() => {- ui.setNotification({ category: 'loading', message: 'Oh wait' })- }}- >- Loading- </button>- <button- onClick={() => {- ui.setNotification({ category: 'info', message: 'Oh?' })- }}- >- Information- </button>{IS_PLATFORM && project && (<>{isUndefined(usage) ? (diff --git a/studio/stores/pgmeta/MetaStore.ts b/studio/stores/pgmeta/MetaStore.tsindex 3d8a1e30027..67cc8c7f27b 100644--- a/studio/stores/pgmeta/MetaStore.ts+++ b/studio/stores/pgmeta/MetaStore.ts@@ -302,6 +302,8 @@ export default class MetaStore implements IMetaStore {// Duplicate foreign key constraints overconst relationships = metadata.duplicateTable.relationshipsif (relationships.length > 0) {+ // @ts-ignore, but might need to investigate, sounds bad:+ // Type instantiation is excessively deep and possibly infiniterelationships.map(async (relationship: PostgresRelationship) => {const relation = await this.rootStore.meta.addForeignKey({...relationship,@@ -410,13 +412,12 @@ export default class MetaStore implements IMetaStore {const { error }: any = await this.insertRowsViaSpreadsheet(importContent.file,table,- (progress: any) => {+ (progress: number) => {this.rootStore.ui.setNotification({id: toastId,+ progress,category: 'loading',- message: `Adding ${importContent.rowCount.toLocaleString()} rows to ${- table.name- }... (${progress}%)`,+ message: `Adding ${importContent.rowCount.toLocaleString()} rows to ${table.name}`,})})@@ -444,13 +445,12 @@ export default class MetaStore implements IMetaStore {}} else {// Via text copy and paste- await this.insertTableRows(table, importContent.rows, (progress: any) => {+ await this.insertTableRows(table, importContent.rows, (progress: number) => {this.rootStore.ui.setNotification({id: toastId,+ progress,category: 'loading',- message: `Adding ${importContent.rows.length.toLocaleString()} rows to ${- table.name- }... (${progress}%)`,+ message: `Adding ${importContent.rows.length.toLocaleString()} rows to ${table.name}`,})})@@ -566,7 +566,7 @@ export default class MetaStore implements IMetaStore {async insertRowsViaSpreadsheet(file: any,table: PostgresTable,- onProgressUpdate: (progress: any) => void+ onProgressUpdate: (progress: number) => void) {let chunkNumber = 0let insertError: any = undefined@@ -594,7 +594,7 @@ export default class MetaStore implements IMetaStore {} else {chunkNumber += 1const progress = (chunkNumber * CHUNK_SIZE) / file.size- const progressPercentage = progress > 1 ? 100 : Number((progress * 100).toFixed(2))+ const progressPercentage = progress > 1 ? 100 : progress * 100onProgressUpdate(progressPercentage)parser.resume()}@@ -611,7 +611,7 @@ export default class MetaStore implements IMetaStore {async insertTableRows(table: PostgresTable,rows: any,- onProgressUpdate: (progress: any) => void+ onProgressUpdate: (progress: number) => void) {let insertError = undefinedlet insertProgress = 0@@ -642,7 +642,7 @@ export default class MetaStore implements IMetaStore {if (hasFailedBatch) {break}- onProgressUpdate((insertProgress * 100).toFixed(2))+ onProgressUpdate(insertProgress * 100)}}}diff --git a/studio/types/ui.ts b/studio/types/ui.tsindex 49a2057ff5f..9eeb823a21a 100644--- a/studio/types/ui.ts+++ b/studio/types/ui.ts@@ -3,5 +3,5 @@ export interface Notification {message: string // Readable message for users to understandid?: stringerror?: any // Optional: Any other errors that needs to be logged out in the console- progress?: number // Optional: For loading messages to show a progress bar+ progress?: number // Optional: For loading messages to show a progress bar (Out of 100)}