Pārlūkot izejas kodu

fixed sidebar filter and route for url '/'

Skylsmoi 6 gadus atpakaļ
vecāks
revīzija
c891ae84af

+ 3 - 9
src/action-creator.async.js Parādīt failu

13
   setUserRole,
13
   setUserRole,
14
   WORKSPACE,
14
   WORKSPACE,
15
   WORKSPACE_LIST,
15
   WORKSPACE_LIST,
16
-  updateWorkspaceListData,
17
   FOLDER,
16
   FOLDER,
18
   setFolderData,
17
   setFolderData,
19
   APP_LIST,
18
   APP_LIST,
20
-  setAppList,
21
-  setWorkspaceListIsOpenInSidebar
19
+  setAppList
22
 } from './action-creator.sync.js'
20
 } from './action-creator.sync.js'
23
 
21
 
24
 /*
22
 /*
155
 //   console.log('jsonResponseNoData', fetchResponseNoData)
153
 //   console.log('jsonResponseNoData', fetchResponseNoData)
156
 // }
154
 // }
157
 
155
 
158
-export const getWorkspaceList = (userId, workspaceIdToOpen) => async dispatch => {
159
-  const fetchGetWorkspaceList = await fetchWrapper({
156
+export const getWorkspaceList = userId => dispatch => {
157
+  return fetchWrapper({
160
     url: `${FETCH_CONFIG.mockApiUrl}/user/${userId}/workspace`,
158
     url: `${FETCH_CONFIG.mockApiUrl}/user/${userId}/workspace`,
161
     param: {...FETCH_CONFIG.header, method: 'GET'},
159
     param: {...FETCH_CONFIG.header, method: 'GET'},
162
     actionName: WORKSPACE_LIST,
160
     actionName: WORKSPACE_LIST,
163
     dispatch
161
     dispatch
164
   })
162
   })
165
-  if (fetchGetWorkspaceList.status === 200) {
166
-    dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
167
-    dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdToOpen, true))
168
-  }
169
 }
163
 }
170
 
164
 
171
 export const getWorkspaceContent = workspaceId => dispatch => {
165
 export const getWorkspaceContent = workspaceId => dispatch => {

+ 1 - 1
src/component/Sidebar/WorkspaceListItem.jsx Parādīt failu

95
 
95
 
96
                 <div className='dropdown__title' id='navbarDropdown'>
96
                 <div className='dropdown__title' id='navbarDropdown'>
97
                   <div className='dropdown__title__text'>
97
                   <div className='dropdown__title__text'>
98
-                    { props.app[a].label[props.lang.id] }
98
+                    {props.app[a].label[props.lang.id]}
99
                   </div>
99
                   </div>
100
                 </div>
100
                 </div>
101
               </div>
101
               </div>

+ 3 - 15
src/container/Sidebar.jsx Parādīt failu

4
 import classnames from 'classnames'
4
 import classnames from 'classnames'
5
 import { translate } from 'react-i18next'
5
 import { translate } from 'react-i18next'
6
 import WorkspaceListItem from '../component/Sidebar/WorkspaceListItem.jsx'
6
 import WorkspaceListItem from '../component/Sidebar/WorkspaceListItem.jsx'
7
-import { getWorkspaceList } from '../action-creator.async.js'
8
 import {
7
 import {
9
   setWorkspaceListIsOpenInSidebar,
8
   setWorkspaceListIsOpenInSidebar,
10
   updateWorkspaceFilter
9
   updateWorkspaceFilter
20
     }
19
     }
21
   }
20
   }
22
 
21
 
23
-  componentDidMount () {
24
-    const { workspaceIdInUrl } = this.state
25
-    const { user, workspaceList, dispatch } = this.props
26
-
27
-    user.id !== -1 && workspaceList.length === 0 && dispatch(getWorkspaceList(user.id, workspaceIdInUrl))
28
-  }
29
-
30
   componentDidUpdate (prevProps, prevState) {
22
   componentDidUpdate (prevProps, prevState) {
31
-    const { user, match, dispatch } = this.props
32
-
33
-    if (this.state.workspaceIdInUrl === null) return
34
-
35
-    const newWorkspaceId = parseInt(match.params.idws)
36
-    prevState.workspaceIdInUrl !== newWorkspaceId && this.setState({workspaceIdInUrl: newWorkspaceId})
23
+    if (this.props.match.params.idws === undefined) return
37
 
24
 
38
-    user.id !== -1 && prevProps.user.id !== user.id && dispatch(getWorkspaceList(user.id, newWorkspaceId))
25
+    const newWorkspaceId = parseInt(this.props.match.params.idws)
26
+    if (prevState.workspaceIdInUrl !== newWorkspaceId) this.setState({workspaceIdInUrl: newWorkspaceId})
39
   }
27
   }
40
 
28
 
41
   handleClickWorkspace = (idWs, newIsOpenInSidebar) => this.props.dispatch(setWorkspaceListIsOpenInSidebar(idWs, newIsOpenInSidebar))
29
   handleClickWorkspace = (idWs, newIsOpenInSidebar) => this.props.dispatch(setWorkspaceListIsOpenInSidebar(idWs, newIsOpenInSidebar))

+ 1 - 1
src/container/Tracim.jsx Parādīt failu

58
               <Route path={PAGE.LOGIN} component={Login} />
58
               <Route path={PAGE.LOGIN} component={Login} />
59
 
59
 
60
               <PrivateRoute exact path={PAGE.HOME} component={WorkspaceContent} />
60
               <PrivateRoute exact path={PAGE.HOME} component={WorkspaceContent} />
61
+              <PrivateRoute path={PAGE.ACCOUNT} component={Account} />
61
               {/* bellow, the '?' is important, it avoid to have to declare another route for CONTENT_LIST which could double match */}
