|
@@ -6,16 +6,8 @@ import { translate } from 'react-i18next'
|
6
|
6
|
import appFactory from '../appFactory.js'
|
7
|
7
|
import WorkspaceListItem from '../component/Sidebar/WorkspaceListItem.jsx'
|
8
|
8
|
import {
|
9
|
|
- setAppList,
|
10
|
|
- setContentTypeList,
|
11
|
|
- setWorkspaceListIsOpenInSidebar,
|
12
|
|
- updateWorkspaceFilter,
|
13
|
|
- updateWorkspaceListData
|
|
9
|
+ setWorkspaceListIsOpenInSidebar
|
14
|
10
|
} from '../action-creator.sync.js'
|
15
|
|
-import {
|
16
|
|
- getAppList, getContentTypeList,
|
17
|
|
- getWorkspaceList
|
18
|
|
-} from '../action-creator.async.js'
|
19
|
11
|
import { PAGE, workspaceConfig } from '../helper.js'
|
20
|
12
|
|
21
|
13
|
const qs = require('query-string')
|
|
@@ -25,6 +17,7 @@ class Sidebar extends React.Component {
|
25
|
17
|
super(props)
|
26
|
18
|
this.state = {
|
27
|
19
|
sidebarClose: false,
|
|
20
|
+ workspaceListLoaded: false,
|
28
|
21
|
workspaceIdInUrl: props.match && props.match.params.idws ? parseInt(props.match.params.idws) : null
|
29
|
22
|
}
|
30
|
23
|
|
|
@@ -40,62 +33,26 @@ class Sidebar extends React.Component {
|
40
|
33
|
}
|
41
|
34
|
}
|
42
|
35
|
|
43
|
|
- componentDidMount () {
|
44
|
|
- // console.log('Sidebar Did Mount', this.props)
|
45
|
|
- this.loadAppConfigAndWorkspaceList()
|
46
|
|
- }
|
47
|
|
-
|
48
|
36
|
componentDidUpdate (prevProps, prevState) {
|
49
|
37
|
const { props } = this
|
50
|
38
|
|
51
|
|
- // console.log('%c<Sidebar> Did Update', 'color: #c17838')
|
52
|
|
- if (!props.match || props.match.params.idws === undefined || isNaN(props.match.params.idws)) return
|
53
|
|
-
|
54
|
|
- const newWorkspaceId = parseInt(props.match.params.idws)
|
55
|
|
- if (prevState.workspaceIdInUrl !== newWorkspaceId) this.setState({workspaceIdInUrl: newWorkspaceId})
|
56
|
|
- }
|
57
|
|
-
|
58
|
|
- loadAppConfigAndWorkspaceList = async () => {
|
59
|
|
- const { workspaceIdInUrl } = this.state
|
60
|
|
- const { user, dispatch } = this.props
|
61
|
|
-
|
62
|
|
- if (user.user_id !== -1) {
|
63
|
|
- const fetchGetAppList = await dispatch(getAppList(user))
|
64
|
|
- if (fetchGetAppList.status === 200) dispatch(setAppList(fetchGetAppList.json))
|
65
|
|
-
|
66
|
|
- const fetchGetContentTypeList = await dispatch(getContentTypeList(user))
|
67
|
|
- if (fetchGetContentTypeList.status === 200) dispatch(setContentTypeList(fetchGetContentTypeList.json))
|
68
|
|
-
|
69
|
|
- const fetchGetWorkspaceList = await dispatch(getWorkspaceList(user))
|
|
39
|
+ if (!this.shouldDisplaySidebar()) return
|
70
|
40
|
|
71
|
|
- if (fetchGetWorkspaceList.status === 200) {
|
72
|
|
- dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
|
73
|
|
- dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].workspace_id, true))
|
74
|
|
- }
|
|
41
|
+ // console.log('%c<Sidebar> Did Update', 'color: #c17838')
|
|
42
|
+ if (props.match && props.match.params.idws !== undefined && !isNaN(props.match.params.idws)) {
|
|
43
|
+ const newWorkspaceId = parseInt(props.match.params.idws)
|
|
44
|
+ if (prevState.workspaceIdInUrl !== newWorkspaceId) this.setState({workspaceIdInUrl: newWorkspaceId})
|
75
|
45
|
}
|
76
|
46
|
}
|
77
|
47
|
|
78
|
|
- handleClickWorkspace = (idWs, newIsOpenInSidebar) => this.props.dispatch(setWorkspaceListIsOpenInSidebar(idWs, newIsOpenInSidebar))
|
79
|
|
-
|
80
|
|
- handleClickAllContent = idWs => {
|
81
|
|
- this.props.dispatch(updateWorkspaceFilter([]))
|
82
|
|
-
|
83
|
|
- this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(idWs))
|
|
48
|
+ shouldDisplaySidebar = () => {
|
|
49
|
+ const pageWithoutSidebar = [PAGE.LOGIN]
|
|
50
|
+ return !pageWithoutSidebar.includes(this.props.location.pathname)
|
84
|
51
|
}
|
85
|
52
|
|
86
|
|
- // @DEPRECATED
|
87
|
|
- // not used, right now, link on sidebar filters is a <Link>
|
88
|
|
- handleClickContentFilter = (idWs, filter) => {
|
89
|
|
- const { workspace, history } = this.props
|
90
|
|
-
|
91
|
|
- const newFilter = workspace.filter.includes(filter) ? [] : [filter] // use an array to allow multiple filters (NYI)
|
92
|
|
-
|
93
|
|
- history.push(`${PAGE.WORKSPACE.CONTENT_LIST(idWs)}?type=${newFilter.join(';')}`) // workspace.filter gets updated on react redraw from match.params
|
|
53
|
+ handleClickWorkspace = (idWs, newIsOpenInSidebar) => this.props.dispatch(setWorkspaceListIsOpenInSidebar(idWs, newIsOpenInSidebar))
|
94
|
54
|
|
95
|
|
- // obviously, it's ugly to use custom event to tell WorkspaceContentList to refresh, but since WorkspaceContentList
|
96
|
|
- // will end up being an App, it'll have to be that way. So it's fine
|
97
|
|
- GLOBAL_dispatchEvent({ type: 'refreshContentList', data: {} })
|
98
|
|
- }
|
|
55
|
+ handleClickAllContent = idWs => this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(idWs))
|
99
|
56
|
|
100
|
57
|
handleClickToggleSidebar = () => this.setState(prev => ({sidebarClose: !prev.sidebarClose}))
|
101
|
58
|
|
|
@@ -105,6 +62,8 @@ class Sidebar extends React.Component {
|
105
|
62
|
const { sidebarClose, workspaceIdInUrl } = this.state
|
106
|
63
|
const { activeLang, workspaceList, t } = this.props
|
107
|
64
|
|
|
65
|
+ if (!this.shouldDisplaySidebar()) return null
|
|
66
|
+
|
108
|
67
|
return (
|
109
|
68
|
<div className={classnames('sidebar primaryColorBgDarken', {'sidebarclose': sidebarClose})}>
|
110
|
69
|
|
|
@@ -125,7 +84,6 @@ class Sidebar extends React.Component {
|
125
|
84
|
isOpenInSidebar={ws.isOpenInSidebar}
|
126
|
85
|
onClickTitle={() => this.handleClickWorkspace(ws.id, !ws.isOpenInSidebar)}
|
127
|
86
|
onClickAllContent={this.handleClickAllContent}
|
128
|
|
- // onClickContentFilter={this.handleClickContentFilter}
|
129
|
87
|
key={ws.id}
|
130
|
88
|
/>
|
131
|
89
|
)}
|
|
@@ -156,10 +114,9 @@ class Sidebar extends React.Component {
|
156
|
114
|
}
|
157
|
115
|
}
|
158
|
116
|
|
159
|
|
-const mapStateToProps = ({ lang, user, workspace, workspaceList }) => ({
|
|
117
|
+const mapStateToProps = ({ lang, user, workspaceList }) => ({
|
160
|
118
|
activeLang: lang.find(l => l.active) || {id: 'en'},
|
161
|
119
|
user,
|
162
|
|
- workspace,
|
163
|
120
|
workspaceList
|
164
|
121
|
})
|
165
|
122
|
export default withRouter(connect(mapStateToProps)(appFactory(translate()(Sidebar))))
|