Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INV-3528] Refactor** activities batch #3676

Merged
merged 25 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0207ccc
BatchActions.list
LocalNewsTV Nov 13, 2024
3b3b443
BatchActions.listSuccess
LocalNewsTV Nov 13, 2024
c61eb9e
remove BATCH_LIST_ERROR
LocalNewsTV Nov 13, 2024
bf79c62
BatchActions.retrieve
LocalNewsTV Nov 13, 2024
5575b76
BatchActions.retrieveSuccess
LocalNewsTV Nov 13, 2024
e76f1e5
BATCH_RETRIEVE_ERROR, BATCH_CREATE_REQUEST removal
LocalNewsTV Nov 13, 2024
5eca80d
createWithCallback, createSuccess
LocalNewsTV Nov 13, 2024
753a674
remove BATCH_CREATE_ERROR
LocalNewsTV Nov 14, 2024
fd6959f
BatchActions.update
LocalNewsTV Nov 14, 2024
7092237
BatchActions.updateSuccess
LocalNewsTV Nov 14, 2024
3e68151
Remove BATCH_UPDATE_ERROR
LocalNewsTV Nov 14, 2024
066e1ad
Batch.delete
LocalNewsTV Nov 14, 2024
0c1cd9d
Batch.deleteSuccess/Error
LocalNewsTV Nov 14, 2024
c6ff321
BatchActions.execute
LocalNewsTV Nov 14, 2024
809885e
BatchActions.executeSuccess
LocalNewsTV Nov 14, 2024
7b4a042
BatchActions.executeError
LocalNewsTV Nov 14, 2024
997d95c
BatchActions.templateList
LocalNewsTV Nov 14, 2024
cdd6820
BatchActions.templateListSuccess
LocalNewsTV Nov 14, 2024
bcecd38
remove BATCH_TEMPLATE_LIST_ERROR
LocalNewsTV Nov 14, 2024
e86b7f5
BatchActions.downloadTemplate
LocalNewsTV Nov 14, 2024
7d46168
BatchActions.downloadTemplateSuccess
LocalNewsTV Nov 14, 2024
22b236d
remove BATCH_TEMPLATE_DOWNLOAD_ERROR
LocalNewsTV Nov 14, 2024
5eb4b06
BatchActions.downloadTemplateCsv
LocalNewsTV Nov 14, 2024
03d6940
Merge branch 'dev' into 3528-activities-batch
LocalNewsTV Nov 14, 2024
ca1296c
Remove switch statement, unused variable
LocalNewsTV Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { useSelector } from 'utils/use_selector';
import { selectBatch } from 'state/reducers/batch';
import { BATCH_CREATE_REQUEST_WITH_CALLBACK, BATCH_TEMPLATE_LIST_REQUEST } from 'state/actions';
import Spinner from 'UI/Spinner/Spinner';
import { selectAuth } from 'state/reducers/auth';
import BatchActions from 'state/actions/batch/BatchActions';

