-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* State for file browser added * File browser page added * Breadcrumb navigation and files table added * css added * Reducer splitted, JSON object check added, refactoring and new tests added
- Loading branch information
Showing
32 changed files
with
1,363 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ yarn-error.log* | |
|
||
# false folder | ||
/false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { mockApi } from 'test/testUtils'; | ||
import { FILE_BROWSER } from 'test/mocks/fileBrowser'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const getFileBrowser = jest.fn(mockApi({ payload: FILE_BROWSER })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.FileBreadcrumb { | ||
// sass-lint:disable class-name-format | ||
.breadcrumb { | ||
border: 0; | ||
} | ||
// sass-lint:enable class-name-format | ||
} | ||
|
||
.BreadcrumbItem { | ||
&__first-level-folder { | ||
cursor: pointer; | ||
} | ||
|
||
&__a-item-link { | ||
cursor: pointer; | ||
} | ||
|
||
&__root-link { | ||
cursor: pointer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.FilesListTable { | ||
&__link-dir { | ||
cursor: pointer; | ||
} | ||
|
||
&__link-download { | ||
cursor: pointer; | ||
} | ||
|
||
&__up-link { | ||
cursor: pointer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { makeRequest, METHODS } from '@entando/apimanager'; | ||
import { FILE_BROWSER } from 'test/mocks/fileBrowser'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const getFileBrowser = (queryString = '') => ( | ||
makeRequest({ | ||
uri: `/api/fileBrowser${queryString}`, | ||
method: METHODS.GET, | ||
mockResponse: FILE_BROWSER, | ||
useAuthentication: true, | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getFileBrowser } from 'api/fileBrowser'; | ||
import { addErrors } from 'state/errors/actions'; | ||
import { SET_FILE_LIST, SET_PATH_INFO } from 'state/file-browser/types'; | ||
import { toggleLoading } from 'state/loading/actions'; | ||
|
||
export const setFileList = fileList => ({ | ||
type: SET_FILE_LIST, | ||
payload: { | ||
fileList, | ||
}, | ||
}); | ||
|
||
export const setPathInfo = pathInfo => ({ | ||
type: SET_PATH_INFO, | ||
payload: { | ||
pathInfo, | ||
}, | ||
}); | ||
|
||
export const wrapApiCall = apiFunc => (...args) => async (dispatch) => { | ||
const response = await apiFunc(...args); | ||
const contentType = response.headers.get('content-type'); | ||
if (contentType && contentType.includes('application/json')) { | ||
const json = await response.json(); | ||
if (response.ok) { | ||
return json; | ||
} | ||
dispatch(addErrors(json.errors.map(e => e.message))); | ||
throw json; | ||
} | ||
throw new TypeError('No JSON content-type in response headers'); | ||
}; | ||
|
||
|
||
// thunks | ||
export const fetchFileList = (protectedFolder = '', path = '') => dispatch => | ||
new Promise((resolve) => { | ||
dispatch(toggleLoading('files')); | ||
const queryString = []; | ||
if ((protectedFolder !== '') && (protectedFolder !== null)) { | ||
queryString.push(`protectedFolder=${protectedFolder}`); | ||
} | ||
if (path) { | ||
queryString.push(`currentPath=${path}`); | ||
} | ||
const getFileBrowserApi = wrapApiCall(getFileBrowser); | ||
getFileBrowserApi((`?${queryString.join('&')}`))(dispatch).then((response) => { | ||
dispatch(setFileList(response.payload)); | ||
dispatch(setPathInfo(response.metaData)); | ||
dispatch(toggleLoading('files')); | ||
resolve(); | ||
}).catch(() => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { combineReducers } from 'redux'; | ||
import { SET_FILE_LIST, SET_PATH_INFO } from 'state/file-browser/types'; | ||
|
||
const defaultState = { | ||
list: [], | ||
pathInfo: { | ||
protectedFolder: null, | ||
prevPath: '', | ||
currentPath: '', | ||
}, | ||
}; | ||
|
||
const list = (state = defaultState.list, action = {}) => { | ||
switch (action.type) { | ||
case SET_FILE_LIST: { | ||
return action.payload.fileList || defaultState.list; | ||
} | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
const pathInfo = (state = defaultState.pathInfo, action = {}) => { | ||
switch (action.type) { | ||
case SET_PATH_INFO: { | ||
return Object.assign({}, defaultState.pathInfo, action.payload.pathInfo); | ||
} | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default combineReducers({ | ||
list, | ||
pathInfo, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
export const getFileBrowser = state => state.fileBrowser; | ||
|
||
export const getFileList = createSelector( | ||
getFileBrowser, | ||
fileBrowser => fileBrowser.list, | ||
); | ||
|
||
export const getPathInfo = createSelector( | ||
getFileBrowser, | ||
fileBrowser => fileBrowser.pathInfo, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SET_FILE_LIST = 'filebrowser/set-file-list'; | ||
export const SET_PATH_INFO = 'filebrowser/set-path-info'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.