This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathSideList.js
169 lines (152 loc) · 5.09 KB
/
SideList.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React, { Component } from 'react';
import {connect} from 'react-redux';
import Attachments from './Attachments';
import Referenced from './Referenced';
import DocumentList from '../app/DocumentList';
import onClickOutside from 'react-onclickoutside';
import Tooltips from '../tooltips/Tooltips';
import keymap from '../../keymap.js';
import counterpart from 'counterpart';
class SideList extends Component {
constructor(props) {
super(props);
const {defaultTab} = this.props;
this.state = {
tab: defaultTab ? defaultTab : 0,
tooltipOpen: false
}
}
handleClickOutside = () => {
const {closeSideList} = this.props;
closeSideList();
}
changeTab = (index) => {
this.setState({
tab: index
})
}
renderBody = () => {
const {
windowType, closeOverlays, closeSideList, isSideListShow,
docId, pagination, sorting, viewId
} = this.props;
const {
tab
} = this.state;
switch (tab) {
case 0:
return <DocumentList
type="list"
readonly={true}
defaultViewId={
(viewId && viewId.windowType === windowType) ?
viewId.id : null
}
defaultSort={
(sorting && sorting.windowType === windowType) ?
sorting.sort : null
}
defaultPage={
(pagination && pagination.windowType === windowType) ?
pagination.page : null
}
selected={[docId]}
disconnectFromState={true}
autofocus={true}
{...{windowType, closeOverlays, closeSideList,
isSideListShow}}
/>
case 1:
return <Referenced
{...{windowType, docId}}
/>
case 2:
return <Attachments
{...{windowType, docId}}
/>
}
}
toggleTooltip = (id) => {
this.setState({
tooltipOpen: id
})
}
render() {
const {
tab, tooltipOpen
} = this.state;
const tabs = [
{ icon: 'meta-icon-list',
title: counterpart.translate(
'mainScreen.sideList.documentList.tooltip'
)},
{ icon: 'meta-icon-share',
title: counterpart.translate(
'mainScreen.sideList.referencedDocuments.tooltip'
)},
{ icon: 'meta-icon-attachments',
title: counterpart.translate(
'mainScreen.sideList.attachments.tooltip'
)}
]
return (
<div
ref={(c) => this.panel = c}
className="order-list-panel overlay-shadow order-list-panel-open js-not-unselect"
>
<div className="order-list-panel-body">
<div className="order-list-nav">
{tabs.map((item, index) => <div
key={index}
className={'order-list-btn tooltip-parent ' +
(index === tab ? 'active ' : '')
}
onClick={() => this.changeTab(index)}
onMouseEnter={() =>
this.toggleTooltip(index)
}
onMouseLeave={() =>
this.toggleTooltip()
}
tabIndex={0}
>
<i className={item.icon} />
{ tooltipOpen === index &&
<Tooltips
name={
keymap
.GLOBAL_CONTEXT[
'OPEN_SIDEBAR_MENU_' + index
]
}
action={item.title}
type={''}
/>
}
</div>)}
</div>
<div className="order-list-body">
{this.renderBody()}
</div>
</div>
</div>
)
}
}
function mapStateToProps(state) {
const { listHandler } = state;
const {
sorting,
pagination,
viewId
} = listHandler || {
sorting: {},
pagination: {},
viewId: {}
}
return {
sorting, pagination, viewId
}
}
SideList = connect(mapStateToProps)(onClickOutside(SideList))
export default SideList;