The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Disable pagination buttons while rows are being fetched
Joshen Limd91cf6bd4c00
diff --git a/studio/components/grid/components/footer/pagination/Pagination.tsx b/studio/components/grid/components/footer/pagination/Pagination.tsxindex 96343ee4a1a..1c3ef9f5847 100644--- a/studio/components/grid/components/footer/pagination/Pagination.tsx+++ b/studio/components/grid/components/footer/pagination/Pagination.tsx@@ -1,6 +1,6 @@import { FC, useState, useEffect } from 'react'import AwesomeDebouncePromise from 'awesome-debounce-promise'-import { Button, InputNumber, IconArrowRight, IconArrowLeft } from '@supabase/ui'+import { Button, InputNumber, IconArrowRight, IconArrowLeft, IconLoader } from '@supabase/ui'import { DropdownControl, showConfirmAlert } from '../../common'import { useDispatch, useTrackedState } from '../../../store'@@ -34,6 +34,10 @@ const Pagination: FC<PaginationProps> = () => {// [Joshen] Oddly without this, state.selectedRows will be staleuseEffect(() => {}, [state.selectedRows])+ // [Joshen] Note: I've made pagination buttons disabled while rows are being fetched for now+ // at least until we can send an abort signal to cancel requests if users are mashing the+ // pagination buttons to find the data they want+const onPreviousPage = () => {if (state.page > 1) {if (state.selectedRows.size >= 1) {@@ -106,7 +110,7 @@ const Pagination: FC<PaginationProps> = () => {<Buttonicon={<IconArrowLeft />}type="outline"- disabled={state.page <= 1}+ disabled={state.page <= 1 || state.isLoading}onClick={onPreviousPage}style={{ padding: '3px 10px' }}/>@@ -128,7 +132,7 @@ const Pagination: FC<PaginationProps> = () => {<Buttonicon={<IconArrowRight />}type="outline"- disabled={state.page >= maxPages}+ disabled={state.page >= maxPages || state.isLoading}onClick={onNextPage}style={{ padding: '3px 10px' }}/>@@ -146,6 +150,7 @@ const Pagination: FC<PaginationProps> = () => {>{`${state.rowsPerPage} rows`}</Button></DropdownControl><p className="text-scale-1100 text-sm">{`${state.totalRows.toLocaleString()} records`}</p>+ {state.isLoading && <IconLoader size={14} className="animate-spin" />}</>)}</div>diff --git a/studio/components/grid/store/reducers/row.ts b/studio/components/grid/store/reducers/row.tsindex e54ab2ca9d0..a3de4a47f9f 100644--- a/studio/components/grid/store/reducers/row.ts+++ b/studio/components/grid/store/reducers/row.ts@@ -4,6 +4,7 @@ import { Dictionary, SupaRow } from '../../types'import { INIT_ACTIONTYPE } from './base'export interface RowInitialState {+ isLoading: booleanrows: SupaRow[]selectedRows: ReadonlySet<number>selectedCellPosition: { idx: number; rowIdx: number } | null@@ -13,6 +14,7 @@ export interface RowInitialState {}export const rowInitialState: RowInitialState = {+ isLoading: false,rows: [],selectedRows: new Set(),selectedCellPosition: null,@@ -45,6 +47,7 @@ type ROW_ACTIONTYPE =| { type: 'ADD_NEW_ROW'; payload: Dictionary<any> }| { type: 'EDIT_ROW'; payload: { row: Dictionary<any>; idx: number } }| { type: 'REMOVE_ROWS'; payload: { rowIdxs: number[] } }+ | { type: 'SET_IS_LOADING'; payload: { isLoading: boolean } }const RowReducer = (state: RowInitialState, action: ROW_ACTIONTYPE) => {switch (action.type) {@@ -131,6 +134,12 @@ const RowReducer = (state: RowInitialState, action: ROW_ACTIONTYPE) => {totalRows: totalRows,}}+ case 'SET_IS_LOADING': {+ return {+ ...state,+ isLoading: action.payload.isLoading,+ }+ }default:return state}diff --git a/studio/components/grid/utils/row.ts b/studio/components/grid/utils/row.tsindex 1e60e115180..b0c45f8f270 100644--- a/studio/components/grid/utils/row.ts+++ b/studio/components/grid/utils/row.ts@@ -16,6 +16,7 @@ export async function fetchCount(state: InitialStateType, dispatch: (value: unknexport async function fetchPage(state: InitialStateType, dispatch: (value: unknown) => void) {if (!state.rowService) return+ dispatch({ type: 'SET_IS_LOADING', payload: { isLoading: true } })const { data, error } = await state.rowService.fetchPage(state.page,state.rowsPerPage,@@ -30,5 +31,6 @@ export async function fetchPage(state: InitialStateType, dispatch: (value: unknopayload: { rows: data?.rows ?? [] },})}+ dispatch({ type: 'SET_IS_LOADING', payload: { isLoading: false } })}export const refreshPageDebounced = AwesomeDebouncePromise(fetchPage, 500)