-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: initial * refactoring and changes * changes * changes * fix tests * changes * fix modal layer * changes * mock api added * fix test * demo data changes * drag and drop file into forms * change placeholder * fix missing filter values * merge develop * set initial test parameters * refactoring * renamed label: uploadConceptListModal * added maxWidth to Dropzone * run script build-app for publish * fix version * update actions * version to 1.9.0-rc.1 changed * enable drag&drop files for InputMultiSelect * changes
- Loading branch information
1 parent
37b9f46
commit 48cb2a3
Showing
34 changed files
with
539 additions
and
252 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Afghanistan | ||
Albania | ||
Algeria | ||
America | ||
Andorra | ||
Angola | ||
Antigua | ||
Argentina | ||
Armenia | ||
Australia |
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,28 @@ | ||
// @flow | ||
|
||
export const readFileAsText = (file: File) => new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
|
||
reader.onload = (evt) => resolve(evt.target.result); | ||
reader.onerror = (err) => reject(err); | ||
|
||
reader.readAsText(file); | ||
}); | ||
|
||
/** | ||
* Split by \n, trim rows and filter empty rows | ||
* @param fileContent | ||
*/ | ||
export const cleanFileContent = (fileContent: string) => { | ||
return fileContent.split('\n') | ||
.map(row => row.trim()) | ||
.filter(row => row.length > 0); | ||
}; | ||
|
||
export const checkFileType = (file: File, type?: string) => { | ||
return file.type === type || "text/plain"; | ||
}; | ||
|
||
export const stripFileName = (fileName: string) => { | ||
return fileName.replace(/\.[^/.]+$/, ""); | ||
} |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
export * from './commonHelper'; | ||
export * from './dateHelper'; | ||
export * from './fileHelper'; |
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 @@ | ||
// @flow | ||
|
||
export const DROP_FILES_START = "file-dnd/DROP_FILES_START"; | ||
export const DROP_FILES_SUCCESS = "file-dnd/DROP_FILES_SUCCESS"; | ||
export const DROP_FILES_ERROR = "file-dnd/DROP_FILES_ERROR"; |
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,76 @@ | ||
// @flow | ||
|
||
import type { Dispatch } from 'redux'; | ||
|
||
import { | ||
checkFileType, | ||
readFileAsText, | ||
cleanFileContent | ||
} from "../common/helpers"; | ||
import { | ||
defaultSuccess, | ||
defaultError | ||
} from "../common/actions"; | ||
import type { DateRangeType } from "../common/types/backend"; | ||
import { | ||
uploadConceptListModalOpen | ||
} from "../upload-concept-list-modal/actions"; | ||
import { | ||
DROP_FILES_START, | ||
DROP_FILES_SUCCESS, | ||
DROP_FILES_ERROR | ||
} from "./actionTypes"; | ||
import type | ||
{ | ||
DraggedFileType, | ||
GenericFileType | ||
} from "./types"; | ||
|
||
const initialGenericFileType = (type?: GenericFileType) => ({ | ||
parameters: type ? type.parameters : {}, | ||
callback: uploadConceptListModalOpen | ||
}) | ||
|
||
export const loadFilesStart = () => | ||
({ type: DROP_FILES_START }); | ||
export const loadFilesSuccess = (res: any) => | ||
defaultSuccess(DROP_FILES_SUCCESS, res); | ||
export const loadFilesError = (err: any) => | ||
defaultError(DROP_FILES_ERROR, err); | ||
|
||
export const dropFiles = (item: DraggedFileType, type?: GenericFileType) => { | ||
return (dispatch: Dispatch) => { | ||
dispatch(loadFilesStart()); | ||
|
||
type = !type || !type.callback ? initialGenericFileType(type) : type; | ||
|
||
// Ignore all dropped files except the first | ||
const file = item[0] || item.files[0]; | ||
|
||
if (!checkFileType(file)) | ||
return dispatch(loadFilesError(new Error("Invalid concept list file"))); | ||
|
||
return readFileAsText(file).then( | ||
r => { | ||
const values = cleanFileContent(r); | ||
type.parameters.values = values; | ||
type.parameters.fileName = file.name; | ||
|
||
if (values.length) | ||
return dispatch([ | ||
loadFilesSuccess(r), | ||
type.callback(type) | ||
]); | ||
|
||
return dispatch(loadFilesError(new Error('An empty file was dropped'))); | ||
}, | ||
e => dispatch(loadFilesError(e)) | ||
); | ||
} | ||
}; | ||
|
||
export const dropFilesAndIdx = (item: DraggedFileType, andIdx: number) => | ||
dropFiles(item, { parameters: { andIdx }, callback: uploadConceptListModalOpen }); | ||
|
||
export const dropFilesDateRangeType = (item: DraggedFileType, dateRange: DateRangeType) => | ||
dropFiles(item, { parameters: { dateRange }, callback: uploadConceptListModalOpen }); |
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,11 @@ | ||
// @flow | ||
|
||
export type DraggedFileType = { | ||
files: File[], | ||
isPreviousQuery?: void, | ||
} | ||
|
||
export type GenericFileType = { | ||
parameters: Object, | ||
callback?: Function | ||
} |
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
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.