|
@@ -14,11 +14,14 @@ import PopupCreateContent from '../component/PopupCreateContent/PopupCreateConta
|
14
|
14
|
import {
|
15
|
15
|
getAppList,
|
16
|
16
|
getWorkspaceContent,
|
17
|
|
- getFolderContent
|
|
17
|
+ getFolderContent,
|
|
18
|
+ getWorkspaceList
|
18
|
19
|
} from '../action-creator.async.js'
|
19
|
20
|
import {
|
20
|
21
|
newFlashMessage,
|
21
|
|
- setWorkspaceData
|
|
22
|
+ setWorkspaceData,
|
|
23
|
+ setWorkspaceListIsOpenInSidebar,
|
|
24
|
+ updateWorkspaceListData
|
22
|
25
|
} from '../action-creator.sync.js'
|
23
|
26
|
|
24
|
27
|
const qs = require('query-string')
|
|
@@ -31,18 +34,32 @@ class WorkspaceContent extends React.Component {
|
31
|
34
|
display: false,
|
32
|
35
|
type: undefined,
|
33
|
36
|
folder: undefined
|
34
|
|
- }
|
|
37
|
+ },
|
|
38
|
+ workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null
|
35
|
39
|
}
|
36
|
40
|
}
|
37
|
41
|
|
38
|
42
|
async componentDidMount () {
|
39
|
|
- const { workspaceList, app, match, location, dispatch } = this.props
|
|
43
|
+ const { workspaceIdInUrl } = this.state
|
|
44
|
+ const { user, workspaceList, app, match, location, dispatch } = this.props
|
40
|
45
|
|
41
|
46
|
if (Object.keys(app).length === 0) dispatch(getAppList()) // async but no need await
|
42
|
47
|
|
43
|
48
|
let wsToLoad = null
|
44
|
49
|
if (match.params.idws !== undefined) wsToLoad = match.params.idws
|
45
|
|
- else if (workspaceList.length > 0) wsToLoad = workspaceList[0].id // load first ws if none specified
|
|
50
|
+
|
|
51
|
+ if (user.user_id !== -1 && workspaceList.length === 0) {
|
|
52
|
+ const fetchGetWorkspaceList = await dispatch(getWorkspaceList(user.user_id))
|
|
53
|
+
|
|
54
|
+ if (fetchGetWorkspaceList.status === 200) {
|
|
55
|
+ dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
|
|
56
|
+ dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].id, true))
|
|
57
|
+
|
|
58
|
+ if (match.params.idws === undefined && fetchGetWorkspaceList.json.length > 0) {
|
|
59
|
+ wsToLoad = fetchGetWorkspaceList.json[0].id // load first ws if none specified
|
|
60
|
+ }
|
|
61
|
+ }
|
|
62
|
+ }
|
46
|
63
|
|
47
|
64
|
if (wsToLoad === null) return // ws already loaded
|
48
|
65
|
|
|
@@ -59,6 +76,17 @@ class WorkspaceContent extends React.Component {
|
59
|
76
|
} else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
|
60
|
77
|
}
|
61
|
78
|
|
|
79
|
+ componentDidUpdate (prevProps, prevState) {
|
|
80
|
+ const { user, match, dispatch } = this.props
|
|
81
|
+
|
|
82
|
+ if (this.state.workspaceIdInUrl === null) return
|
|
83
|
+
|
|
84
|
+ const newWorkspaceId = parseInt(match.params.idws)
|
|
85
|
+ prevState.workspaceIdInUrl !== newWorkspaceId && this.setState({workspaceIdInUrl: newWorkspaceId})
|
|
86
|
+
|
|
87
|
+ if (user.id !== -1 && prevProps.user.id !== user.id) dispatch(getWorkspaceList(user.user_id, newWorkspaceId))
|
|
88
|
+ }
|
|
89
|
+
|
62
|
90
|
handleClickContentItem = content => {
|
63
|
91
|
this.props.history.push(`${PAGE.WORKSPACE.CONTENT(content.workspace_id, content.id)}${this.props.location.search}`)
|
64
|
92
|
this.props.renderApp(this.props.app[content.type], this.props.user, {...content, workspace: this.props.workspace})
|
|
@@ -115,7 +143,7 @@ class WorkspaceContent extends React.Component {
|
115
|
143
|
const filterWorkspaceContent = (contentList, filter) => filter.length === 0
|
116
|
144
|
? contentList
|
117
|
145
|
: contentList.filter(c => c.type === 'folder' || filter.includes(c.type)) // keep unfiltered files and folders
|
118
|
|
- .map(c => c.type !== 'folder' ? c : {...c, content: this.filterWorkspaceContent(c.content, filter)}) // recursively filter folder content
|
|
146
|
+ .map(c => c.type !== 'folder' ? c : {...c, content: filterWorkspaceContent(c.content, filter)}) // recursively filter folder content
|
119
|
147
|
// .filter(c => c.type !== 'folder' || c.content.length > 0) // remove empty folder => 2018/05/21 - since we load only one lvl of content, don't remove empty folders
|
120
|
148
|
|
121
|
149
|
const filteredWorkspaceContent = filterWorkspaceContent(workspace.content, workspace.filter)
|