62
               {/* bellow, the '?' is important, it avoid to have to declare another route for CONTENT_LIST which could double match */}
62
               <PrivateRoute path={PAGE.WORKSPACE.CONTENT(':idws', ':idcts?')} component={WorkspaceContent} />
63
               <PrivateRoute path={PAGE.WORKSPACE.CONTENT(':idws', ':idcts?')} component={WorkspaceContent} />
63
-              <PrivateRoute path={PAGE.ACCOUNT} component={Account} />
64
               <PrivateRoute exact path={PAGE.WORKSPACE.DASHBOARD()} component={Dashboard} />
64
               <PrivateRoute exact path={PAGE.WORKSPACE.DASHBOARD()} component={Dashboard} />
65
               <PrivateRoute path={'/wip/:cp'} component={WIPcomponent} /> {/* for testing purpose only */}
65
               <PrivateRoute path={'/wip/:cp'} component={WIPcomponent} /> {/* for testing purpose only */}
66
 
66
 

+ 34 - 6
src/container/WorkspaceContent.jsx Parādīt failu

14
 import {
14
 import {
15
   getAppList,
15
   getAppList,
16
   getWorkspaceContent,
16
   getWorkspaceContent,
17
-  getFolderContent
17
+  getFolderContent,
18
+  getWorkspaceList
18
 } from '../action-creator.async.js'
19
 } from '../action-creator.async.js'
19
 import {
20
 import {
20
   newFlashMessage,
21
   newFlashMessage,
21
-  setWorkspaceData
22
+  setWorkspaceData,
23
+  setWorkspaceListIsOpenInSidebar,
24
+  updateWorkspaceListData
22
 } from '../action-creator.sync.js'
25
 } from '../action-creator.sync.js'
23
 
26
 
24
 const qs = require('query-string')
27
 const qs = require('query-string')
31
         display: false,
34
         display: false,
32
         type: undefined,
35
         type: undefined,
33
         folder: undefined
36
         folder: undefined
34
-      }
37
+      },
38
+      workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null
35
     }
39
     }
36
   }
40
   }
37
 
41
 
38
   async componentDidMount () {
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
     if (Object.keys(app).length === 0) dispatch(getAppList()) // async but no need await
46
     if (Object.keys(app).length === 0) dispatch(getAppList()) // async but no need await
42
 
47
 
43
     let wsToLoad = null
48
     let wsToLoad = null
44
     if (match.params.idws !== undefined) wsToLoad = match.params.idws
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
     if (wsToLoad === null) return // ws already loaded
64
     if (wsToLoad === null) return // ws already loaded
48
 
65
 
59
     } else dispatch(newFlashMessage('Error while loading workspace', 'danger'))
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
   handleClickContentItem = content => {
90
   handleClickContentItem = content => {
63
     this.props.history.push(`${PAGE.WORKSPACE.CONTENT(content.workspace_id, content.id)}${this.props.location.search}`)
91
     this.props.history.push(`${PAGE.WORKSPACE.CONTENT(content.workspace_id, content.id)}${this.props.location.search}`)
64
     this.props.renderApp(this.props.app[content.type], this.props.user, {...content, workspace: this.props.workspace})
92
     this.props.renderApp(this.props.app[content.type], this.props.user, {...content, workspace: this.props.workspace})
115
     const filterWorkspaceContent = (contentList, filter) => filter.length === 0
143
     const filterWorkspaceContent = (contentList, filter) => filter.length === 0
116
       ? contentList
144
       ? contentList
117
       : contentList.filter(c => c.type === 'folder' || filter.includes(c.type)) // keep unfiltered files and folders
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
     // .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
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
     const filteredWorkspaceContent = filterWorkspaceContent(workspace.content, workspace.filter)
149
     const filteredWorkspaceContent = filterWorkspaceContent(workspace.content, workspace.filter)