const BatchCreate = () => {
const dispatch = useDispatch();

const history = useHistory();

const [data, setData] = useState(null);
const [selectedTemplate, setSelectedTemplate] = useState<string>();
const [ready, setReady] = useState<boolean>(false);

const { working, templates, item } = useSelector(selectBatch);
const { working, templates } = useSelector(selectBatch);
const authState = useSelector(selectAuth);

useEffect(() => {
Expand All @@ -29,8 +28,7 @@ const BatchCreate = () => {
if (!authState?.authenticated) {
return;
}

dispatch({ type: BATCH_TEMPLATE_LIST_REQUEST });
dispatch(BatchActions.templateList());
}, [authState?.authenticated]);

const acceptData = (d) => {
Expand All @@ -39,15 +37,14 @@ const BatchCreate = () => {

const doUpload = () => {
new Promise((resolve, reject) => {
dispatch({
type: BATCH_CREATE_REQUEST_WITH_CALLBACK,
payload: {
dispatch(
BatchActions.createWithCallback({
csvData: data,
template: selectedTemplate,
resolve,
reject
}
});
})
);
}).then((batchId) => {
history.push(`/Batch/list/${batchId}`);
});
Expand Down
28 changes: 13 additions & 15 deletions app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import BatchFileComponent from './BatchFileComponent';
import { useSelector } from 'utils/use_selector';
import { selectBatch } from 'state/reducers/batch';
import Spinner from 'UI/Spinner/Spinner';
import { BATCH_EXECUTE_REQUEST, BATCH_RETRIEVE_REQUEST, BATCH_UPDATE_REQUEST } from 'state/actions';
import BatchActions from 'state/actions/batch/BatchActions';

const StyledSelect = {
width: '70pt',
Expand All @@ -30,34 +30,32 @@ const BatchMetadata = ({ batch }) => {
}

function uploadRevisedData() {
dispatch({
type: BATCH_UPDATE_REQUEST,
payload: {
dispatch(
BatchActions.update({
id: batch.id,
csvData: fileData
}
});
csvData: fileData ?? ''
})
);
}

function doBatchExec() {
dispatch({
type: BATCH_EXECUTE_REQUEST,
payload: {
dispatch(
BatchActions.execute({
id: batch.id,
desiredActivityState: execFinalState,
treatmentOfErrorRows: execErrorRowsTreatment
}
});
})
);
}

const [fileData, setFileData] = useState(null);
const [fileData, setFileData] = useState<string>();
const [uploadReady, setUploadReady] = useState(false);

const [execFinalState, setExecFinalState] = useState('');
const [execErrorRowsTreatment, setExecErrorRowsTreatment] = useState('');

useEffect(() => {
setUploadReady(fileData !== null);
setUploadReady(fileData != null);
}, [fileData]);

const acceptFileData = (d) => {
Expand Down Expand Up @@ -164,7 +162,7 @@ const BatchDetail = ({ id }) => {
const dispatch = useDispatch();

useEffect(() => {
dispatch({ type: BATCH_RETRIEVE_REQUEST, payload: { id } });
dispatch(BatchActions.retrieve(id));
}, [id]);

function renderContent() {
Expand Down
8 changes: 4 additions & 4 deletions app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Box, Paper, Typography } from '@mui/material';
import React, { useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { Error } from '@mui/icons-material';
import { Link } from 'react-router-dom';
import { selectUserSettings } from 'state/reducers/userSettings';
import { useSelector } from 'utils/use_selector';
import { selectBatch } from 'state/reducers/batch';
import { BATCH_DELETE_REQUEST, BATCH_LIST_REQUEST } from 'state/actions';
import Spinner from 'UI/Spinner/Spinner';
import { selectAuth } from 'state/reducers/auth';
import BatchActions from 'state/actions/batch/BatchActions';

const BatchUploadList = () => {
const { working, error, list, templates, errorMessage } = useSelector(selectBatch);
Expand All @@ -22,11 +22,11 @@ const BatchUploadList = () => {
return;
}

dispatch({ type: BATCH_LIST_REQUEST });
dispatch(BatchActions.list());
}, [serial, authState?.authenticated]);

function deleteBatch(batchId) {
dispatch({ type: BATCH_DELETE_REQUEST, payload: { id: batchId } });
dispatch(BatchActions.delete(batchId));
}

function renderError() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Typography } from '@mui/material';
import React, { useEffect } from 'react';
import { useEffect } from 'react';
import TemplatePreview from './TemplatePreview';
import { useDispatch } from 'react-redux';
import { useSelector } from 'utils/use_selector';
import { selectBatch } from 'state/reducers/batch';
import { BATCH_TEMPLATE_LIST_REQUEST } from 'state/actions';
import Spinner from 'UI/Spinner/Spinner';
import { selectAuth } from 'state/reducers/auth';
import BatchActions from 'state/actions/batch/BatchActions';

const TemplateDownloadList = () => {
const dispatch = useDispatch();
Expand All @@ -17,8 +17,7 @@ const TemplateDownloadList = () => {
if (!authState?.authenticated) {
return;
}

dispatch({ type: BATCH_TEMPLATE_LIST_REQUEST });
dispatch(BatchActions.templateList());
}, [authState?.authenticated]);

if (working) {
Expand Down
20 changes: 7 additions & 13 deletions app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Accordion, AccordionDetails, AccordionSummary, Box, Button, Typography } from '@mui/material';
import React, { useEffect, useState } from 'react';
import { useEffect, useState } from 'react';

import { CodeTableReference } from './CodeTableReference';
import { useDispatch } from 'react-redux';
Expand All @@ -8,8 +8,8 @@ import { Download } from '@mui/icons-material';
import { selectUserSettings } from 'state/reducers/userSettings';
import { useSelector } from 'utils/use_selector';
import { selectBatch } from 'state/reducers/batch';
import { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST } from 'state/actions';
import Spinner from 'UI/Spinner/Spinner';
import BatchActions from 'state/actions/batch/BatchActions';

const TemplatePreview = ({ name, id }) => {
const dispatch = useDispatch();
Expand All @@ -23,12 +23,7 @@ const TemplatePreview = ({ name, id }) => {

useEffect(() => {
if (expanded && !detail) {
dispatch({
type: BATCH_TEMPLATE_DOWNLOAD_REQUEST,
payload: {
key: id
}
});
dispatch(BatchActions.downloadTemplate(id));
}
}, [id, expanded]);

Expand All @@ -44,13 +39,12 @@ const TemplatePreview = ({ name, id }) => {

const downloadTemplate = (key: string) => {
new Promise((resolve, reject) => {
dispatch({
type: BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST,
payload: {
dispatch(
BatchActions.downloadTemplateCsv({
key: id,
resolve
}
});
})
);
}).then((data) => {
const dataUrl = `data:text/csv;base64,${btoa(data as string)}`;
const downloadLink = document.createElement('a');
Expand Down
26 changes: 0 additions & 26 deletions app/src/state/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,32 +207,6 @@ export const CUSTOM_LAYER_DRAWN = 'CUSTOM_LAYER_DRAWN';
export const REMOVE_CLIENT_BOUNDARY = 'REMOVE_CLIENT_BOUNDARY';
export const REMOVE_SERVER_BOUNDARY = 'REMOVE_SERVER_BOUNDARY';

export const BATCH_LIST_REQUEST = 'BATCH_LIST_REQUEST';
export const BATCH_LIST_SUCCESS = 'BATCH_LIST_SUCCESS';
export const BATCH_LIST_ERROR = 'BATCH_LIST_ERROR';
export const BATCH_RETRIEVE_REQUEST = 'BATCH_RETRIEVE_REQUEST';
export const BATCH_RETRIEVE_SUCCESS = 'BATCH_RETRIEVE_SUCCESS';
export const BATCH_RETRIEVE_ERROR = 'BATCH_RETRIEVE_ERROR';
export const BATCH_CREATE_REQUEST = 'BATCH_CREATE_REQUEST';
export const BATCH_CREATE_REQUEST_WITH_CALLBACK = 'BATCH_CREATE_REQUEST_WITH_CALLBACK';
export const BATCH_CREATE_SUCCESS = 'BATCH_CREATE_SUCCESS';
export const BATCH_CREATE_ERROR = 'BATCH_CREATE_ERROR';
export const BATCH_UPDATE_REQUEST = 'BATCH_UPDATE_REQUEST';
export const BATCH_UPDATE_SUCCESS = 'BATCH_UPDATE_SUCCESS';
export const BATCH_UPDATE_ERROR = 'BATCH_UPDATE_ERROR';
export const BATCH_DELETE_REQUEST = 'BATCH_DELETE_REQUEST';
export const BATCH_DELETE_SUCCESS = 'BATCH_DELETE_SUCCESS';
export const BATCH_DELETE_ERROR = 'BATCH_DELETE_ERROR';
export const BATCH_EXECUTE_REQUEST = 'BATCH_EXECUTE_REQUEST';
export const BATCH_EXECUTE_SUCCESS = 'BATCH_EXECUTE_SUCCESS';
export const BATCH_EXECUTE_ERROR = 'BATCH_EXECUTE_ERROR';
export const BATCH_TEMPLATE_LIST_REQUEST = 'BATCH_TEMPLATE_LIST_REQUEST';
export const BATCH_TEMPLATE_LIST_SUCCESS = 'BATCH_TEMPLATE_LIST_SUCCESS';
export const BATCH_TEMPLATE_LIST_ERROR = 'BATCH_TEMPLATE_LIST_ERROR';
export const BATCH_TEMPLATE_DOWNLOAD_REQUEST = 'BATCH_TEMPLATE_DOWNLOAD_REQUEST';
export const BATCH_TEMPLATE_DOWNLOAD_SUCCESS = 'BATCH_TEMPLATE_DOWNLOAD_SUCCESS';
export const BATCH_TEMPLATE_DOWNLOAD_ERROR = 'BATCH_TEMPLATE_DOWNLOAD_ERROR';
export const BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST = 'BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST';
export const CSV_LINK_CLICKED = 'CSV_LINK_CLICKED';

export const EXPORT_CONFIG_LOAD_REQUEST = 'EXPORT_CONFIG_LOAD_REQUEST';
Expand Down
71 changes: 71 additions & 0 deletions app/src/state/actions/batch/BatchActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { createAction } from '@reduxjs/toolkit';
import { DeepBatch, DeepTemplate, ShallowBatch } from 'state/reducers/batch';

interface IBatchCreateWithCallback {
csvData: Record<string, any> | null;
template?: string;
resolve: Function;
reject: Function;
}

export interface IBatchSuccess extends DeepBatch {
batchId: string;
}
export interface IBatchUpdate {
id: string;
csvData: string;
}
export interface IBatchExecute {
id: string;
desiredActivityState: string;
treatmentOfErrorRows: string;
}

export interface IBatchListTemplate {
name: string;
key: string;
}

export interface IBatchDownloadTemplate {
key: string;
data: DeepTemplate;
}

export interface IBatchDownloadTemplateCsv {
key: string;
resolve: any;
}
class BatchActions {
private static readonly PREFIX = 'Batch';

static readonly list = createAction(`${this.PREFIX}/list`);
static readonly listSuccess = createAction<ShallowBatch[]>(`${this.PREFIX}/listSuccess`);

static readonly retrieve = createAction<string>(`${this.PREFIX}/retrieve`);
static readonly retrieveSuccess = createAction<DeepBatch>(`${this.PREFIX}/retrieveSuccess`);

static readonly createWithCallback = createAction<IBatchCreateWithCallback>(`${this.PREFIX}/createWithCallback`);
static readonly createSuccess = createAction<IBatchSuccess>(`${this.PREFIX}/create`);

static readonly update = createAction<IBatchUpdate>(`${this.PREFIX}/update`);
static readonly updateSuccess = createAction<IBatchSuccess>(`${this.PREFIX}/updateSuccess`);

static readonly delete = createAction<string>(`${this.PREFIX}/delete`);
static readonly deleteSuccess = createAction(`${this.PREFIX}/deleteSuccess`);
static readonly deleteError = createAction(`${this.PREFIX}/deleteError`);

static readonly execute = createAction<IBatchExecute>(`${this.PREFIX}/execute`);
static readonly executeSuccess = createAction<DeepBatch>(`${this.PREFIX}/executeSuccess`);
static readonly executeError = createAction<string>(`${this.PREFIX}/executeError`);

static readonly templateList = createAction(`${this.PREFIX}/templateList`);
static readonly templateListSuccess = createAction<IBatchListTemplate[]>(`${this.PREFIX}/templateListSuccess`);

static readonly downloadTemplate = createAction<string>(`${this.PREFIX}/downloadTemplate`);
static readonly downloadTemplateSuccess = createAction<IBatchDownloadTemplate>(
`${this.PREFIX}/downloadTemplateSuccess`
);
static readonly downloadTemplateCsv = createAction<IBatchDownloadTemplateCsv>(`${this.PREFIX}/downloadTemplateCsv`);
}

export default BatchActions;
Loading
Loading