Skip to content

Commit 752dd4d

Browse files
committed
feat: update code
1 parent efe811b commit 752dd4d

File tree

11 files changed

+251
-96
lines changed

11 files changed

+251
-96
lines changed

packages/studio-explore/src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const Explore: React.FunctionComponent<ExploreProps> = props => {
122122
<FetchGraph />
123123
<Placeholder />
124124
<Loading />
125-
<PropertiesPanel />
125+
<PropertiesPanel style={{ right: '12px' }} />
126126
<FloatTabs
127127
searchbar={<Searchbar />}
128128
direction="vertical"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const Searchbar: React.FunctionComponent<ISearchbarProps> = props => {
174174
});
175175
const data = await getService<IQuerySearch>('querySearch')({
176176
config: breadcrumb,
177-
value: '',
177+
value: state.words,
178178
});
179179

180180
updateStore(draft => {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React, { useState } from 'react';
2+
import { Button, Popover, Select } from 'antd';
3+
import { ControlOutlined } from '@ant-design/icons';
4+
import { Utils } from '@graphscope/studio-components';
5+
import { useContext } from '@graphscope/studio-graph';
6+
import { getTable } from './getTableData';
7+
interface IAdjustColumnsProps {
8+
onChange: (columnIds: string[]) => void;
9+
}
10+
11+
export function getTableColumns(columnIds: string[]) {
12+
return columnIds.map(key => {
13+
return {
14+
title: key,
15+
dataIndex: key,
16+
key: key,
17+
sorter: (a, b) => a[key] - b[key],
18+
};
19+
});
20+
}
21+
const AdjustColumns: React.FunctionComponent<IAdjustColumnsProps> = props => {
22+
const { store } = useContext();
23+
const { source } = store;
24+
const { columns } = getTable(source.nodes);
25+
const { onChange } = props;
26+
27+
const defaultColumnIds =
28+
(Utils.storage.get('explore_table_view_column_ids') as string[]) || columns.map(item => item.key);
29+
const [state, setState] = useState({
30+
columnIds: defaultColumnIds,
31+
tableColumns: getTableColumns(defaultColumnIds),
32+
});
33+
const { columnIds, tableColumns } = state;
34+
const onChangeColumns = value => {
35+
setState(preState => {
36+
return {
37+
...preState,
38+
columnIds: value,
39+
tableColumns: getTableColumns(value),
40+
};
41+
});
42+
Utils.storage.set('explore_table_view_column_ids', value);
43+
if (onChange) {
44+
onChange(value);
45+
}
46+
};
47+
48+
const options = columns.map(item => {
49+
return {
50+
label: item.key,
51+
value: item.key,
52+
};
53+
});
54+
55+
return (
56+
<Popover
57+
title="Select Display Columns"
58+
arrow={false}
59+
placement="bottomRight"
60+
style={{ padding: '0px' }}
61+
content={
62+
<Select
63+
// maxTagCount="responsive"
64+
mode="multiple"
65+
allowClear
66+
style={{ width: '300px' }}
67+
variant="borderless"
68+
placeholder="Adjust Table Columns"
69+
value={columnIds}
70+
onChange={onChangeColumns}
71+
options={options}
72+
/>
73+
}
74+
>
75+
<Button style={{ padding: '12px 0px' }} type="text" icon={<ControlOutlined />}></Button>
76+
</Popover>
77+
);
78+
};
79+
80+
export default React.memo(AdjustColumns);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react';
2+
import { Button, Dropdown, Typography, MenuProps } from 'antd';
3+
import { MoreOutlined, PlayCircleOutlined } from '@ant-design/icons';
4+
import { useContext } from '@graphscope/studio-graph';
5+
interface ISaveSelectedProps {}
6+
7+
const SaveSelected: React.FunctionComponent<ISaveSelectedProps> = props => {
8+
const { store, updateStore } = useContext();
9+
const { selectNodes } = store;
10+
11+
const handleChangeData = () => {
12+
updateStore(draft => {
13+
draft.data.nodes = selectNodes;
14+
const matchIds = selectNodes.map(item => item.id);
15+
const newEdges = draft.data.edges.filter(item => {
16+
const { source, target } = item;
17+
const matchSource = matchIds.indexOf(typeof source === 'object' ? source.id : source) !== -1;
18+
const matchTarget = matchIds.indexOf(typeof target === 'object' ? target.id : target) !== -1;
19+
return matchSource && matchTarget;
20+
});
21+
22+
draft.data.edges = newEdges;
23+
draft.source.nodes = selectNodes;
24+
draft.source.edges = newEdges;
25+
});
26+
};
27+
const items: MenuProps['items'] = [
28+
{
29+
key: 'save',
30+
label: <Typography.Text onClick={handleChangeData}>Save Selected Nodes</Typography.Text>,
31+
icon: <PlayCircleOutlined />,
32+
},
33+
];
34+
return (
35+
<Dropdown menu={{ items }} placement="bottomRight">
36+
<Button type="text" icon={<MoreOutlined />}></Button>
37+
</Dropdown>
38+
);
39+
};
40+
41+
export default SaveSelected;

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

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import React, { useEffect, useState } from 'react';
2-
import { Table, TableProps, Flex, Typography, Button, Popover, Select } from 'antd';
2+
import { Table, Flex, Typography, Space } from 'antd';
33
import { useContext } from '@graphscope/studio-graph';
44
import { getTable } from './getTableData';
5-
import { ControlOutlined } from '@ant-design/icons';
5+
6+
import SaveSelected from './SaveSelected';
7+
import { getTableColumns } from './AdjustColumns';
8+
import AdjustColumns from './AdjustColumns';
69
import { Utils } from '@graphscope/studio-components';
710
interface ITableViewProps {}
811

9-
const TableView: React.FunctionComponent<ITableViewProps> = props => {
12+
const useRowSelection = () => {
1013
const { store, updateStore } = useContext();
11-
const { source, selectNodes, data } = store;
12-
const { dataSource, columns } = getTable([...source.nodes]);
14+
const { selectNodes, data } = store;
1315
const selectKeys = selectNodes.map(item => item.id);
1416
const keys = selectKeys.join('__');
1517
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>(selectKeys);
16-
const [state, setState] = useState({
17-
columnIds: (Utils.storage.get('explore_table_view_column_ids') as string[]) || columns.map(item => item.key),
18-
});
19-
const { columnIds } = state;
2018

2119
useEffect(() => {
2220
const ids = keys.split('__');
@@ -37,59 +35,49 @@ const TableView: React.FunctionComponent<ITableViewProps> = props => {
3735
}, {});
3836
});
3937
};
40-
41-
const rowSelection: TableProps<any>['rowSelection'] = {
38+
return {
39+
onSelectChange,
4240
selectedRowKeys,
43-
onChange: onSelectChange,
4441
};
42+
};
43+
44+
const TableView: React.FunctionComponent<ITableViewProps> = props => {
45+
const { store } = useContext();
46+
const { selectNodes, data, source } = store;
47+
const { dataSource, columns } = getTable(source.nodes);
48+
const { selectedRowKeys, onSelectChange } = useRowSelection();
49+
50+
const [state, setState] = useState({
51+
columnIds: (Utils.storage.get('explore_table_view_column_ids') as string[]) || columns.map(item => item.key),
52+
});
53+
const { columnIds } = state;
4554

46-
const content = <div>ddd</div>;
4755
const handleChangeColumns = value => {
48-
console.log('value', value);
4956
setState(preState => {
5057
return {
5158
...preState,
5259
columnIds: value,
5360
};
5461
});
55-
Utils.storage.set('explore_table_view_column_ids', value);
5662
};
57-
const options = columns.map(item => {
58-
return {
59-
label: item.key,
60-
value: item.key,
61-
};
62-
});
63-
const tableColumns = columnIds.map(key => {
64-
return {
65-
title: key,
66-
dataIndex: key,
67-
key: key,
68-
sorter: (a, b) => a[key] - b[key],
69-
};
70-
});
63+
const tableColumns = getTableColumns(columnIds);
7164

7265
return (
7366
<Flex vertical gap={12}>
7467
<Flex justify="space-between" align="center">
75-
<Typography.Text type="secondary">{data.nodes.length + data.edges.length} records</Typography.Text>
76-
<Select
77-
suffixIcon={<ControlOutlined />}
78-
maxTagCount="responsive"
79-
mode="multiple"
80-
allowClear
81-
style={{ width: '160px' }}
82-
placeholder="Adjust Columns"
83-
value={columnIds}
84-
onChange={handleChangeColumns}
85-
options={options}
86-
/>
87-
{/* <Popover placement="bottomRight" title={'x'} content={content} trigger="click">
88-
<Button icon={<SettingOutlined />} type="text"></Button>
89-
</Popover> */}
68+
<Typography.Text type="secondary">
69+
Total {data.nodes.length} node items, {selectNodes.length} selected.
70+
</Typography.Text>
71+
<Space size={0}>
72+
<AdjustColumns onChange={handleChangeColumns} />
73+
<SaveSelected />
74+
</Space>
9075
</Flex>
9176
<Table
92-
rowSelection={rowSelection}
77+
rowSelection={{
78+
selectedRowKeys,
79+
onChange: onSelectChange,
80+
}}
9381
size="large"
9482
dataSource={dataSource}
9583
columns={tableColumns}
@@ -100,7 +88,6 @@ const TableView: React.FunctionComponent<ITableViewProps> = props => {
10088
size: 'small',
10189
pageSize: 10,
10290
}}
103-
// scroll={{ x: 10000, y: 800 }}
10491
/>
10592
</Flex>
10693
);

packages/studio-graph/src/components/ClearStatus/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ const ClearStatus: React.FunctionComponent<IClearStatatusProps> = props => {
99
useEffect(() => {
1010
const handleClear = e => {
1111
updateStore(draft => {
12+
const isEmpty =
13+
Object.keys(draft.nodeStatus).length === 0 &&
14+
Object.keys(draft.edgeStatus).length === 0 &&
15+
draft.selectNodes.length === 0 &&
16+
draft.selectEdges.length === 0;
17+
18+
if (isEmpty) {
19+
return;
20+
}
1221
draft.nodeStatus = {};
1322
draft.edgeStatus = {};
14-
draft.focusNodes = [];
23+
// draft.focusNodes = [];
1524
draft.selectNodes = [];
1625
draft.selectEdges = [];
1726
});

packages/studio-graph/src/components/PropertiesPanel/PropertiesTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface IPropertiesTableProps {
99
style?: React.CSSProperties;
1010
title?: string;
1111
}
12-
import { width } from './index';
12+
1313
const PropertiesTable: React.FunctionComponent<IPropertiesTableProps> = props => {
1414
const { data, style = {}, title } = props;
1515
const { dataSource, columns } = getTable(data);

packages/studio-graph/src/components/PropertiesPanel/PropertyInfo.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,21 @@ import { Utils } from '@graphscope/studio-components';
99
interface IPropertyInfoProps {
1010
style?: React.CSSProperties;
1111
noTitle?: boolean;
12+
data: NodeData | EdgeData;
1213
}
1314

1415
const PropertyInfo: React.FunctionComponent<IPropertyInfoProps> = props => {
15-
const { style, noTitle } = props;
16+
const { style, noTitle, data } = props;
1617
const { store, updateStore } = useContext();
17-
18-
const { nodeStyle, selectNodes, selectEdges } = store;
19-
20-
if (selectEdges.length === 0 && selectNodes.length === 0) {
21-
return null;
22-
}
23-
24-
const node = selectNodes[0];
25-
const edge = selectEdges[0];
26-
const type = node ? 'node' : 'edge';
27-
const data = node ? node : edge;
18+
const { nodeStyle } = store;
2819

2920
const { id, label, properties = {} } = data as EdgeData;
3021
//@ts-ignore
3122
const source = data.source && data.source.id;
3223
//@ts-ignore
3324
const target = data.target && data.target.id;
3425
const elementStyle = nodeStyle[id] || nodeStyle[String(label)];
26+
const type = source && target ? 'edge' : 'node';
3527
const title = type === 'node' ? 'Vertex Properties' : 'Edge Properties';
3628

3729
const onChange = val => {

0 commit comments

Comments
 (0)