Skip to content

Commit c537055

Browse files
committed
feat: update table view
1 parent f3858d0 commit c537055

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

packages/studio-explore/src/components/TableView/index.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,57 @@
1-
import * as React from 'react';
2-
import { Table } from 'antd';
1+
import React, { useEffect, useState } from 'react';
2+
import { Table, TableProps } from 'antd';
33
import { useContext } from '@graphscope/studio-graph';
44
import { getTable } from './getTableData';
55
interface ITableViewProps {}
66

77
const TableView: React.FunctionComponent<ITableViewProps> = props => {
8-
const { store } = useContext();
9-
const { source } = store;
8+
const { store, updateStore } = useContext();
9+
const { source, selectNodes, data } = store;
1010
const { dataSource, columns } = getTable([...source.nodes]);
11+
const selectKeys = selectNodes.map(item => item.id);
12+
const keys = selectKeys.join('__');
13+
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>(selectKeys);
14+
15+
useEffect(() => {
16+
const ids = keys.split('__');
17+
setSelectedRowKeys(ids);
18+
}, [keys]);
19+
const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
20+
setSelectedRowKeys(newSelectedRowKeys);
21+
updateStore(draft => {
22+
const newSelectNodes = data.nodes.filter(item => {
23+
return newSelectedRowKeys.includes(item.id);
24+
});
25+
draft.selectNodes = newSelectNodes;
26+
draft.nodeStatus = newSelectNodes.reduce((acc, cur) => {
27+
acc[cur.id] = {
28+
selected: true,
29+
};
30+
return acc;
31+
}, {});
32+
});
33+
};
34+
35+
const rowSelection: TableProps<any>['rowSelection'] = {
36+
selectedRowKeys,
37+
onChange: onSelectChange,
38+
};
1139

1240
return (
1341
<div>
1442
<Table
43+
rowSelection={rowSelection}
1544
size="large"
1645
dataSource={dataSource}
1746
columns={columns}
1847
bordered
19-
scroll={{ x: 'max-content' }}
48+
// scroll={{ x: 'max-content' }}
2049
pagination={{
2150
simple: true,
2251
size: 'small',
52+
pageSize: 10,
2353
}}
54+
// scroll={{ x: 10000, y: 800 }}
2455
/>
2556
</div>
2657
);

packages/studio-query/src/components/query-graph/queryStatement.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const queryStatement: IQueryStatement['query'] = async (script: string) =
88
const query_initiation = storage.get<'Server' | 'Browser'>('query_initiation');
99
const query_username = storage.get<string>('query_username');
1010
const query_password = storage.get<string>('query_password');
11+
const query_initiation_service = storage.get<string>('query_initiation_service');
1112
try {
1213
const _params = {
1314
script,
@@ -16,8 +17,8 @@ export const queryStatement: IQueryStatement['query'] = async (script: string) =
1617
username: query_username,
1718
password: query_password,
1819
};
19-
if (query_initiation === 'Server') {
20-
return await fetch('/graph/query', {
20+
if (query_initiation === 'Server' && query_initiation_service) {
21+
return await fetch(query_initiation_service, {
2122
method: 'POST',
2223
headers: {
2324
'Content-Type': 'application/json',

packages/studio-query/src/statement/result/table.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ const GraphTable = ({ nodes, edges }) => {
116116
};
117117
});
118118

119-
return <Table style={{ width: '100%' }} columns={columns} dataSource={result} scroll={{ x: 500 }} />;
119+
return (
120+
<Table
121+
columns={columns}
122+
dataSource={result}
123+
scroll={{ x: 'max-content' }}
124+
pagination={{ simple: true, pageSize: 10, size: 'small' }}
125+
/>
126+
);
120127
};
121128

122129
const TableView: React.FunctionComponent<ITableViewProps> = props => {
@@ -172,12 +179,19 @@ const TableView: React.FunctionComponent<ITableViewProps> = props => {
172179
};
173180
/** table 表格 */
174181
let Content: React.ReactNode;
175-
if (mode === 'table' && table.length !== 0) {
176-
Content = <RowTable data={table} />;
177-
}
178-
if (mode === 'table' && table.length === 0 && raw.records.length !== 0) {
179-
Content = <InteranctiveTable data={raw.records} />;
182+
if (mode === 'table') {
183+
if (nodes.length !== 0) {
184+
Content = <GraphTable nodes={nodes} edges={edges} />;
185+
}
186+
if (table.length !== 0) {
187+
Content = <RowTable data={table} />;
188+
}
189+
//@ts-ignore
190+
if (table.length === 0 && raw.records.length !== 0 && window.GS_ENGINE_TYPE === 'interactive') {
191+
Content = <InteranctiveTable data={raw.records} />;
192+
}
180193
}
194+
181195
return (
182196
<div style={{ overflowX: 'scroll' }}>
183197
<Flex justify="space-between" style={{ padding: '0px 10px 10px 10px' }} align="center">

0 commit comments

Comments
 (0)