Skip to content

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

Midway: Fix for pagination not clearing selected rows

Joshen Lim84262d36e492
diff --git a/studio/components/grid/SupabaseGrid.tsx b/studio/components/grid/SupabaseGrid.tsx
index 4f192d036d5..c740fd78b8a 100644
--- a/studio/components/grid/SupabaseGrid.tsx
+++ b/studio/components/grid/SupabaseGrid.tsx
@@ -1,40 +1,33 @@
-import React from 'react';
-import { createPortal } from 'react-dom';
-import { useMonaco } from '@monaco-editor/react';
-import { DndProvider } from 'react-dnd';
-import { HTML5Backend } from 'react-dnd-html5-backend';
-import { Dictionary, SupabaseGridProps, SupabaseGridRef } from './types';
-import { DataGridHandle } from '@supabase/react-data-grid';
-import { RowContextMenu } from './components/menu';
-import { StoreProvider, useDispatch, useTrackedState } from './store';
-import { fetchCount, fetchPage, refreshPageDebounced } from './utils';
-import { REFRESH_PAGE_IMMEDIATELY, TOTAL_ROWS_RESET } from './constants';
-import { Grid } from './components/grid';
-import { Shortcuts } from './components/common';
-import Header from './components/header';
-import Footer from './components/footer';
-import {
- cleanupProps,
- initTable,
- saveStorageDebounced,
-} from './SupabaseGrid.utils';
+import { useEffect, useState, useRef, forwardRef, useImperativeHandle } from 'react'
+import { createPortal } from 'react-dom'
+import { useMonaco } from '@monaco-editor/react'
+import { DndProvider } from 'react-dnd'
+import { HTML5Backend } from 'react-dnd-html5-backend'
+import { Dictionary, SupabaseGridProps, SupabaseGridRef } from './types'
+import { DataGridHandle } from '@supabase/react-data-grid'
+import { RowContextMenu } from './components/menu'
+import { StoreProvider, useDispatch, useTrackedState } from './store'
+import { fetchCount, fetchPage, refreshPageDebounced } from './utils'
+import { REFRESH_PAGE_IMMEDIATELY, TOTAL_ROWS_RESET } from './constants'
+import { Grid } from './components/grid'
+import { Shortcuts } from './components/common'
+import Header from './components/header'
+import Footer from './components/footer'
+import { cleanupProps, initTable, saveStorageDebounced } from './SupabaseGrid.utils'
/**
* Supabase Grid.
*
* React component to render database table.
*/
-export const SupabaseGrid = React.forwardRef<
- SupabaseGridRef,
- SupabaseGridProps
->((props, ref) => {
- const monaco = useMonaco();
- const _props = cleanupProps(props);
- const { theme } = _props;
+export const SupabaseGrid = forwardRef<SupabaseGridRef, SupabaseGridProps>((props, ref) => {
+ const monaco = useMonaco()
+ const _props = cleanupProps(props)
+ const { theme } = _props
- React.useEffect(() => {
+ useEffect(() => {
if (monaco) {
- const darkTheme = theme && theme === 'dark' ? true : false;
+ const darkTheme = theme && theme === 'dark' ? true : false
monaco.editor.defineTheme('supabase', {
base: 'vs-dark', // can also be vs-dark or hc-black
@@ -47,9 +40,9 @@ export const SupabaseGrid = React.forwardRef<
colors: {
'editor.background': darkTheme ? '#1f1f1f' : '#30313f',
},
- });
+ })
}
- }, [monaco]);
+ }, [monaco])
return (
<StoreProvider>
@@ -57,103 +50,101 @@ export const SupabaseGrid = React.forwardRef<
<SupabaseGridLayout ref={ref} {..._props} />
</DndProvider>
</StoreProvider>
- );
-});
+ )
+})
-const SupabaseGridLayout = React.forwardRef<SupabaseGridRef, SupabaseGridProps>(
- (props, ref) => {
- const { editable, storageRef, gridProps, headerActions } = props;
- const dispatch = useDispatch();
- const state = useTrackedState();
- const gridRef = React.useRef<DataGridHandle>(null);
- const [mounted, setMount] = React.useState(false);
+const SupabaseGridLayout = forwardRef<SupabaseGridRef, SupabaseGridProps>((props, ref) => {
+ const { editable, storageRef, gridProps, headerActions } = props
+ const dispatch = useDispatch()
+ const state = useTrackedState()
+ const gridRef = useRef<DataGridHandle>(null)
+ const [mounted, setMount] = useState(false)
- React.useImperativeHandle(ref, () => ({
- rowAdded(row: Dictionary<any>) {
- dispatch({
- type: 'ADD_NEW_ROW',
- payload: row,
- });
- },
- rowEdited(row: Dictionary<any>, idx: number) {
- dispatch({
- type: 'EDIT_ROW',
- payload: { row, idx },
- });
- },
- }));
+ useImperativeHandle(ref, () => ({
+ rowAdded(row: Dictionary<any>) {
+ dispatch({
+ type: 'ADD_NEW_ROW',
+ payload: row,
+ })
+ },
+ rowEdited(row: Dictionary<any>, idx: number) {
+ dispatch({
+ type: 'EDIT_ROW',
+ payload: { row, idx },
+ })
+ },
+ }))
- React.useEffect(() => {
- if (!mounted) setMount(true);
- }, []);
+ useEffect(() => {
+ if (!mounted) setMount(true)
+ }, [])
- React.useEffect(() => {
- if (state.isInitialComplete && storageRef && state.table) {
- saveStorageDebounced(state, storageRef);
- }
- }, [
- state.table,
- state.isInitialComplete,
- state.gridColumns,
- state.sorts,
- state.filters,
- storageRef,
- ]);
+ useEffect(() => {
+ if (state.isInitialComplete && storageRef && state.table) {
+ saveStorageDebounced(state, storageRef)
+ }
+ }, [
+ state.table,
+ state.isInitialComplete,
+ state.gridColumns,
+ state.sorts,
+ state.filters,
+ storageRef,
+ ])
- React.useEffect(() => {
- if (state.refreshPageFlag == REFRESH_PAGE_IMMEDIATELY) {
- fetchPage(state, dispatch);
- } else if (state.refreshPageFlag != 0) {
- refreshPageDebounced(state, dispatch);
- }
- }, [state.refreshPageFlag]);
+ useEffect(() => {
+ if (state.refreshPageFlag == REFRESH_PAGE_IMMEDIATELY) {
+ fetchPage(state, dispatch)
+ } else if (state.refreshPageFlag != 0) {
+ refreshPageDebounced(state, dispatch)
+ }
+ }, [state.refreshPageFlag])
- React.useEffect(() => {
- if (state.totalRows === TOTAL_ROWS_RESET) {
- fetchCount(state, dispatch);
- }
- }, [state.totalRows]);
+ useEffect(() => {
+ if (state.totalRows === TOTAL_ROWS_RESET) {
+ fetchCount(state, dispatch)
+ }
+ }, [state.totalRows])
- React.useEffect(() => {
- if (!state.metaService) {
- dispatch({
- type: 'INIT_CLIENT',
- payload: { onSqlQuery: props.onSqlQuery },
- });
- dispatch({
- type: 'INIT_CALLBACK',
- payload: { ...props },
- });
- }
- }, [state.metaService]);
+ useEffect(() => {
+ if (!state.metaService) {
+ dispatch({
+ type: 'INIT_CLIENT',
+ payload: { onSqlQuery: props.onSqlQuery },
+ })
+ dispatch({
+ type: 'INIT_CALLBACK',
+ payload: { ...props },
+ })
+ }
+ }, [state.metaService])
- React.useEffect(() => {
- if (!state.metaService) return;
+ useEffect(() => {
+ if (!state.metaService) return
- if (
- !state.table ||
- (typeof props.table == 'string' &&
- state.table!.name != props.table &&
- state.table!.schema != props.schema) ||
- (typeof props.table != 'string' &&
- JSON.stringify(props.table) !== JSON.stringify(state.table))
- ) {
- initTable(props, state, dispatch);
- }
- }, [state.metaService, state.table, props.table, props.schema]);
+ if (
+ !state.table ||
+ (typeof props.table == 'string' &&
+ state.table!.name != props.table &&
+ state.table!.schema != props.schema) ||
+ (typeof props.table != 'string' &&
+ JSON.stringify(props.table) !== JSON.stringify(state.table))
+ ) {
+ initTable(props, state, dispatch)
+ }
+ }, [state.metaService, state.table, props.table, props.schema])
- return (
- <div className="sb-grid">
- <Header
- onAddRow={editable ? props.onAddRow : undefined}
- onAddColumn={editable ? props.onAddColumn : undefined}
- headerActions={headerActions}
- />
- <Grid ref={gridRef} {...gridProps} />
- <Footer />
- <Shortcuts gridRef={gridRef} />
- {mounted && createPortal(<RowContextMenu />, document.body)}
- </div>
- );
- }
-);
+ return (
+ <div className="sb-grid">
+ <Header
+ onAddRow={editable ? props.onAddRow : undefined}
+ onAddColumn={editable ? props.onAddColumn : undefined}
+ headerActions={headerActions}
+ />
+ <Grid ref={gridRef} {...gridProps} />
+ <Footer />
+ <Shortcuts gridRef={gridRef} />
+ {mounted && createPortal(<RowContextMenu />, document.body)}
+ </div>
+ )
+})
diff --git a/studio/components/grid/components/common/ConfirmAlert.tsx b/studio/components/grid/components/common/ConfirmAlert.tsx
index d1e0dd7f03a..294e3916cc0 100644
--- a/studio/components/grid/components/common/ConfirmAlert.tsx
+++ b/studio/components/grid/components/common/ConfirmAlert.tsx
@@ -1,14 +1,14 @@
-import * as React from 'react';
-import { Button, Modal } from '@supabase/ui';
-import { render, unmountComponentAtNode } from 'react-dom';
+import * as React from 'react'
+import { Button, Modal } from '@supabase/ui'
+import { render, unmountComponentAtNode } from 'react-dom'
type ConfirmModalProps = {
- title: string;
- message: string;
- onConfirm?: () => void;
- onAsyncConfirm?: () => Promise<void>;
- variant?: 'danger' | 'warning' | 'success' | undefined;
-};
+ title: string
+ message: string
+ onConfirm?: () => void
+ onAsyncConfirm?: () => Promise<void>
+ variant?: 'danger' | 'warning' | 'success' | undefined
+}
const ConfirmModal: React.FC<ConfirmModalProps> = ({
title,
message,
@@ -16,26 +16,26 @@ const ConfirmModal: React.FC<ConfirmModalProps> = ({
onAsyncConfirm,
variant = 'danger',
}) => {
- const [loading, setLoading] = React.useState(false);
+ const [loading, setLoading] = React.useState(false)
function onCancelClick() {
- if (!loading) onClose();
+ if (!loading) onClose()
}
async function onConfirmClick() {
if (onAsyncConfirm) {
- setLoading(true);
- await onAsyncConfirm();
+ setLoading(true)
+ await onAsyncConfirm()
- onClose();
+ onClose()
} else if (onConfirm) {
- onConfirm();
- onClose();
+ onConfirm()
+ onClose()
}
}
function onClose() {
- removeElement();
+ removeElement()
}
return (
@@ -55,11 +55,7 @@ const ConfirmModal: React.FC<ConfirmModalProps> = ({
<Button type="default" onClick={() => onCancelClick()}>
Cancel
</Button>
- <Button
- type="primary"
- loading={loading}
- onClick={() => onConfirmClick()}
- >
+ <Button type="primary" loading={loading} onClick={() => onConfirmClick()}>
Confirm
</Button>
</div>
@@ -67,32 +63,32 @@ const ConfirmModal: React.FC<ConfirmModalProps> = ({
}
>
<Modal.Content>
- <p className="text-sm text-scale-1100">{message}</p>
+ <p className="text-scale-1100 py-4 text-sm">{message}</p>
</Modal.Content>
</Modal>
- );
-};
+ )
+}
function removeElement() {
- const target = document.getElementById('supabase-ui-confirm-alert');
+ const target = document.getElementById('supabase-ui-confirm-alert')
if (target) {
- unmountComponentAtNode(target);
- target?.parentNode?.removeChild(target);
+ unmountComponentAtNode(target)
+ target?.parentNode?.removeChild(target)
}
}
function createElement(props: ConfirmModalProps) {
- let divTarget = document.getElementById('supabase-ui-confirm-alert');
+ let divTarget = document.getElementById('supabase-ui-confirm-alert')
if (divTarget) {
- render(<ConfirmModal {...props} />, divTarget);
+ render(<ConfirmModal {...props} />, divTarget)
} else {
- divTarget = document.createElement('div');
- divTarget.id = 'supabase-ui-confirm-alert';
- document.body.appendChild(divTarget);
- render(<ConfirmModal {...props} />, divTarget);
+ divTarget = document.createElement('div')
+ divTarget.id = 'supabase-ui-confirm-alert'
+ document.body.appendChild(divTarget)
+ render(<ConfirmModal {...props} />, divTarget)
}
}
export function showConfirmAlert(props: ConfirmModalProps) {
- createElement(props);
+ createElement(props)
}
diff --git a/studio/components/grid/components/footer/pagination/Pagination.tsx b/studio/components/grid/components/footer/pagination/Pagination.tsx
index 4e9a317db08..3cfa45b07fc 100644
--- a/studio/components/grid/components/footer/pagination/Pagination.tsx
+++ b/studio/components/grid/components/footer/pagination/Pagination.tsx
@@ -1,73 +1,106 @@
-import * as React from 'react';
-import AwesomeDebouncePromise from 'awesome-debounce-promise';
-import {
- Button,
- InputNumber,
- Typography,
- IconArrowRight,
- IconArrowLeft,
-} from '@supabase/ui';
-import { DropdownControl } from '../../common';
-import { useDispatch, useTrackedState } from '../../../store';
+import { FC, useState, useEffect, useRef } from 'react'
+import AwesomeDebouncePromise from 'awesome-debounce-promise'
+import { Button, InputNumber, IconArrowRight, IconArrowLeft } from '@supabase/ui'
+import { DropdownControl, showConfirmAlert } from '../../common'
+import { useDispatch, useTrackedState } from '../../../store'
const updatePage = (payload: number, dispatch: (value: unknown) => void) => {
dispatch({
type: 'SET_PAGE',
payload: payload,
- });
-};
-const updatePageDebounced = AwesomeDebouncePromise(updatePage, 550);
+ })
+}
+const updatePageDebounced = AwesomeDebouncePromise(updatePage, 550)
const rowsPerPageOptions = [
{ value: 100, label: '100 rows' },
{ value: 500, label: '500 rows' },
{ value: 1000, label: '1000 rows' },
-];
+]
-type PaginationProps = {};
+type PaginationProps = {}
-const Pagination: React.FC<PaginationProps> = () => {
- const state = useTrackedState();
- const dispatch = useDispatch();
- const [page, setPage] = React.useState(state.page);
- const maxPages = Math.ceil(state.totalRows / state.rowsPerPage);
- const totalPages = state.totalRows > 0 ? maxPages : 1;
+const Pagination: FC<PaginationProps> = () => {
+ const state = useTrackedState()
+ const dispatch = useDispatch()
+ const [page, setPage] = useState(state.page)
+ const maxPages = Math.ceil(state.totalRows / state.rowsPerPage)
+ const totalPages = state.totalRows > 0 ? maxPages : 1
- React.useEffect(() => {
- if (state.page != page) setPage(state.page);
- }, [state.page, page]);
+ useEffect(() => {
+ if (state.page != page) setPage(state.page)
+ }, [state.page, page])
- function onPreviousPage() {
+ // [Joshen] Oddly the methods here seems to be getting stale state
+ console.log('Pagination', state.selectedRows)
+
+ const onPreviousPage = () => {
if (state.page > 1) {
- const previousPage = state.page - 1;
- setPage(previousPage);
- dispatch({ type: 'SET_PAGE', payload: previousPage });
+ if (state.selectedRows.size >= 1) {
+ showConfirmAlert({
+ title: 'Confirm moving to previous page',
+ message: 'The currently selected lines will be deselected, do you want to proceed?',
+ onConfirm: () => {
+ goToPreviousPage()
+ dispatch({
+ type: 'SELECTED_ROWS_CHANGE',
+ payload: { selectedRows: new Set() },
+ })
+ },
+ })
+ } else {
+ goToPreviousPage()
+ }
}
}
- function onNextPage() {
+ const onNextPage = () => {
if (state.page < maxPages) {
- const nextPage = state.page + 1;
- setPage(nextPage);
- dispatch({ type: 'SET_PAGE', payload: nextPage });
+ if (state.selectedRows.size >= 1) {
+ showConfirmAlert({
+ title: 'Confirm moving to next page',
+ message: 'The currently selected lines will be deselected, do you want to proceed?',
+ onConfirm: () => {
+ goToNextPage()
+ dispatch({
+ type: 'SELECTED_ROWS_CHANGE',
+ payload: { selectedRows: new Set() },
+ })
+ },
+ })
+ } else {
+ goToNextPage()
+ }
}
}
+ const goToPreviousPage = () => {
+ const previousPage = state.page - 1
+ setPage(previousPage)
+ dispatch({ type: 'SET_PAGE', payload: previousPage })
+ }
+
+ const goToNextPage = () => {
+ const nextPage = state.page + 1
+ setPage(nextPage)
+ dispatch({ type: 'SET_PAGE', payload: nextPage })
+ }
+
function onPageChange(event: React.ChangeEvent<HTMLInputElement>) {
- const value = event.target.value;
- const pageNum = Number(value);
- setPage(pageNum);
- updatePageDebounced(pageNum, dispatch);
+ const value = event.target.value
+ const pageNum = Number(value)
+ setPage(pageNum)
+ updatePageDebounced(pageNum, dispatch)
}
function onRowsPerPageChange(value: string | number) {
- dispatch({ type: 'SET_ROWS_PER_PAGE', payload: value });
+ dispatch({ type: 'SET_ROWS_PER_PAGE', payload: value })
}
return (
<div className="sb-grid-pagination">
{state.totalRows < 0 ? (
- <Typography.Text>... loading total records</Typography.Text>
+ <p className="text-scale-1100 text-sm">Loading records...</p>
) : (
<>
<Button
@@ -77,7 +110,7 @@ const Pagination: React.FC<PaginationProps> = () => {
onClick={onPreviousPage}
style={{ padding: '3px 10px' }}
/>
- <Typography.Text>Page</Typography.Text>
+ <p className="text-scale-1100 text-sm">Page</p>
<div className="sb-grid-pagination-input-container">
<InputNumber
value={page}
@@ -91,7 +124,7 @@ const Pagination: React.FC<PaginationProps> = () => {
min={1}
/>
</div>
- <Typography.Text>{`of ${totalPages}`}</Typography.Text>
+ <p className="text-scale-1100 text-sm">{`of ${totalPages}`}</p>
<Button
icon={<IconArrowRight />}
type="outline"
@@ -112,12 +145,10 @@ const Pagination: React.FC<PaginationProps> = () => {
style={{ padding: '3px 10px' }}
>{`${state.rowsPerPage} rows`}</Button>
</DropdownControl>
- <Typography.Text>
- {`${state.totalRows.toLocaleString()} records`}
- </Typography.Text>
+ <p className="text-scale-1100 text-sm">{`${state.totalRows.toLocaleString()} records`}</p>
</>
)}
</div>
- );
-};
-export default Pagination;
+ )
+}
+export default Pagination
diff --git a/studio/components/grid/components/grid/Grid.tsx b/studio/components/grid/components/grid/Grid.tsx
index e49d199a13a..b9e774ac1ca 100644
--- a/studio/components/grid/components/grid/Grid.tsx
+++ b/studio/components/grid/components/grid/Grid.tsx
@@ -1,4 +1,4 @@
-import * as React from 'react'
+import { forwardRef } from 'react'
import { memo } from 'react-tracked'
import DataGrid, { DataGridHandle, RowsChangeData } from '@supabase/react-data-grid'
import { IconLoader } from '@supabase/ui'
@@ -12,7 +12,7 @@ function rowKeyGetter(row: SupaRow) {
}
export const Grid = memo(
- React.forwardRef<DataGridHandle, GridProps>(
+ forwardRef<DataGridHandle, GridProps>(
(
{ width, height, containerClass, gridClass, rowClass },
ref: React.Ref<DataGridHandle> | undefined
@@ -23,6 +23,9 @@ export const Grid = memo(
const columnHeaders = state.gridColumns.map((x) => `${x.key}_${x.frozen}`)
const { gridColumns, rows, onError: onErrorFunc } = state
+ // PROBLEM MIGHT BE HERE - MEMO IS NOT LETTING THE GRID RERENDER
+ console.log('Rows', rows)
+
function onColumnResize(index: number, width: number) {
updateColumnResizeDebounced(index, width, dispatch)
}
@@ -52,6 +55,7 @@ export const Grid = memo(
}
function onSelectedRowsChange(selectedRows: ReadonlySet<number>) {
+ console.log('onSelectedRowsChange', selectedRows)
dispatch({
type: 'SELECTED_ROWS_CHANGE',
payload: { selectedRows },
@@ -80,6 +84,7 @@ export const Grid = memo(
</div>
)
}
+
return (
<div
className={containerClass}
diff --git a/studio/components/grid/store/reducers/row.ts b/studio/components/grid/store/reducers/row.ts
index 569aa5a5815..84033ecf1ca 100644
--- a/studio/components/grid/store/reducers/row.ts
+++ b/studio/components/grid/store/reducers/row.ts
@@ -1,19 +1,15 @@
-import update from 'immutability-helper';
-import {
- REFRESH_PAGE_IMMEDIATELY,
- TOTAL_ROWS_INITIAL,
- TOTAL_ROWS_RESET,
-} from '../../constants';
-import { Dictionary, SupaRow } from '../../types';
-import { INIT_ACTIONTYPE } from './base';
+import update from 'immutability-helper'
+import { REFRESH_PAGE_IMMEDIATELY, TOTAL_ROWS_INITIAL, TOTAL_ROWS_RESET } from '../../constants'
+import { Dictionary, SupaRow } from '../../types'
+import { INIT_ACTIONTYPE } from './base'
export interface RowInitialState {
- rows: SupaRow[];
- selectedRows: ReadonlySet<number>;
- selectedCellPosition: { idx: number; rowIdx: number } | null;
- page: number;
- rowsPerPage: number;
- totalRows: number;
+ rows: SupaRow[]
+ selectedRows: ReadonlySet<number>
+ selectedCellPosition: { idx: number; rowIdx: number } | null
+ page: number
+ rowsPerPage: number
+ totalRows: number
}
export const rowInitialState: RowInitialState = {
@@ -23,32 +19,32 @@ export const rowInitialState: RowInitialState = {
page: 1,
rowsPerPage: 100,
totalRows: TOTAL_ROWS_INITIAL,
-};
+}
type ROW_ACTIONTYPE =
| INIT_ACTIONTYPE
| {
- type: 'SELECTED_CELL_CHANGE';
- payload: { position: { idx: number; rowIdx: number } };
+ type: 'SELECTED_CELL_CHANGE'
+ payload: { position: { idx: number; rowIdx: number } }
}
| {
- type: 'SELECTED_ROWS_CHANGE';
- payload: { selectedRows: ReadonlySet<number> };
+ type: 'SELECTED_ROWS_CHANGE'
+ payload: { selectedRows: ReadonlySet<number> }
}
| { type: 'SET_PAGE'; payload: number }
| { type: 'SET_ROWS_PER_PAGE'; payload: number }
| {
- type: 'SET_ROWS';
- payload: { rows: SupaRow[] };
+ type: 'SET_ROWS'
+ payload: { rows: SupaRow[] }
}
| {
- type: 'SET_ROWS_COUNT';
- payload: number;
+ type: 'SET_ROWS_COUNT'
+ payload: number
}
| { type: 'ADD_ROWS'; payload: SupaRow[] }
| { type: 'ADD_NEW_ROW'; payload: Dictionary<any> }
| { type: 'EDIT_ROW'; payload: { row: Dictionary<any>; idx: number } }
- | { type: 'REMOVE_ROWS'; payload: { rowIdxs: number[] } };
+ | { type: 'REMOVE_ROWS'; payload: { rowIdxs: number[] } }
const RowReducer = (state: RowInitialState, action: ROW_ACTIONTYPE) => {
switch (action.type) {
@@ -59,26 +55,26 @@ const RowReducer = (state: RowInitialState, action: ROW_ACTIONTYPE) => {
selectedCellPosition: null,
selectedRows: new Set(),
totalRows: TOTAL_ROWS_RESET,
- };
+ }
}
case 'SELECTED_CELL_CHANGE': {
return {
...state,
selectedCellPosition: action.payload.position,
- };
+ }
}
case 'SELECTED_ROWS_CHANGE': {
return {
...state,
selectedRows: action.payload.selectedRows,
- };
+ }
}
case 'SET_PAGE': {
return {
...state,
page: action.payload,
refreshPageFlag: REFRESH_PAGE_IMMEDIATELY,
- };
+ }
}
case 'SET_ROWS_PER_PAGE': {
return {
@@ -86,58 +82,59 @@ const RowReducer = (state: RowInitialState, action: ROW_ACTIONTYPE) => {
page: 1,
rowsPerPage: action.payload,
refreshPageFlag: REFRESH_PAGE_IMMEDIATELY,
- };
+ }
}
case 'SET_ROWS': {
+ console.log('SET_ROWS', action.payload.rows[0])
return {
...state,
rows: action.payload.rows,
refreshPageFlag: 0,
- };
+ }
}
case 'SET_ROWS_COUNT': {
return {
...state,
totalRows: action.payload,
- };
+ }
}
case 'ADD_ROWS': {
- const totalRows = state.totalRows + action.payload.length;
+ const totalRows = state.totalRows + action.payload.length
return {
...state,
rows: update(state.rows, { $push: action.payload }),
totalRows: totalRows,
- };
+ }
}
case 'ADD_NEW_ROW': {
- const supaRow = { ...action.payload, idx: state.rows.length };
- const totalRows = state.totalRows + 1;
+ const supaRow = { ...action.payload, idx: state.rows.length }
+ const totalRows = state.totalRows + 1
return {
...state,
rows: update(state.rows, { $push: [supaRow] }),
totalRows: totalRows,
- };
+ }
}
case 'EDIT_ROW': {
- const supaRow = { ...action.payload.row, idx: action.payload.idx };
+ const supaRow = { ...action.payload.row, idx: action.payload.idx }
return {
...state,
rows: update(state.rows, {
[action.payload.idx]: { $set: supaRow },
}),
- };
+ }
}
case 'REMOVE_ROWS': {
- const totalRows = state.totalRows - action.payload.rowIdxs.length;
+ const totalRows = state.totalRows - action.payload.rowIdxs.length
return {
...state,
rows: state.rows.filter((x) => !action.payload.rowIdxs.includes(x.idx)),
totalRows: totalRows,
- };
+ }
}
default:
- return state;
+ return state
}
-};
+}
-export default RowReducer;
+export default RowReducer
diff --git a/studio/components/grid/utils/row.ts b/studio/components/grid/utils/row.ts
index 718fa4b1d77..23e2f8943b7 100644
--- a/studio/components/grid/utils/row.ts
+++ b/studio/components/grid/utils/row.ts
@@ -1,40 +1,35 @@
-import AwesomeDebouncePromise from 'awesome-debounce-promise';
-import { InitialStateType } from '../store/reducers';
+import AwesomeDebouncePromise from 'awesome-debounce-promise'
+import { InitialStateType } from '../store/reducers'
-export async function fetchCount(
- state: InitialStateType,
- dispatch: (value: unknown) => void
-) {
- if (!state.rowService) return;
- const { data, error } = await state.rowService.count(state.filters);
+export async function fetchCount(state: InitialStateType, dispatch: (value: unknown) => void) {
+ if (!state.rowService) return
+ const { data, error } = await state.rowService.count(state.filters)
if (error) {
// TODO: handle fetch rows count error
} else {
dispatch({
type: 'SET_ROWS_COUNT',
payload: data ?? 0,
- });
+ })
}
}
-export async function fetchPage(
- state: InitialStateType,
- dispatch: (value: unknown) => void
-) {
- if (!state.rowService) return;
+export async function fetchPage(state: InitialStateType, dispatch: (value: unknown) => void) {
+ if (!state.rowService) return
const { data, error } = await state.rowService.fetchPage(
state.page,
state.rowsPerPage,
state.filters,
state.sorts
- );
+ )
+ console.log('Fetch page', { page: state.page, rowsPerPage: state.rowsPerPage }, data, error)
if (error) {
// TODO: handle fetch rows data error
} else {
dispatch({
type: 'SET_ROWS',
payload: { rows: data?.rows ?? [] },
- });
+ })
}
}
-export const refreshPageDebounced = AwesomeDebouncePromise(fetchPage, 500);
+export const refreshPageDebounced = AwesomeDebouncePromise(fetchPage, 500)