mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
fix(plugin-object-viewer): CB-1755 scroll to last position
This commit is contained in:
@@ -15,11 +15,11 @@ export interface IScrollState {
|
||||
|
||||
export function useControlledScroll(element: HTMLDivElement | null, state: IScrollState): void {
|
||||
useEffect(() => {
|
||||
const box = element;
|
||||
|
||||
if (box) {
|
||||
box.scrollTop = state.scrollTop;
|
||||
box.scrollLeft = state.scrollLeft;
|
||||
if (element) {
|
||||
setTimeout(() => {
|
||||
element.scrollTop = state.scrollTop;
|
||||
element.scrollLeft = state.scrollLeft;
|
||||
}, 0);
|
||||
}
|
||||
}, [element, state]);
|
||||
|
||||
|
||||
+9
-5
@@ -8,15 +8,16 @@
|
||||
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useRef } from 'react';
|
||||
import DataGrid, { DataGridHandle } from 'react-data-grid';
|
||||
import DataGrid from 'react-data-grid';
|
||||
import styled, { css } from 'reshadow';
|
||||
|
||||
import { DBObject, NavTreeResource } from '@cloudbeaver/core-app';
|
||||
import { useTable } from '@cloudbeaver/core-blocks';
|
||||
import { IScrollState, useControlledScroll, useTable } from '@cloudbeaver/core-blocks';
|
||||
import { useService } from '@cloudbeaver/core-di';
|
||||
import { Translate } from '@cloudbeaver/core-localization';
|
||||
import type { ObjectPropertyInfo } from '@cloudbeaver/core-sdk';
|
||||
import { useStyles } from '@cloudbeaver/core-theming';
|
||||
import { useTabLocalState } from '@cloudbeaver/core-ui';
|
||||
import { isDefined, TextTools } from '@cloudbeaver/core-utils';
|
||||
|
||||
import { getValue } from '../../helpers';
|
||||
@@ -95,10 +96,14 @@ export const Table = observer<Props>(function Table({
|
||||
objects,
|
||||
truncated,
|
||||
}) {
|
||||
const ref = useRef<DataGridHandle | null>(null);
|
||||
const tableContainer = useRef<HTMLDivElement | null>(null);
|
||||
const navTreeResource = useService(NavTreeResource);
|
||||
const styles = useStyles(style, baseStyles, tableStyles);
|
||||
const tableState = useTable();
|
||||
const tabLocalState = useTabLocalState<IScrollState>(() => ({ scrollTop: 0, scrollLeft: 0 }));
|
||||
|
||||
const scrollBox = (tableContainer.current?.firstChild as HTMLDivElement | undefined) ?? null;
|
||||
useControlledScroll(scrollBox, tabLocalState);
|
||||
|
||||
const baseObject = objects
|
||||
.slice()
|
||||
@@ -126,9 +131,8 @@ export const Table = observer<Props>(function Table({
|
||||
|
||||
return styled(styles)(
|
||||
<TableContext.Provider value={{ tableData, tableState }}>
|
||||
<wrapper>
|
||||
<wrapper ref={tableContainer}>
|
||||
<DataGrid
|
||||
ref={ref}
|
||||
className='cb-metadata-grid-theme'
|
||||
rows={objects}
|
||||
rowKeyGetter={row => row.id}
|
||||
|
||||
Reference in New Issue
Block a user