Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit 5f276d9

Browse files
committed
Various UI improvements
- Add sorter - Init pagination correctly - Cleanup store handling in objectStorage - Handle window resize correctly (longhorn/longhorn#7036) - Stop event propagation in action menu (longhorn/longhorn#7032) Signed-off-by: Volker Theile <[email protected]>
1 parent f5230a0 commit 5f276d9

File tree

4 files changed

+90
-16
lines changed

4 files changed

+90
-16
lines changed

src/models/objectStore.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { listObjectStores, getObjectStore, createObjectStore, deleteObjectStore
22
import { wsChanges, updateState } from '../utils/websocket'
33
import queryString from 'query-string'
44
import { enableQueryData } from '../utils/dataDependency'
5+
import { getSorter, saveSorter } from '../utils/store'
56

67
export default {
78
namespace: 'objectstorage',
89
state: {
910
ws: null,
1011
data: [],
11-
selected: {},
1212
resourceType: 'objectstore',
1313
socketStatus: 'closed',
14+
sorter: getSorter('objectstoreList.sorter'),
1415
},
1516
subscriptions: {
1617
setup({ dispatch, history }) {
@@ -82,5 +83,9 @@ export default {
8283
updateWs(state, action) {
8384
return { ...state, ws: action.payload }
8485
},
86+
updateSorter(state, action) {
87+
saveSorter('objectstoreList.sorter', action.payload)
88+
return { ...state, sorter: action.payload }
89+
},
8590
},
8691
}

src/routes/objectStorage/ObjectStoreActions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const confirm = Modal.confirm
88

99
function actions({ selected, deleteObjectStore, editObjectStore, administrateObjectStore }) {
1010
const handleMenuClick = (event, record) => {
11+
// Stop event propagation, otherwise the click will be processed by
12+
// other UI components, e.g. the table row below the clicked menu,
13+
// which is not wanted in that case.
14+
event.domEvent.stopPropagation()
15+
1116
switch (event.key) {
1217
case 'delete':
1318
confirm({

src/routes/objectStorage/ObjectStoreList.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types'
33
import { Table, Tooltip } from 'antd'
44
import { pagination } from '../../utils/page'
55
import ObjectStoreActions from './ObjectStoreActions'
6+
import { sortTable } from '../../utils/sort'
7+
import { setSortOrder } from '../../utils/store'
68

79
function list({
810
dataSource,
@@ -12,6 +14,9 @@ function list({
1214
editObjectStore,
1315
administrateObjectStore,
1416
deleteObjectStore,
17+
onSorterChange,
18+
sorter,
19+
onRowClick,
1520
}) {
1621
const actionsProps = {
1722
editObjectStore,
@@ -35,6 +40,7 @@ function list({
3540
dataIndex: 'state',
3641
key: 'state',
3742
width: 160,
43+
sorter: (a, b) => sortTable(a, b, 'state'),
3844
render: (text, record) => {
3945
const tooltip = `Object Store ${record.name} is ${record.state}`
4046
const colormap = storeStateColorMap[record.state] || { color: '', bg: '' }
@@ -52,6 +58,7 @@ function list({
5258
dataIndex: 'name',
5359
key: 'name',
5460
width: 200,
61+
sorter: (a, b) => sortTable(a, b, 'name'),
5562
render: (text, record) => {
5663
return (
5764
<div>{record.name}</div>
@@ -82,17 +89,21 @@ function list({
8289
},
8390
]
8491

92+
setSortOrder(columns, sorter)
93+
8594
return (
8695
<div id="objectStoreTable" style={{ flex: 1, height: '1px', overflow: 'hidden' }}>
8796
<Table
8897
className="common-table-class"
8998
bordered={false}
9099
columns={columns}
100+
onChange={(p, f, s) => onSorterChange(s)}
91101
rowSelection={rowSelection}
92102
dataSource={dataSource}
93103
loading={loading}
104+
onRowClick={onRowClick}
94105
simple
95-
pagination={pagination}
106+
pagination={pagination('objectStoreSize')}
96107
rowKey={record => record.id}
97108
scroll={{ x: 970, y: dataSource.length > 0 ? height : 1 }}
98109
/>
@@ -108,6 +119,9 @@ list.propTypes = {
108119
editObjectStore: PropTypes.func,
109120
administrateObjectStore: PropTypes.func,
110121
deleteObjectStore: PropTypes.func,
122+
sorter: PropTypes.object,
123+
onSorterChange: PropTypes.func,
124+
onRowClick: PropTypes.func,
111125
}
112126

113127
export default list

src/routes/objectStorage/index.js

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,50 @@ class ObjectStore extends React.Component {
2222
createModalKey: Math.random(),
2323
editModalVisible: false,
2424
editModalKey: Math.random(),
25+
commandKeyDown: false,
2526
}
2627
}
2728

2829
componentDidMount() {
29-
let height = document.getElementById('objectStoreTable').offsetHeight - C.ContainerMarginHeight
30+
this.onResize()
31+
window.addEventListener('resize', this.onResize)
32+
window.addEventListener('keydown', this.onKeyDown)
33+
window.addEventListener('keyup', this.onKeyUp)
34+
}
35+
36+
componentWillUnmount() {
37+
window.removeEventListener('resize', this.onResize)
38+
window.removeEventListener('keydown', this.onKeyDown)
39+
window.removeEventListener('keyup', this.onKeyUp)
40+
}
41+
42+
onKeyUp = () => {
3043
this.setState({
31-
height,
44+
...this.state,
45+
commandKeyDown: false,
3246
})
33-
window.onresize = () => {
34-
height = document.getElementById('objectStoreTable').offsetHeight - C.ContainerMarginHeight
47+
}
48+
49+
onKeyDown = (e) => {
50+
if ((e.keyCode === 91 || e.keyCode === 17) && !this.state.commandKeyDown) {
3551
this.setState({
36-
height,
52+
...this.state,
53+
commandKeyDown: true,
3754
})
38-
this.props.dispatch({ type: 'app/changeNavbar' })
3955
}
4056
}
4157

58+
onResize = () => {
59+
const height = document.getElementById('objectStoreTable').offsetHeight - C.ContainerMarginHeight
60+
this.setState({
61+
height,
62+
})
63+
}
64+
4265
showCreateModal = () => {
4366
this.setState({
4467
...this.state,
45-
selected: {},
68+
selectedRows: [],
4669
createModalVisible: true,
4770
createModalKey: Math.random(),
4871
})
@@ -51,7 +74,7 @@ class ObjectStore extends React.Component {
5174
render() {
5275
const me = this
5376
const { dispatch, loading, location } = this.props
54-
const { data } = this.props.objectstorage
77+
const { data, sorter } = this.props.objectstorage
5578
const { field, value } = queryString.parse(this.props.location.search)
5679

5780
const settings = this.props.setting.data
@@ -113,7 +136,7 @@ class ObjectStore extends React.Component {
113136
}
114137

115138
const editModalProps = {
116-
selected: this.state.selected,
139+
selected: this.state.selectedRows[0],
117140
visible: this.state.editModalVisible,
118141
onCancel() {
119142
me.setState({
@@ -142,14 +165,14 @@ class ObjectStore extends React.Component {
142165
onChange(_, records) {
143166
me.setState({
144167
...me.state,
145-
selectedRows: records,
168+
selectedRows: [...records],
146169
})
147170
},
148171
},
149172
editObjectStore: (record) => {
150-
this.setState({
151-
...this.state,
152-
selected: record,
173+
me.setState({
174+
...me.state,
175+
selectedRows: [record],
153176
editModalVisible: true,
154177
editModalKey: Math.random(),
155178
})
@@ -165,6 +188,33 @@ class ObjectStore extends React.Component {
165188
payload: record,
166189
})
167190
},
191+
onSorterChange: (s) => {
192+
dispatch({
193+
type: 'objectstorage/updateSorter',
194+
payload: { field: s.field, order: s.order, columnKey: s.columnKey },
195+
})
196+
},
197+
sorter,
198+
onRowClick: (record) => {
199+
let selecteRowByClick = [record]
200+
if (me.state.commandKeyDown) {
201+
me.state.selectedRows.forEach((item) => {
202+
if (selecteRowByClick.every((ele) => {
203+
return ele.id !== item.id
204+
})) {
205+
selecteRowByClick.push(item)
206+
} else {
207+
selecteRowByClick = selecteRowByClick.filter((ele) => {
208+
return ele.id !== item.id
209+
})
210+
}
211+
})
212+
}
213+
me.setState({
214+
...me.state,
215+
selectedRows: [...selecteRowByClick],
216+
})
217+
},
168218
}
169219

170220
const filterProps = {
@@ -197,7 +247,7 @@ class ObjectStore extends React.Component {
197247
payload: record,
198248
callback: () => {
199249
me.setState({
200-
...this.state,
250+
...me.state,
201251
selectedRows: [],
202252
})
203253
},

0 commit comments

Comments
 (0)