Browse Source

workspace content now handles unique depth of folder

Skylsmoi 6 years ago
parent
commit
8dc29c4dd2

+ 9 - 0
jsonserver/server.js View File

@@ -56,6 +56,15 @@ server.get('/workspace/:id', (req, res) => res.jsonp(
56 56
   Object.assign({}, jsonDb.workspace_detail, {content: shuffle(jsonDb.workspace_detail.content)}, {id: req.params.id})
57 57
 ))
58 58
 
59
+server.get('/workspace/:idws/folder/:idf', (req, res) => {
60
+  switch (req.params.idf) {
61
+    case '3':
62
+      return res.jsonp(jsonDb.folder_content_3)
63
+    case '11':
64
+      return res.jsonp(jsonDb.folder_content_11)
65
+  }
66
+})
67
+
59 68
 server.get('/user/:id/roles', (req, res) => res.jsonp(jsonDb.user_role))
60 69
 
61 70
 server.get('/timezone', (req, res) => res.jsonp(timezoneDb.timezone))

+ 45 - 43
jsonserver/static_db.json View File

@@ -151,52 +151,54 @@
151 151
         "workspace_id": 1,
152 152
         "title": "Programmation objet",
153 153
         "type": "folder",
154
-        "content": [
155
-          {
156
-            "id": 4,
157
-            "parent_id": 3,
158
-            "workspace_id": 1,
159
-            "title": "des trucs de backend",
160
-            "type": "File",
161
-            "status": "outdated"
162
-          },
163
-          {
164
-            "id": 5,
165
-            "parent_id": 3,
166
-            "workspace_id": 1,
167
-            "title": "on s'emmerde",
168
-            "type": "PageHtml",
169
-            "status": "outdated"
170
-          },
171
-          {
172
-            "id": 11,
173
-            "parent_id": 3,
174
-            "workspace_id": 1,
175
-            "title": "Hidden features",
176
-            "type": "folder",
177
-            "content": [
178
-              {
179
-                "id": 12,
180
-                "parent_id": 11,
181
-                "workspace_id": 1,
182
-                "title": "flatMap",
183
-                "type": "PageHtml",
184
-                "status": "current"
185
-              },
186
-              {
187
-                "id": 13,
188
-                "parent_id": 11,
189
-                "workspace_id": 1,
190
-                "title": "c'est tout pété",
191
-                "type": "Issue",
192
-                "status": "current"
193
-              }
194
-            ]
195
-          }
196
-        ]
154
+        "content": []
197 155
       }
198 156
     ]
199 157
   },
