|
@@ -1,6 +1,6 @@
|
1
|
1
|
import React from 'react'
|
2
|
2
|
import { connect } from 'react-redux'
|
3
|
|
-import { withRouter } from 'react-router'
|
|
3
|
+import { withRouter, Route } from 'react-router-dom'
|
4
|
4
|
import appFactory from '../appFactory.js'
|
5
|
5
|
import { PAGE } from '../helper.js'
|
6
|
6
|
import Sidebar from './Sidebar.jsx'
|
|
@@ -11,6 +11,7 @@ import PageWrapper from '../component/common/layout/PageWrapper.jsx'
|
11
|
11
|
import PageTitle from '../component/common/layout/PageTitle.jsx'
|
12
|
12
|
import PageContent from '../component/common/layout/PageContent.jsx'
|
13
|
13
|
import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
|
|
14
|
+import OpenContentApp from './OpenContentApp.jsx'
|
14
|
15
|
import {
|
15
|
16
|
getAppList,
|
16
|
17
|
getContentTypeList,
|
|
@@ -39,21 +40,22 @@ class WorkspaceContent extends React.Component {
|
39
|
40
|
type: undefined,
|
40
|
41
|
folder: undefined
|
41
|
42
|
},
|
42
|
|
- workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null,
|
43
|
|
- workspaceOpened: false
|
|
43
|
+ workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null, // this is used to avoid handling the parseInt everytime
|
|
44
|
+ appOpened: false
|
44
|
45
|
}
|
45
|
46
|
|
46
|
47
|
document.addEventListener('appCustomEvent', this.customEventReducer)
|
47
|
48
|
}
|
48
|
49
|
|
49
|
50
|
customEventReducer = ({ detail: { type, data } }) => {
|
|
51
|
+ console.log(type, data)
|
50
|
52
|
switch (type) {
|
51
|
53
|
case 'openContentUrl':
|
52
|
|
- this.props.history.push(PAGE.WORKSPACE.CONTENT(data.idWorkspace, data.idContent))
|
|
54
|
+ this.props.history.push(PAGE.WORKSPACE.CONTENT(data.idWorkspace, data.contentType, data.idContent))
|
53
|
55
|
break
|
54
|
56
|
case 'appClosed':
|
55
|
|
- this.props.history.push(PAGE.WORKSPACE.CONTENT(this.props.workspace.id, ''))
|
56
|
|
- this.setState({workspaceOpened: false})
|
|
57
|
+ this.props.history.push(PAGE.WORKSPACE.CONTENT_LIST(this.state.workspaceIdInUrl))
|
|
58
|
+ this.setState({appOpened: false})
|
57
|
59
|
break
|
58
|
60
|
}
|
59
|
61
|
}
|
|
@@ -82,58 +84,39 @@ class WorkspaceContent extends React.Component {
|
82
|
84
|
|
83
|
85
|
if (fetchGetWorkspaceList.status === 200) {
|
84
|
86
|
dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
|
85
|
|
- dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].id, true))
|
|
87
|
+ dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].workspace_id, true))
|
86
|
88
|
|
87
|
89
|
if (match.params.idws === undefined && fetchGetWorkspaceList.json.length > 0) {
|
88
|
|
- wsToLoad = fetchGetWorkspaceList.json[0].id // load first ws if none specified
|
|
90
|
+ wsToLoad = fetchGetWorkspaceList.json[0].workspace_id // load first ws if none specified
|
89
|
91
|
}
|
90
|
92
|
}
|
91
|
93
|
}
|
92
|
94
|
|
93
|
95
|
if (wsToLoad === null) return // ws already loaded
|
94
|
96
|
|
95
|
|
- const wsContent = await dispatch(getWorkspaceContentList(wsToLoad))
|
|
97
|
+ const wsContent = await dispatch(getWorkspaceContentList(wsToLoad, 0))
|
96
|
98
|
|
97
|
99
|
if (wsContent.status === 200) dispatch(setWorkspaceContent(wsContent.json, qs.parse(location.search).type))
|
98
|
100
|
else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
|
99
|
101
|
}
|
100
|
102
|
|
101
|
103
|
componentDidUpdate (prevProps, prevState) {
|
102
|
|
- const { contentType, workspaceContent, user, renderApp, match } = this.props
|
103
|
|
-
|
104
|
104
|
console.log('componentDidUpdate')
|
105
|
105
|
|
106
|
106
|
if (this.state.workspaceIdInUrl === null) return
|
107
|
107
|
|
108
|
|
- const idWorkspace = parseInt(match.params.idws)
|
109
|
|
- if (prevState.workspaceIdInUrl !== idWorkspace) this.setState({workspaceIdInUrl: idWorkspace})
|
110
|
|
-
|
111
|
|
- // if (user.user_id !== -1 && prevProps.user.id !== user.id) dispatch(getWorkspaceList(user.user_id, idWorkspace))
|
|
108
|
+ const idWorkspace = parseInt(this.props.match.params.idws)
|
112
|
109
|
|
113
|
|
- if (match.params.idcts && workspaceContent.id !== -1 && !workspaceOpened && workspaceContent.length) { // if a content id is in url, open it
|
114
|
|
- const idContentToOpen = parseInt(match.params.idcts)
|
115
|
|
- const contentToOpen = workspaceContent.find(wsc => wsc.id === idContentToOpen) // || await dispatch(getWorkspaceContent(idWorkspace, idContentToOpen))
|
|
110
|
+ if (isNaN(idWorkspace)) return
|
116
|
111
|
|
117
|
|
- // @FIXME : for alpha, we do not handle subfolder. commented code bellow should load a component that is not in the workspace root
|
118
|
|
- // if (contentToOpen === undefined) { // content is not is ws root
|
119
|
|
- // const fetchContent = await dispatch(getWorkspaceContent(idWorkspace, idContentToOpen))
|
120
|
|
- // console.log(fetchContent)
|
121
|
|
- // }
|
122
|
|
-
|
123
|
|
- console.log('contentToOpen', contentToOpen)
|
|
112
|
+ if (prevState.workspaceIdInUrl !== idWorkspace) this.setState({workspaceIdInUrl: idWorkspace})
|
124
|
113
|
|
125
|
|
- renderApp(
|
126
|
|
- contentType.find(ct => ct.type === contentToOpen.type),
|
127
|
|
- user,
|
128
|
|
- {...contentToOpen, workspaceContent: workspaceContent}
|
129
|
|
- )
|
130
|
|
- this.setState({workspaceOpened: true})
|
131
|
|
- }
|
|
114
|
+ // if (user.user_id !== -1 && prevProps.user.id !== user.id) dispatch(getWorkspaceList(user.user_id, idWorkspace))
|
132
|
115
|
}
|
133
|
116
|
|
134
|
117
|
handleClickContentItem = content => {
|
135
|
118
|
console.log('content clicked', content)
|
136
|
|
- this.props.history.push(`${PAGE.WORKSPACE.CONTENT(content.workspaceId, content.id)}${this.props.location.search}`)
|
|
119
|
+ this.props.history.push(`/workspaces/${content.idWorkspace}/${content.type}/${content.id}`)
|
137
|
120
|
}
|
138
|
121
|
|
139
|
122
|
handleClickEditContentItem = (e, content) => {
|
|
@@ -165,15 +148,22 @@ class WorkspaceContent extends React.Component {
|
165
|
148
|
this.props.dispatch(getFolderContent(this.props.workspace.id, folderId))
|
166
|
149
|
}
|
167
|
150
|
|
168
|
|
- handleClickCreateContent = (folder, contentType) => {
|
169
|
|
- this.props.renderCreateContentApp(this.props.app[contentType], this.props.user, folder)
|
|
151
|
+ handleClickCreateContent = (e, idFolder, contentType) => {
|
|
152
|
+ e.stopPropagation()
|
|
153
|
+ this.props.renderCreateContentApp(
|
|
154
|
+ this.props.contentType.find(ct => ct.slug === contentType),
|
|
155
|
+ this.props.user,
|
|
156
|
+ this.props.match.params.idws,
|
|
157
|
+ idFolder
|
|
158
|
+ )
|
170
|
159
|
}
|
171
|
160
|
|
|
161
|
+ handleUpdateAppOpened = opened => this.setState({appOpened: opened})
|
|
162
|
+
|
172
|
163
|
render () {
|
173
|
|
- const { workspaceContent, app, contentType } = this.props
|
|
164
|
+ const { workspaceContent, contentType, match } = this.props
|
174
|
165
|
|
175
|
166
|
const filterWorkspaceContent = (contentList, filter) => {
|
176
|
|
- console.log(contentList, filter)
|
177
|
167
|
return filter.length === 0
|
178
|
168
|
? contentList
|
179
|
169
|
: contentList.filter(c => c.type === 'folder' || filter.includes(c.type)) // keep unfiltered files and folders
|
|
@@ -187,19 +177,28 @@ class WorkspaceContent extends React.Component {
|
187
|
177
|
const filteredWorkspaceContent = workspaceContent.length > 0
|
188
|
178
|
? filterWorkspaceContent(workspaceContent, urlFilter ? [urlFilter] : [])
|
189
|
179
|
: []
|
190
|
|
- console.log('workspaceContent => filteredWorkspaceContent', filteredWorkspaceContent)
|
|
180
|
+ console.log('workspaceContent => filteredWorkspaceContent', filteredWorkspaceContent, 'urlFilter', urlFilter)
|
191
|
181
|
|
192
|
182
|
return (
|
193
|
183
|
<div className='sidebarpagecontainer'>
|
194
|
184
|
<Sidebar />
|
195
|
185
|
|
|
186
|
+ <Route path={`${match.url}/:type/:idcts`} render={() =>
|
|
187
|
+ <OpenContentApp idWorkspace={match.params.idws} appOpened={this.state.appOpened} updateAppOpened={this.handleUpdateAppOpened} />}
|
|
188
|
+ />
|
|
189
|
+
|
196
|
190
|
<PageWrapper customeClass='workspace'>
|
197
|
191
|
<PageTitle
|
198
|
192
|
parentClass='workspace__header'
|
199
|
193
|
customClass='justify-content-between'
|
200
|
194
|
title={workspaceContent.label ? workspaceContent.label : ''}
|
201
|
195
|
>
|
202
|
|
- <DropdownCreateButton parentClass='workspace__header__btnaddworkspace' />
|
|
196
|
+ <DropdownCreateButton
|
|
197
|
+ parentClass='workspace__header__btnaddworkspace'
|
|
198
|
+ idFolder={null}
|
|
199
|
+ onClickCreateContent={this.handleClickCreateContent}
|
|
200
|
+ availableApp={contentType}
|
|
201
|
+ />
|
203
|
202
|
</PageTitle>
|
204
|
203
|
|
205
|
204
|
<PageContent parentClass='workspace__content'>
|
|
@@ -211,7 +210,7 @@ class WorkspaceContent extends React.Component {
|
211
|
210
|
{ filteredWorkspaceContent.map((c, i) => c.type === 'folder'
|
212
|
211
|
? (
|
213
|
212
|
<Folder
|
214
|
|
- app={app}
|
|
213
|
+ availableApp={contentType}
|
215
|
214
|
folderData={c}
|
216
|
215
|
onClickItem={this.handleClickContentItem}
|
217
|
216
|
onClickExtendedAction={{
|
|
@@ -242,6 +241,7 @@ class WorkspaceContent extends React.Component {
|
242
|
241
|
archive: e => this.handleClickArchiveContentItem(e, c),
|
243
|
242
|
delete: e => this.handleClickDeleteContentItem(e, c)
|
244
|
243
|
}}
|
|
244
|
+ onClickCreateContent={this.handleClickCreateContent}
|
245
|
245
|
isLast={i === filteredWorkspaceContent.length - 1}
|
246
|
246
|
key={c.id}
|
247
|
247
|
/>
|
|
@@ -249,7 +249,12 @@ class WorkspaceContent extends React.Component {
|
249
|
249
|
)}
|
250
|
250
|
</div>
|
251
|
251
|
|
252
|
|
- <DropdownCreateButton customClass='workspace__content__button mb-5' />
|
|
252
|
+ <DropdownCreateButton
|
|
253
|
+ customClass='workspace__content__button mb-5'
|
|
254
|
+ idFolder={null}
|
|
255
|
+ onClickCreateContent={this.handleClickCreateContent}
|
|
256
|
+ availableApp={contentType}
|
|
257
|
+ />
|
253
|
258
|
|
254
|
259
|
<div id='appContainer' />
|
255
|
260
|
</PageContent>
|