Feature #15160
Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
// SPDX-License-Identifier: AGPL-3.0
import { unionize, ofType, UnionOf } from "~/common/unionize";
// SPDX-License-Identifier: AGPL-3.0
import { unionize, ofType, UnionOf } from "~/common/unionize";
+import { Dispatch } from "redux";
+import { RootState } from '~/store/store';
export interface UploadFile {
id: number;
export interface UploadFile {
id: number;
export const fileUploaderActions = unionize({
CLEAR_UPLOAD: ofType(),
SET_UPLOAD_FILES: ofType<File[]>(),
export const fileUploaderActions = unionize({
CLEAR_UPLOAD: ofType(),
SET_UPLOAD_FILES: ofType<File[]>(),
+ UPDATE_UPLOAD_FILES: ofType<File[]>(),
SET_UPLOAD_PROGRESS: ofType<{ fileId: number, loaded: number, total: number, currentTime: number }>(),
START_UPLOAD: ofType(),
});
export type FileUploaderAction = UnionOf<typeof fileUploaderActions>;
SET_UPLOAD_PROGRESS: ofType<{ fileId: number, loaded: number, total: number, currentTime: number }>(),
START_UPLOAD: ofType(),
});
export type FileUploaderAction = UnionOf<typeof fileUploaderActions>;
+
+export const getFileUploaderState = () => (dispatch: Dispatch, getState: () => RootState) => {
+ return getState().fileUploader;
+};
\ No newline at end of file
// SPDX-License-Identifier: AGPL-3.0
import { UploadFile, fileUploaderActions, FileUploaderAction } from "./file-uploader-actions";
// SPDX-License-Identifier: AGPL-3.0
import { UploadFile, fileUploaderActions, FileUploaderAction } from "./file-uploader-actions";
+import * as _ from 'lodash';
export type UploaderState = UploadFile[];
export type UploaderState = UploadFile[];
prevTime: 0,
currentTime: 0
})),
prevTime: 0,
currentTime: 0
})),
+ UPDATE_UPLOAD_FILES: files => {
+ const updateFiles = files.map((f, idx) => ({
+ id: state.length + idx,
+ file: f,
+ prevLoaded: 0,
+ loaded: 0,
+ total: 0,
+ startTime: 0,
+ prevTime: 0,
+ currentTime: 0
+ }));
+ const updatedState = state.concat(updateFiles);
+ const uniqUpdatedState = _.uniqBy(updatedState, 'file.name');
+
+ return uniqUpdatedState;
+ },
START_UPLOAD: () => {
const startTime = Date.now();
START_UPLOAD: () => {
const startTime = Date.now();
- return state.map(f => ({...f, startTime, prevTime: startTime}));
+ return state.map(f => ({ ...f, startTime, prevTime: startTime }));
},
SET_UPLOAD_PROGRESS: ({ fileId, loaded, total, currentTime }) =>
state.map(f => f.id === fileId ? {
},
SET_UPLOAD_PROGRESS: ({ fileId, loaded, total, currentTime }) =>
state.map(f => f.id === fileId ? {
import { RootState } from '~/store/store';
import { FileUploadProps } from '../../components/file-upload/file-upload';
import { Dispatch } from 'redux';
import { RootState } from '~/store/store';
import { FileUploadProps } from '../../components/file-upload/file-upload';
import { Dispatch } from 'redux';
-import { fileUploaderActions } from '~/store/file-uploader/file-uploader-actions';
+import { fileUploaderActions, getFileUploaderState } from '~/store/file-uploader/file-uploader-actions';
import { WrappedFieldProps } from 'redux-form';
import { Typography } from '@material-ui/core';
import { WrappedFieldProps } from 'redux-form';
import { Typography } from '@material-ui/core';
const mapDispatchToProps = (dispatch: Dispatch, { onDrop }: FileUploaderProps): Pick<FileUploadProps, 'onDrop'> => ({
onDrop: files => {
const mapDispatchToProps = (dispatch: Dispatch, { onDrop }: FileUploaderProps): Pick<FileUploadProps, 'onDrop'> => ({
onDrop: files => {
- if (files.length > 0) {
+ const state = dispatch<any>(getFileUploaderState());
+ if (files.length > 0 && state.length === 0) {
dispatch(fileUploaderActions.SET_UPLOAD_FILES(files));
onDrop(files);
dispatch(fileUploaderActions.SET_UPLOAD_FILES(files));
onDrop(files);
+ } else if (files.length > 0 && state.length > 0) {
+ dispatch(fileUploaderActions.UPDATE_UPLOAD_FILES(files));
+ onDrop(files);