158
+  "folder_content_3": [
159
+    {
160
+      "id": 4,
161
+      "parent_id": 3,
162
+      "workspace_id": 1,
163
+      "title": "des trucs de backend",
164
+      "type": "File",
165
+      "status": "outdated"
166
+    },
167
+    {
168
+      "id": 5,
169
+      "parent_id": 3,
170
+      "workspace_id": 1,
171
+      "title": "on s'emmerde",
172
+      "type": "PageHtml",
173
+      "status": "outdated"
174
+    },
175
+    {
176
+      "id": 11,
177
+      "parent_id": 3,
178
+      "workspace_id": 1,
179
+      "title": "Hidden features",
180
+      "type": "folder",
181
+      "content": []
182
+    }
183
+  ],
184
+  "folder_content_11": [
185
+    {
186
+      "id": 12,
187
+      "parent_id": 11,
188
+      "workspace_id": 1,
189
+      "title": "flatMap",
190
+      "type": "PageHtml",
191
+      "status": "current"
192
+    },
193
+    {
194
+      "id": 13,
195
+      "parent_id": 11,
196
+      "workspace_id": 1,
197
+      "title": "c'est tout pété",
198
+      "type": "Issue",
199
+      "status": "current"
200
+    }
201
+  ],
200 202
   "timeline": [{
201 203
     "id": 0,
202 204
     "type": "message",

+ 14 - 1
src/action-creator.async.js View File

@@ -15,8 +15,11 @@ import {
15 15
   setWorkspaceData,
16 16
   WORKSPACE_LIST,
17 17
   updateWorkspaceListData,
18
+  FOLDER,
19
+  setFolderData,
18 20
   APP_LIST,
19
-  setAppList, setWorkspaceListIsOpenInSidebar
21
+  setAppList,
22
+  setWorkspaceListIsOpenInSidebar
20 23
 } from './action-creator.sync.js'
21 24
 
22 25
 /*
@@ -166,6 +169,16 @@ export const getWorkspaceContent = (workspaceId, filterStr) => async dispatch =>
166 169
   if (fetchGetWorkspaceContent.status === 200) dispatch(setWorkspaceData(fetchGetWorkspaceContent.json, filterStr))
167 170
 }
168 171
 
172
+export const getFolderContent = (workspaceId, folderId) => async dispatch => {
173
+  const fetchGetFolderContent = await fetchWrapper({
174
+    url: `${FETCH_CONFIG.apiUrl}/workspace/${workspaceId}/folder/${folderId}`,
175
+    param: {...FETCH_CONFIG.header, method: 'GET'},
176
+    actionName: `${WORKSPACE}/${FOLDER}`,
177
+    dispatch
178
+  })
179
+  if (fetchGetFolderContent.status === 200) dispatch(setFolderData(folderId, fetchGetFolderContent.json))
180
+}
181
+
169 182
 export const getAppList = () => async dispatch => {
170 183
   const fetchGetAppList = await fetchWrapper({
171 184
     url: `${FETCH_CONFIG.apiUrl}/app/config`,

+ 3 - 0
src/action-creator.sync.js View File

@@ -15,6 +15,9 @@ export const WORKSPACE = 'Workspace'
15 15
 export const setWorkspaceData = (workspace, filterStr = '') => ({ type: `Set/${WORKSPACE}`, workspace, filterStr })
16 16
 export const updateWorkspaceFilter = filterList => ({ type: `Update/${WORKSPACE}/Filter`, filterList })
17 17
 
18
+export const FOLDER = 'Folder'
19
+export const setFolderData = (folderId, content) => ({ type: `Set/${WORKSPACE}/${FOLDER}/Content`, folderId, content })
20
+
18 21
 export const WORKSPACE_LIST = 'WorkspaceList'
19 22
 export const updateWorkspaceListData = workspaceList => ({ type: `Update/${WORKSPACE_LIST}`, workspaceList })
20 23
 export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `Set/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })

+ 11 - 3
src/component/Workspace/Folder.jsx View File

@@ -14,7 +14,10 @@ class Folder extends React.Component {
14 14
     }
15 15
   }
16 16
 
17
-  handleClickToggleFolder = () => this.setState({open: !this.state.open})
17
+  handleClickToggleFolder = () => {
18
+    !this.state.open && this.props.folderData.content.length === 0 && this.props.onClickFolder(this.props.folderData.id)
19
+    this.setState({open: !this.state.open})
20
+  }
18 21
 
19 22
   handleClickNewFile = e => {
20 23
     e.stopPropagation() // because we have a link inside a link (togler and newFile)
@@ -22,7 +25,8 @@ class Folder extends React.Component {
22 25
   }
23 26
 
24 27
   render () {
25
-    const { app, folderData: { title, content }, onClickItem, isLast, t } = this.props
28
+    const { app, folderData: { title, content }, onClickItem, onClickFolder, isLast, t } = this.props
29
+
26 30
     return (
27 31
       <div className={classnames('folder', {'active': this.state.open, 'item-last': isLast})}>
28 32
         <div className='folder__header' onClick={this.handleClickToggleFolder}>
@@ -60,6 +64,7 @@ class Folder extends React.Component {
60 64
               app={app}
61 65
               folderData={c}
62 66
               onClickItem={onClickItem}
67
+              onClickFolder={onClickFolder}
63 68
               isLast={isLast}
64 69
               t={t}
65 70
               key={c.id}
@@ -87,5 +92,8 @@ Folder.propTypes = {
87 92
     title: PropTypes.string.isRequired,
88 93
     content: PropTypes.array
89 94
   }),
90
-  app: PropTypes.object
95
+  app: PropTypes.object,
96
+  onClickItem: PropTypes.func.isRequired,
97
+  onClickFolder: PropTypes.func.isRequired,
98
+  isLast: PropTypes.bool.isRequired
91 99
 }

+ 7 - 1
src/container/WorkspaceContent.jsx View File

@@ -11,7 +11,8 @@ import PageContent from '../component/common/layout/PageContent.jsx'
11 11
 import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
12 12
 import {
13 13
   getAppList,
14
-  getWorkspaceContent
14
+  getWorkspaceContent,
15
+  getFolderContent
15 16
 } from '../action-creator.async.js'
16 17
 
17 18
 class WorkspaceContent extends React.Component {
@@ -42,6 +43,10 @@ class WorkspaceContent extends React.Component {
42 43
     // dispatch(setActiveFileContentActive(content))
43 44
   }
44 45
 
46
+  handleClickFolder = folderId => {
47
+    this.props.dispatch(getFolderContent(this.props.workspace.id, folderId))
48
+  }
49
+
45 50
   filterWorkspaceContent = (contentList, filter) => filter.length === 0
46 51
     ? contentList
47 52
     : contentList.filter(c => c.type === 'folder' || filter.includes(c.type)) // keep unfiltered files and folders
@@ -76,6 +81,7 @@ class WorkspaceContent extends React.Component {
76 81
                     app={app}
77 82
                     folderData={c}
78 83
                     onClickItem={this.handleClickContentItem}
84
+                    onClickFolder={this.handleClickFolder}
79 85
                     isLast={i === filteredWorkspaceContent.length - 1}
80 86
                     key={c.id}
81 87
                   />

+ 16 - 1
src/reducer/workspace.js View File

@@ -1,5 +1,6 @@
1 1
 import {
2
-  WORKSPACE
2
+  WORKSPACE,
3
+  FOLDER
3 4
 } from '../action-creator.sync.js'
4 5
 
5 6
 const serializeWorkspace = data => ({
@@ -26,6 +27,20 @@ export default function user (state = {
26 27
     case `Update/${WORKSPACE}/Filter`:
27 28
       return {...state, filter: action.filterList}
28 29
 
30
+    case `Set/${WORKSPACE}/${FOLDER}/Content`:
31
+      const setFolderContent = (contentItem, action) => {
32
+        if (contentItem.id === action.folderId) return {...contentItem, content: action.content}
33
+
34
+        if (contentItem.type === 'folder') return {...contentItem, content: contentItem.content.map(c => setFolderContent(c, action))}
35
+
36
+        return contentItem
37
+      }
38
+
39
+      return {
40
+        ...state,
41
+        content: state.content.map(c => setFolderContent(c, action))
42
+      }
43
+
29 44
     default:
30 45
       return state
31 46
   }