-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathDataViewerPanel.tsx
More file actions
77 lines (67 loc) · 2.36 KB
/
DataViewerPanel.tsx
File metadata and controls
77 lines (67 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { observer } from 'mobx-react-lite';
import { useCallback } from 'react';
import { TextPlaceholder, useAutoLoad, useTranslate } from '@cloudbeaver/core-blocks';
import type { ObjectPagePanelComponent } from '@cloudbeaver/plugin-object-viewer';
import type { IDataViewerPageState } from '../IDataViewerPageState.js';
import { TableViewerLoader } from '../TableViewer/TableViewerLoader.js';
import classes from './DataViewerPanel.module.css';
import { useDataViewerPanel } from './useDataViewerPanel.js';
export const DataViewerPanel: ObjectPagePanelComponent<IDataViewerPageState> = observer(function DataViewerPanel({ tab, page }) {
const translate = useTranslate();
const panel = useDataViewerPanel(tab);
const pageState = page.getState(tab);
const handlePresentationChange = useCallback(
(presentationId: string) => {
const pageState = page.getState(tab);
if (!pageState) {
page.setState(tab, {
presentationId,
resultIndex: 0,
valuePresentationId: null,
persistedState: {},
});
} else {
pageState.presentationId = presentationId;
}
},
[page, tab],
);
const handleValuePresentationChange = useCallback(
(valuePresentationId: string | null) => {
const pageState = page.getState(tab);
if (!pageState) {
page.setState(tab, {
presentationId: '',
resultIndex: 0,
valuePresentationId,
persistedState: {},
});
} else {
pageState.valuePresentationId = valuePresentationId;
}
},
[page, tab],
);
useAutoLoad(DataViewerPanel, panel);
if (!tab.handlerState.tableId) {
return <TextPlaceholder>{translate('data_viewer_model_not_loaded')}</TextPlaceholder>;
}
return (
<TableViewerLoader
className={classes['tableViewerLoader']}
tableId={tab.handlerState.tableId}
resultIndex={pageState?.resultIndex}
presentationId={pageState?.presentationId}
valuePresentationId={pageState?.valuePresentationId}
onPresentationChange={handlePresentationChange}
onValuePresentationChange={handleValuePresentationChange}
/>
);
});