From 0207cccf8173499085d4fff77ae3c06d72f0765d Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:41:00 -0800 Subject: [PATCH 01/24] BatchActions.list --- .../Batch/batch-upload/BatchUploadList.tsx | 5 +- app/src/state/actions.tsx | 52 +++++++++---------- app/src/state/actions/batch/BatchActions.ts | 42 +++++++++++++++ app/src/state/reducers/batch.ts | 22 ++++---- app/src/state/sagas/batch.ts | 4 +- 5 files changed, 84 insertions(+), 41 deletions(-) create mode 100644 app/src/state/actions/batch/BatchActions.ts diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx index 3077e41b2..3fe298bdc 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx @@ -6,9 +6,10 @@ 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 { BATCH_DELETE_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); @@ -22,7 +23,7 @@ const BatchUploadList = () => { return; } - dispatch({ type: BATCH_LIST_REQUEST }); + dispatch(BatchActions.list()); }, [serial, authState?.authenticated]); function deleteBatch(batchId) { diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 8a50a2cc1..b99c10389 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,3 +1,29 @@ +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 SET_APP_MODE = 'SET_APP_MODE'; export const TOGGLE_PANEL = 'TOGGLE_PANEL'; export const OVERLAY_MENU_TOGGLE = 'OVERLAY_MENU_TOGGLE'; @@ -207,32 +233,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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts new file mode 100644 index 000000000..24312afc2 --- /dev/null +++ b/app/src/state/actions/batch/BatchActions.ts @@ -0,0 +1,42 @@ +import { createAction } from '@reduxjs/toolkit'; +import { DeepBatch, ShallowBatch } from 'state/reducers/batch'; + +interface IBatchCreate extends DeepBatch { + createdBatchId: string; +} +class BatchActions { + private static readonly PREFIX = 'Batch'; + + static readonly list = createAction(`${this.PREFIX}/list`); + static readonly listSuccess = createAction(`${this.PREFIX}/listSuccess`); + + static readonly retrieve = createAction(`${this.PREFIX}/retrieve`); + static readonly retrieveSuccess = createAction(`${this.PREFIX}/retrieveSuccess`); + + static readonly createWithCallback = createAction(`${this.PREFIX}/createWithCallback`); + static readonly createSuccess = createAction(`${this.PREFIX}/create`); + static readonly createError = createAction(`${this.PREFIX}/createError`); + + static readonly update = createAction(`${this.PREFIX}/update`); + static readonly updateSuccess = createAction(`${this.PREFIX}/updateSuccess`); + static readonly updateError = createAction(`${this.PREFIX}/updateError`); + + static readonly delete = createAction(`${this.PREFIX}/delete`); + static readonly deleteSuccess = createAction(`${this.PREFIX}/deleteSuccess`); + static readonly deleteError = createAction(`${this.PREFIX}/deleteError`); + + static readonly execute = createAction(`${this.PREFIX}/execute`); + static readonly executeSuccess = createAction(`${this.PREFIX}/executeSuccess`); + static readonly executeError = createAction(`${this.PREFIX}/executeError`); + + static readonly templateList = createAction(`${this.PREFIX}/templateList`); + static readonly templateListSuccess = createAction(`${this.PREFIX}/templateListSuccess`); + static readonly templateListError = createAction(`${this.PREFIX}/templateListError`); + + static readonly downloadTemplate = createAction(`${this.PREFIX}/downloadTemplate`); + static readonly downloadTemplateSuccess = createAction(`${this.PREFIX}/downloadTemplateSuccess`); + static readonly downloadTemplateError = createAction(`${this.PREFIX}/downloadTemplateError`); + static readonly downloadTemplateCsv = createAction(`${this.PREFIX}/downloadTemplateCsv`); +} + +export default BatchActions; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 9ecedc0b8..6143aea36 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -11,7 +11,6 @@ import { BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, BATCH_LIST_ERROR, - BATCH_LIST_REQUEST, BATCH_LIST_SUCCESS, BATCH_RETRIEVE_ERROR, BATCH_RETRIEVE_REQUEST, @@ -26,25 +25,26 @@ import { BATCH_UPDATE_REQUEST, BATCH_UPDATE_SUCCESS } from '../actions'; +import BatchActions from 'state/actions/batch/BatchActions'; -interface DeepBatch { +export interface DeepBatch { created_at: string; id: string | number; } -interface ShallowBatch { +export interface ShallowBatch { created_at: string; template: string; status: string; id: string | number; } -interface ShallowTemplate { +export interface ShallowTemplate { name: string; key: string; } -interface DeepTemplate { +export interface DeepTemplate { name: string; key: string; } @@ -82,6 +82,11 @@ function createBatchReducer() { return (state = initialState, action) => { return createNextState(state, (draftState: Draft) => { + if (BatchActions.list.match(action)) { + draftState.working = true; + draftState.error = false; + draftState.list = []; + } switch (action.type) { case BATCH_LIST_SUCCESS: draftState.working = false; @@ -93,11 +98,6 @@ function createBatchReducer() { draftState.error = true; draftState.list = []; break; - case BATCH_LIST_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.list = []; - break; case BATCH_RETRIEVE_REQUEST: draftState.working = true; draftState.error = false; @@ -210,7 +210,7 @@ function createBatchReducer() { 'monitoring_chemical_treatment', 'monitoring_chemical_treatment_temp', 'monitoring_mechanical_treatment', - 'monitoring_mechanical_treatment_temp', + 'monitoring_mechanical_treatment_temp' ].includes(template.key) ); break; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 91fa5c46a..2ac363d70 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -9,7 +9,6 @@ import { BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, - BATCH_LIST_REQUEST, BATCH_LIST_SUCCESS, BATCH_RETRIEVE_REQUEST, BATCH_RETRIEVE_SUCCESS, @@ -21,6 +20,7 @@ import { BATCH_UPDATE_REQUEST, BATCH_UPDATE_SUCCESS } from 'state/actions'; +import BatchActions from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; import { getCurrentJWT } from 'state/sagas/auth/auth'; @@ -197,7 +197,7 @@ function* executeBatch(action) { function* batchSaga() { yield all([ - takeEvery(BATCH_LIST_REQUEST, listBatches), + takeEvery(BatchActions.list, listBatches), takeLatest(BATCH_RETRIEVE_REQUEST, getBatch), takeEvery(BATCH_CREATE_REQUEST, createBatch), takeEvery(BATCH_UPDATE_REQUEST, updateBatch), From 3b3b44332d68e2fcbe98e0e551ae6752d5686e10 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:44:36 -0800 Subject: [PATCH 02/24] BatchActions.listSuccess --- app/src/state/actions.tsx | 1 - app/src/state/reducers/batch.ts | 331 ++++++++++++++++---------------- app/src/state/sagas/batch.ts | 6 +- 3 files changed, 168 insertions(+), 170 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index b99c10389..d282159f8 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 6143aea36..07ee95f92 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -11,7 +11,6 @@ import { BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, BATCH_LIST_ERROR, - BATCH_LIST_SUCCESS, BATCH_RETRIEVE_ERROR, BATCH_RETRIEVE_REQUEST, BATCH_RETRIEVE_SUCCESS, @@ -86,171 +85,171 @@ function createBatchReducer() { draftState.working = true; draftState.error = false; draftState.list = []; - } - switch (action.type) { - case BATCH_LIST_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.list = action.payload; - break; - case BATCH_LIST_ERROR: - draftState.working = false; - draftState.error = true; - draftState.list = []; - break; - case BATCH_RETRIEVE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; - case BATCH_RETRIEVE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = action.payload; - break; - case BATCH_RETRIEVE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.item = null; - break; - case BATCH_CREATE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = action.payload; - draftState.createdBatchId = action.payload.batchId; - break; - case BATCH_CREATE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.item = null; - draftState.createdBatchId = null; - break; - case BATCH_CREATE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - draftState.createdBatchId = null; - break; - case BATCH_EXECUTE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = action.payload.result; - break; - case BATCH_EXECUTE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.errorMessage = `Could not execute batch ${JSON.stringify(action.payload?.message, null, 2)}`; - draftState.item = null; - break; - case BATCH_EXECUTE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; - case BATCH_UPDATE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = null; - break; - case BATCH_UPDATE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.item = null; - break; - case BATCH_UPDATE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; - case BATCH_DELETE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; - case BATCH_DELETE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = null; - break; - case BATCH_DELETE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.errorMessage = 'Could not delete batch'; - draftState.item = null; - break; - case BATCH_TEMPLATE_LIST_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.templates = []; - break; - case BATCH_TEMPLATE_LIST_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.templates = action.payload.filter((template) => - [ - 'observation_aquatic_plant', - 'observation_aquatic_plant_temp', - 'observation_terrestrial_plant', - 'observation_terrestrial_plant_temp', - 'treatment_mechanical_terrestrial_plant', - 'treatment_mechanical_terrestrial_plant_temp', - 'treatment_mechanical_aquatic_plant', - 'treatment_mechanical_aquatic_plant_temp', - 'treatment_chemical_terrestrial_plant', - 'treatment_chemical_terrestrial_plant_temp', - 'treatment_chemical_aquatic_plant', - 'treatment_chemical_aquatic_plant_temp', - 'biocontrol_release', - 'biocontrol_release_temp', - 'biocontrol_collection', - 'biocontrol_collection_temp', - 'monitoring_biocontrol_dispersal_terrestrial_plant', - 'monitoring_biocontrol_dispersal_terrestrial_plant_temp', - 'monitoring_biocontrol_release_terrestrial_plant', - 'monitoring_chemical_treatment', - 'monitoring_chemical_treatment_temp', - 'monitoring_mechanical_treatment', - 'monitoring_mechanical_treatment_temp' - ].includes(template.key) - ); - break; - case BATCH_TEMPLATE_LIST_ERROR: - draftState.working = false; - draftState.error = true; - draftState.templates = []; - break; - case BATCH_TEMPLATE_DOWNLOAD_REQUEST: - draftState.templateDetail = { - ...state.templateDetail, - [action.payload.key]: { - working: true, - error: false, - data: null - } - }; - break; - case BATCH_TEMPLATE_DOWNLOAD_SUCCESS: - draftState.templateDetail = { - ...state.templateDetail, - [action.payload.key]: { - working: false, - error: false, - data: action.payload.data - } - }; - break; - case BATCH_TEMPLATE_DOWNLOAD_ERROR: - draftState.templateDetail = { - ...state.templateDetail, - [action.payload.key]: { - working: false, - error: true, - data: null - } - }; - break; - default: - break; + } else if (BatchActions.listSuccess.match(action)) { + draftState.working = false; + draftState.error = false; + draftState.list = action.payload; + } else { + switch (action.type) { + case BATCH_LIST_ERROR: + draftState.working = false; + draftState.error = true; + draftState.list = []; + break; + case BATCH_RETRIEVE_REQUEST: + draftState.working = true; + draftState.error = false; + draftState.item = null; + break; + case BATCH_RETRIEVE_SUCCESS: + draftState.working = false; + draftState.error = false; + draftState.item = action.payload; + break; + case BATCH_RETRIEVE_ERROR: + draftState.working = false; + draftState.error = true; + draftState.item = null; + break; + case BATCH_CREATE_SUCCESS: + draftState.working = false; + draftState.error = false; + draftState.item = action.payload; + draftState.createdBatchId = action.payload.batchId; + break; + case BATCH_CREATE_ERROR: + draftState.working = false; + draftState.error = true; + draftState.item = null; + draftState.createdBatchId = null; + break; + case BATCH_CREATE_REQUEST: + draftState.working = true; + draftState.error = false; + draftState.item = null; + draftState.createdBatchId = null; + break; + case BATCH_EXECUTE_SUCCESS: + draftState.working = false; + draftState.error = false; + draftState.item = action.payload.result; + break; + case BATCH_EXECUTE_ERROR: + draftState.working = false; + draftState.error = true; + draftState.errorMessage = `Could not execute batch ${JSON.stringify(action.payload?.message, null, 2)}`; + draftState.item = null; + break; + case BATCH_EXECUTE_REQUEST: + draftState.working = true; + draftState.error = false; + draftState.item = null; + break; + case BATCH_UPDATE_SUCCESS: + draftState.working = false; + draftState.error = false; + draftState.item = null; + break; + case BATCH_UPDATE_ERROR: + draftState.working = false; + draftState.error = true; + draftState.item = null; + break; + case BATCH_UPDATE_REQUEST: + draftState.working = true; + draftState.error = false; + draftState.item = null; + break; + case BATCH_DELETE_REQUEST: + draftState.working = true; + draftState.error = false; + draftState.item = null; + break; + case BATCH_DELETE_SUCCESS: + draftState.working = false; + draftState.error = false; + draftState.item = null; + break; + case BATCH_DELETE_ERROR: + draftState.working = false; + draftState.error = true; + draftState.errorMessage = 'Could not delete batch'; + draftState.item = null; + break; + case BATCH_TEMPLATE_LIST_REQUEST: + draftState.working = true; + draftState.error = false; + draftState.templates = []; + break; + case BATCH_TEMPLATE_LIST_SUCCESS: + draftState.working = false; + draftState.error = false; + draftState.templates = action.payload.filter((template) => + [ + 'observation_aquatic_plant', + 'observation_aquatic_plant_temp', + 'observation_terrestrial_plant', + 'observation_terrestrial_plant_temp', + 'treatment_mechanical_terrestrial_plant', + 'treatment_mechanical_terrestrial_plant_temp', + 'treatment_mechanical_aquatic_plant', + 'treatment_mechanical_aquatic_plant_temp', + 'treatment_chemical_terrestrial_plant', + 'treatment_chemical_terrestrial_plant_temp', + 'treatment_chemical_aquatic_plant', + 'treatment_chemical_aquatic_plant_temp', + 'biocontrol_release', + 'biocontrol_release_temp', + 'biocontrol_collection', + 'biocontrol_collection_temp', + 'monitoring_biocontrol_dispersal_terrestrial_plant', + 'monitoring_biocontrol_dispersal_terrestrial_plant_temp', + 'monitoring_biocontrol_release_terrestrial_plant', + 'monitoring_chemical_treatment', + 'monitoring_chemical_treatment_temp', + 'monitoring_mechanical_treatment', + 'monitoring_mechanical_treatment_temp' + ].includes(template.key) + ); + break; + case BATCH_TEMPLATE_LIST_ERROR: + draftState.working = false; + draftState.error = true; + draftState.templates = []; + break; + case BATCH_TEMPLATE_DOWNLOAD_REQUEST: + draftState.templateDetail = { + ...state.templateDetail, + [action.payload.key]: { + working: true, + error: false, + data: null + } + }; + break; + case BATCH_TEMPLATE_DOWNLOAD_SUCCESS: + draftState.templateDetail = { + ...state.templateDetail, + [action.payload.key]: { + working: false, + error: false, + data: action.payload.data + } + }; + break; + case BATCH_TEMPLATE_DOWNLOAD_ERROR: + draftState.templateDetail = { + ...state.templateDetail, + [action.payload.key]: { + working: false, + error: true, + data: null + } + }; + break; + default: + break; + } } }); }; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 2ac363d70..e984d2f53 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,3 +1,4 @@ +import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { BATCH_CREATE_REQUEST, @@ -9,7 +10,6 @@ import { BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, - BATCH_LIST_SUCCESS, BATCH_RETRIEVE_REQUEST, BATCH_RETRIEVE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, @@ -24,7 +24,7 @@ import BatchActions from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; import { getCurrentJWT } from 'state/sagas/auth/auth'; -function* listBatches(action) { +function* listBatches(action: PayloadAction) { yield call(listTemplates, action); const configuration = yield select(selectConfiguration); @@ -34,7 +34,7 @@ function* listBatches(action) { } }); - yield put({ type: BATCH_LIST_SUCCESS, payload: (yield res.json())?.result }); + yield put(BatchActions.listSuccess((yield res.json())?.result)); } function* getBatch(action) { From c61eb9e0f895a2fae1aa9e55951b2bcf40f9baf5 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:45:52 -0800 Subject: [PATCH 03/24] remove BATCH_LIST_ERROR --- app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx | 2 +- app/src/state/actions.tsx | 1 - app/src/state/reducers/batch.ts | 6 ------ 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx index 3fe298bdc..87c504fa9 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx @@ -1,5 +1,5 @@ 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'; diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index d282159f8..8af4ecdb2 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 07ee95f92..0112ae149 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -10,7 +10,6 @@ import { BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, - BATCH_LIST_ERROR, BATCH_RETRIEVE_ERROR, BATCH_RETRIEVE_REQUEST, BATCH_RETRIEVE_SUCCESS, @@ -91,11 +90,6 @@ function createBatchReducer() { draftState.list = action.payload; } else { switch (action.type) { - case BATCH_LIST_ERROR: - draftState.working = false; - draftState.error = true; - draftState.list = []; - break; case BATCH_RETRIEVE_REQUEST: draftState.working = true; draftState.error = false; From bf79c6249446665b4b66d2e549685c32c3dab738 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:52:00 -0800 Subject: [PATCH 04/24] BatchActions.retrieve --- .../UI/Overlay/Batch/batch-upload/BatchDetail.tsx | 5 +++-- app/src/state/actions.tsx | 1 - app/src/state/reducers/batch.ts | 10 ++++------ app/src/state/sagas/batch.ts | 12 +++++------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx index 0e32765fb..b854e017c 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx @@ -7,7 +7,8 @@ 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 { BATCH_EXECUTE_REQUEST, BATCH_UPDATE_REQUEST } from 'state/actions'; +import BatchActions from 'state/actions/batch/BatchActions'; const StyledSelect = { width: '70pt', @@ -164,7 +165,7 @@ const BatchDetail = ({ id }) => { const dispatch = useDispatch(); useEffect(() => { - dispatch({ type: BATCH_RETRIEVE_REQUEST, payload: { id } }); + dispatch(BatchActions.retrieve(id)); }, [id]); function renderContent() { diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 8af4ecdb2..a832e1b37 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 0112ae149..55ec1ff9a 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -11,7 +11,6 @@ import { BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, BATCH_RETRIEVE_ERROR, - BATCH_RETRIEVE_REQUEST, BATCH_RETRIEVE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, @@ -88,13 +87,12 @@ function createBatchReducer() { draftState.working = false; draftState.error = false; draftState.list = action.payload; + } else if (BatchActions.retrieve.match(action)) { + draftState.working = true; + draftState.error = false; + draftState.item = null; } else { switch (action.type) { - case BATCH_RETRIEVE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; case BATCH_RETRIEVE_SUCCESS: draftState.working = false; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index e984d2f53..6939e582b 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -10,7 +10,6 @@ import { BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, - BATCH_RETRIEVE_REQUEST, BATCH_RETRIEVE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST, @@ -37,11 +36,10 @@ function* listBatches(action: PayloadAction) { yield put(BatchActions.listSuccess((yield res.json())?.result)); } -function* getBatch(action) { +function* getBatch(action: PayloadAction) { const configuration = yield select(selectConfiguration); - const { id } = action.payload; - const res = yield fetch(configuration.API_BASE + `/api/batch/` + encodeURIComponent(id), { + const res = yield fetch(configuration.API_BASE + `/api/batch/` + encodeURIComponent(action.payload), { headers: { Authorization: yield getCurrentJWT() } @@ -98,7 +96,7 @@ function* updateBatch(action) { }); yield put({ type: BATCH_UPDATE_SUCCESS, payload: res?.json() }); - yield put({ type: BATCH_RETRIEVE_REQUEST, payload: { id } }); + yield put(BatchActions.retrieve(id)); } function* deleteBatch(action: any) { @@ -189,7 +187,7 @@ function* executeBatch(action) { if (data.code === 200) { yield put({ type: BATCH_EXECUTE_SUCCESS, payload: data }); - yield put({ type: BATCH_RETRIEVE_REQUEST, payload: { id } }); + yield put(BatchActions.retrieve(id)); } else { yield put({ type: BATCH_EXECUTE_ERROR, payload: data }); } @@ -198,7 +196,7 @@ function* executeBatch(action) { function* batchSaga() { yield all([ takeEvery(BatchActions.list, listBatches), - takeLatest(BATCH_RETRIEVE_REQUEST, getBatch), + takeLatest(BatchActions.retrieve, getBatch), takeEvery(BATCH_CREATE_REQUEST, createBatch), takeEvery(BATCH_UPDATE_REQUEST, updateBatch), takeEvery(BATCH_DELETE_REQUEST, deleteBatch), From 5575b768a7c6b0027d073a00ca8e1d1a3593f81f Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:53:13 -0800 Subject: [PATCH 05/24] BatchActions.retrieveSuccess --- app/src/state/actions.tsx | 1 - app/src/state/reducers/batch.ts | 10 ++++------ app/src/state/sagas/batch.ts | 3 +-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index a832e1b37..eeef0aa85 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 55ec1ff9a..4e4b969ce 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -11,7 +11,6 @@ import { BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, BATCH_RETRIEVE_ERROR, - BATCH_RETRIEVE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, @@ -91,13 +90,12 @@ function createBatchReducer() { draftState.working = true; draftState.error = false; draftState.item = null; + } else if (BatchActions.retrieveSuccess.match(action)) { + draftState.working = false; + draftState.error = false; + draftState.item = action.payload; } else { switch (action.type) { - case BATCH_RETRIEVE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = action.payload; - break; case BATCH_RETRIEVE_ERROR: draftState.working = false; draftState.error = true; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 6939e582b..26f84250e 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -10,7 +10,6 @@ import { BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, - BATCH_RETRIEVE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, @@ -46,7 +45,7 @@ function* getBatch(action: PayloadAction) { }); const data = yield res.json(); - yield put({ type: BATCH_RETRIEVE_SUCCESS, payload: data.result }); + yield put(BatchActions.retrieveSuccess(data.result)); } function* createBatch(action) { From e76f1e51e2e81540d794b7fb165481d8693bcbc2 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:58:55 -0800 Subject: [PATCH 06/24] BATCH_RETRIEVE_ERROR, BATCH_CREATE_REQUEST removal --- app/src/state/actions.tsx | 2 -- app/src/state/reducers/batch.ts | 13 ------------- app/src/state/sagas/batch.ts | 17 ----------------- 3 files changed, 32 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index eeef0aa85..704d95bec 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,5 +1,3 @@ -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'; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 4e4b969ce..485e7e15c 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -2,7 +2,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { BATCH_CREATE_ERROR, - BATCH_CREATE_REQUEST, BATCH_CREATE_SUCCESS, BATCH_DELETE_ERROR, BATCH_DELETE_REQUEST, @@ -10,7 +9,6 @@ import { BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, - BATCH_RETRIEVE_ERROR, BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, @@ -96,11 +94,6 @@ function createBatchReducer() { draftState.item = action.payload; } else { switch (action.type) { - case BATCH_RETRIEVE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.item = null; - break; case BATCH_CREATE_SUCCESS: draftState.working = false; draftState.error = false; @@ -113,12 +106,6 @@ function createBatchReducer() { draftState.item = null; draftState.createdBatchId = null; break; - case BATCH_CREATE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - draftState.createdBatchId = null; - break; case BATCH_EXECUTE_SUCCESS: draftState.working = false; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 26f84250e..cf3f9462b 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,7 +1,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { - BATCH_CREATE_REQUEST, BATCH_CREATE_REQUEST_WITH_CALLBACK, BATCH_CREATE_SUCCESS, BATCH_DELETE_ERROR, @@ -48,21 +47,6 @@ function* getBatch(action: PayloadAction) { yield put(BatchActions.retrieveSuccess(data.result)); } -function* createBatch(action) { - const configuration = yield select(selectConfiguration); - - const res = yield fetch(configuration.API_BASE + `/api/batch`, { - method: 'POST', - headers: { - Authorization: yield getCurrentJWT(), - 'Content-Type': 'application/json' - }, - body: JSON.stringify(action.payload) - }); - - yield put({ type: BATCH_CREATE_SUCCESS, payload: yield res.json() }); -} - function* createBatchWithCallback(action) { const configuration = yield select(selectConfiguration); const { resolve, reject } = action.payload; @@ -196,7 +180,6 @@ function* batchSaga() { yield all([ takeEvery(BatchActions.list, listBatches), takeLatest(BatchActions.retrieve, getBatch), - takeEvery(BATCH_CREATE_REQUEST, createBatch), takeEvery(BATCH_UPDATE_REQUEST, updateBatch), takeEvery(BATCH_DELETE_REQUEST, deleteBatch), takeEvery(BATCH_DELETE_SUCCESS, listBatches), From 5eca80d678b6d4c3c20ff201773c81969d57ab74 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:39:41 -0800 Subject: [PATCH 07/24] createWithCallback, createSuccess --- .../UI/Overlay/Batch/batch-upload/BatchCreate.tsx | 15 +++++++-------- app/src/state/actions.tsx | 2 -- app/src/state/actions/batch/BatchActions.ts | 15 +++++++++++---- app/src/state/reducers/batch.ts | 12 +++++------- app/src/state/sagas/batch.ts | 9 ++++----- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx index 2c52f363d..891dec497 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx @@ -5,20 +5,20 @@ 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 { 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(); const [ready, setReady] = useState(false); - const { working, templates, item } = useSelector(selectBatch); + const { working, templates } = useSelector(selectBatch); const authState = useSelector(selectAuth); useEffect(() => { @@ -39,15 +39,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}`); }); diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 704d95bec..e446395da 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,5 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 24312afc2..88f474777 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -1,8 +1,15 @@ import { createAction } from '@reduxjs/toolkit'; import { DeepBatch, ShallowBatch } from 'state/reducers/batch'; -interface IBatchCreate extends DeepBatch { - createdBatchId: string; +interface IBatchCreateWithCallback { + csvData: Record | null; + template?: string; + resolve: Function; + reject: Function; +} + +export interface IBatchSuccess extends DeepBatch { + batchId: string; } class BatchActions { private static readonly PREFIX = 'Batch'; @@ -13,8 +20,8 @@ class BatchActions { static readonly retrieve = createAction(`${this.PREFIX}/retrieve`); static readonly retrieveSuccess = createAction(`${this.PREFIX}/retrieveSuccess`); - static readonly createWithCallback = createAction(`${this.PREFIX}/createWithCallback`); - static readonly createSuccess = createAction(`${this.PREFIX}/create`); + static readonly createWithCallback = createAction(`${this.PREFIX}/createWithCallback`); + static readonly createSuccess = createAction(`${this.PREFIX}/create`); static readonly createError = createAction(`${this.PREFIX}/createError`); static readonly update = createAction(`${this.PREFIX}/update`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 485e7e15c..8118271b3 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -2,7 +2,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { BATCH_CREATE_ERROR, - BATCH_CREATE_SUCCESS, BATCH_DELETE_ERROR, BATCH_DELETE_REQUEST, BATCH_DELETE_SUCCESS, @@ -92,14 +91,13 @@ function createBatchReducer() { draftState.working = false; draftState.error = false; draftState.item = action.payload; + } else if (BatchActions.createSuccess.match(action)) { + draftState.working = false; + draftState.error = false; + draftState.item = action.payload; + draftState.createdBatchId = action.payload.batchId; } else { switch (action.type) { - case BATCH_CREATE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = action.payload; - draftState.createdBatchId = action.payload.batchId; - break; case BATCH_CREATE_ERROR: draftState.working = false; draftState.error = true; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index cf3f9462b..182e53617 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,8 +1,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { - BATCH_CREATE_REQUEST_WITH_CALLBACK, - BATCH_CREATE_SUCCESS, BATCH_DELETE_ERROR, BATCH_DELETE_REQUEST, BATCH_DELETE_SUCCESS, @@ -17,6 +15,7 @@ import { BATCH_UPDATE_REQUEST, BATCH_UPDATE_SUCCESS } from 'state/actions'; + import BatchActions from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; import { getCurrentJWT } from 'state/sagas/auth/auth'; @@ -49,7 +48,7 @@ function* getBatch(action: PayloadAction) { function* createBatchWithCallback(action) { const configuration = yield select(selectConfiguration); - const { resolve, reject } = action.payload; + const { resolve } = action.payload; const res = yield fetch(configuration.API_BASE + `/api/batch`, { method: 'POST', @@ -61,7 +60,7 @@ function* createBatchWithCallback(action) { }); const resultBody = yield res.json(); - yield put({ type: BATCH_CREATE_SUCCESS, payload: resultBody }); + yield put(BatchActions.createSuccess(resultBody)); yield call(resolve, resultBody?.batchId); } @@ -186,7 +185,7 @@ function* batchSaga() { takeLatest(BATCH_TEMPLATE_LIST_REQUEST, listTemplates), takeEvery(BATCH_TEMPLATE_DOWNLOAD_REQUEST, templateDetail), takeLatest(BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, templateCSV), - takeLatest(BATCH_CREATE_REQUEST_WITH_CALLBACK, createBatchWithCallback), + takeLatest(BatchActions.createWithCallback, createBatchWithCallback), takeLatest(BATCH_EXECUTE_REQUEST, executeBatch) ]); } From 753a67471d31a60a4d2c9ca243f03761ad686bbc Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:34:03 -0800 Subject: [PATCH 08/24] remove BATCH_CREATE_ERROR --- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 1 - app/src/state/reducers/batch.ts | 7 ------- 3 files changed, 9 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index e446395da..553ab3e90 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 88f474777..88e7d51d5 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -22,7 +22,6 @@ class BatchActions { static readonly createWithCallback = createAction(`${this.PREFIX}/createWithCallback`); static readonly createSuccess = createAction(`${this.PREFIX}/create`); - static readonly createError = createAction(`${this.PREFIX}/createError`); static readonly update = createAction(`${this.PREFIX}/update`); static readonly updateSuccess = createAction(`${this.PREFIX}/updateSuccess`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 8118271b3..58a1268f1 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -1,7 +1,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { - BATCH_CREATE_ERROR, BATCH_DELETE_ERROR, BATCH_DELETE_REQUEST, BATCH_DELETE_SUCCESS, @@ -98,12 +97,6 @@ function createBatchReducer() { draftState.createdBatchId = action.payload.batchId; } else { switch (action.type) { - case BATCH_CREATE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.item = null; - draftState.createdBatchId = null; - break; case BATCH_EXECUTE_SUCCESS: draftState.working = false; draftState.error = false; From fd6959f9e792ab3ae24a8e96c90d5b1a24b343f0 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:55:06 -0800 Subject: [PATCH 09/24] BatchActions.update --- .../UI/Overlay/Batch/batch-upload/BatchDetail.tsx | 15 +++++++-------- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 6 +++++- app/src/state/reducers/batch.ts | 10 ++++------ app/src/state/sagas/batch.ts | 7 +++---- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx index b854e017c..947ff30be 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx @@ -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_UPDATE_REQUEST } from 'state/actions'; +import { BATCH_EXECUTE_REQUEST } from 'state/actions'; import BatchActions from 'state/actions/batch/BatchActions'; const StyledSelect = { @@ -31,13 +31,12 @@ const BatchMetadata = ({ batch }) => { } function uploadRevisedData() { - dispatch({ - type: BATCH_UPDATE_REQUEST, - payload: { + dispatch( + BatchActions.update({ id: batch.id, - csvData: fileData - } - }); + csvData: fileData ?? '' + }) + ); } function doBatchExec() { @@ -51,7 +50,7 @@ const BatchMetadata = ({ batch }) => { }); } - const [fileData, setFileData] = useState(null); + const [fileData, setFileData] = useState(); const [uploadReady, setUploadReady] = useState(false); const [execFinalState, setExecFinalState] = useState(''); diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 553ab3e90..97cc6d371 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 88e7d51d5..4c5320c26 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -11,6 +11,10 @@ interface IBatchCreateWithCallback { export interface IBatchSuccess extends DeepBatch { batchId: string; } +export interface IBatchUpdate { + id: string; + csvData: string; +} class BatchActions { private static readonly PREFIX = 'Batch'; @@ -23,7 +27,7 @@ class BatchActions { static readonly createWithCallback = createAction(`${this.PREFIX}/createWithCallback`); static readonly createSuccess = createAction(`${this.PREFIX}/create`); - static readonly update = createAction(`${this.PREFIX}/update`); + static readonly update = createAction(`${this.PREFIX}/update`); static readonly updateSuccess = createAction(`${this.PREFIX}/updateSuccess`); static readonly updateError = createAction(`${this.PREFIX}/updateError`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 58a1268f1..93d2856d1 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -14,7 +14,6 @@ import { BATCH_TEMPLATE_LIST_REQUEST, BATCH_TEMPLATE_LIST_SUCCESS, BATCH_UPDATE_ERROR, - BATCH_UPDATE_REQUEST, BATCH_UPDATE_SUCCESS } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -95,6 +94,10 @@ function createBatchReducer() { draftState.error = false; draftState.item = action.payload; draftState.createdBatchId = action.payload.batchId; + } else if (BatchActions.update.match(action)) { + draftState.working = true; + draftState.error = false; + draftState.item = null; } else { switch (action.type) { case BATCH_EXECUTE_SUCCESS: @@ -123,11 +126,6 @@ function createBatchReducer() { draftState.error = true; draftState.item = null; break; - case BATCH_UPDATE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; case BATCH_DELETE_REQUEST: draftState.working = true; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 182e53617..350919df8 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -12,7 +12,6 @@ import { BATCH_TEMPLATE_DOWNLOAD_SUCCESS, BATCH_TEMPLATE_LIST_REQUEST, BATCH_TEMPLATE_LIST_SUCCESS, - BATCH_UPDATE_REQUEST, BATCH_UPDATE_SUCCESS } from 'state/actions'; @@ -64,9 +63,9 @@ function* createBatchWithCallback(action) { yield call(resolve, resultBody?.batchId); } -function* updateBatch(action) { +function* updateBatch(action: PayloadAction) { const configuration = yield select(selectConfiguration); - const { id } = action.payload; + const id = action.payload; const res = yield fetch(configuration.API_BASE + `/api/batch/${id}`, { method: 'PUT', @@ -179,7 +178,7 @@ function* batchSaga() { yield all([ takeEvery(BatchActions.list, listBatches), takeLatest(BatchActions.retrieve, getBatch), - takeEvery(BATCH_UPDATE_REQUEST, updateBatch), + takeEvery(BatchActions.update, updateBatch), takeEvery(BATCH_DELETE_REQUEST, deleteBatch), takeEvery(BATCH_DELETE_SUCCESS, listBatches), takeLatest(BATCH_TEMPLATE_LIST_REQUEST, listTemplates), From 709223785ed3ff38d6458b5c65a1b0e55bf9b0c3 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:13:40 -0800 Subject: [PATCH 10/24] BatchActions.updateSuccess --- .../UI/Overlay/Batch/batch-upload/BatchDetail.tsx | 2 +- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 2 +- app/src/state/reducers/batch.ts | 12 +++++------- app/src/state/sagas/batch.ts | 13 +++++-------- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx index 947ff30be..09089f5b9 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx @@ -57,7 +57,7 @@ const BatchMetadata = ({ batch }) => { const [execErrorRowsTreatment, setExecErrorRowsTreatment] = useState(''); useEffect(() => { - setUploadReady(fileData !== null); + setUploadReady(fileData != null); }, [fileData]); const acceptFileData = (d) => { diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 97cc6d371..2aa6d22d2 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 4c5320c26..36dd4c3f7 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -28,7 +28,7 @@ class BatchActions { static readonly createSuccess = createAction(`${this.PREFIX}/create`); static readonly update = createAction(`${this.PREFIX}/update`); - static readonly updateSuccess = createAction(`${this.PREFIX}/updateSuccess`); + static readonly updateSuccess = createAction(`${this.PREFIX}/updateSuccess`); static readonly updateError = createAction(`${this.PREFIX}/updateError`); static readonly delete = createAction(`${this.PREFIX}/delete`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 93d2856d1..9d9e2cf48 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -13,8 +13,7 @@ import { BATCH_TEMPLATE_LIST_ERROR, BATCH_TEMPLATE_LIST_REQUEST, BATCH_TEMPLATE_LIST_SUCCESS, - BATCH_UPDATE_ERROR, - BATCH_UPDATE_SUCCESS + BATCH_UPDATE_ERROR } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -98,6 +97,10 @@ function createBatchReducer() { draftState.working = true; draftState.error = false; draftState.item = null; + } else if (BatchActions.updateSuccess.match(action)) { + draftState.working = false; + draftState.error = false; + draftState.item = null; } else { switch (action.type) { case BATCH_EXECUTE_SUCCESS: @@ -116,11 +119,6 @@ function createBatchReducer() { draftState.error = false; draftState.item = null; break; - case BATCH_UPDATE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = null; - break; case BATCH_UPDATE_ERROR: draftState.working = false; draftState.error = true; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 350919df8..e45543ff4 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -11,11 +11,10 @@ import { BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, BATCH_TEMPLATE_LIST_REQUEST, - BATCH_TEMPLATE_LIST_SUCCESS, - BATCH_UPDATE_SUCCESS + BATCH_TEMPLATE_LIST_SUCCESS } from 'state/actions'; -import BatchActions from 'state/actions/batch/BatchActions'; +import BatchActions, { IBatchUpdate } from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; import { getCurrentJWT } from 'state/sagas/auth/auth'; @@ -63,10 +62,9 @@ function* createBatchWithCallback(action) { yield call(resolve, resultBody?.batchId); } -function* updateBatch(action: PayloadAction) { +function* updateBatch(action: PayloadAction) { const configuration = yield select(selectConfiguration); - const id = action.payload; - + const { id } = action.payload; const res = yield fetch(configuration.API_BASE + `/api/batch/${id}`, { method: 'PUT', headers: { @@ -75,8 +73,7 @@ function* updateBatch(action: PayloadAction) { }, body: JSON.stringify(action.payload) }); - - yield put({ type: BATCH_UPDATE_SUCCESS, payload: res?.json() }); + yield put(BatchActions.updateSuccess(res?.json())); yield put(BatchActions.retrieve(id)); } From 3e68151367f45dbecc06aa52bb3042222d58e009 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:15:38 -0800 Subject: [PATCH 11/24] Remove BATCH_UPDATE_ERROR --- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 1 - app/src/state/reducers/batch.ts | 8 +------- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 2aa6d22d2..d7e1e3f48 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 36dd4c3f7..f56e47627 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -29,7 +29,6 @@ class BatchActions { static readonly update = createAction(`${this.PREFIX}/update`); static readonly updateSuccess = createAction(`${this.PREFIX}/updateSuccess`); - static readonly updateError = createAction(`${this.PREFIX}/updateError`); static readonly delete = createAction(`${this.PREFIX}/delete`); static readonly deleteSuccess = createAction(`${this.PREFIX}/deleteSuccess`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 9d9e2cf48..02c92bbc2 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -12,8 +12,7 @@ import { BATCH_TEMPLATE_DOWNLOAD_SUCCESS, BATCH_TEMPLATE_LIST_ERROR, BATCH_TEMPLATE_LIST_REQUEST, - BATCH_TEMPLATE_LIST_SUCCESS, - BATCH_UPDATE_ERROR + BATCH_TEMPLATE_LIST_SUCCESS } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -119,11 +118,6 @@ function createBatchReducer() { draftState.error = false; draftState.item = null; break; - case BATCH_UPDATE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.item = null; - break; case BATCH_DELETE_REQUEST: draftState.working = true; draftState.error = false; From 066e1ad23fe575525490955d2c53693af32d582c Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:19:43 -0800 Subject: [PATCH 12/24] Batch.delete --- .../UI/Overlay/Batch/batch-upload/BatchUploadList.tsx | 3 +-- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 2 +- app/src/state/reducers/batch.ts | 10 ++++------ app/src/state/sagas/batch.ts | 9 ++++----- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx index 87c504fa9..2eb402b3d 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchUploadList.tsx @@ -6,7 +6,6 @@ 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 } from 'state/actions'; import Spinner from 'UI/Spinner/Spinner'; import { selectAuth } from 'state/reducers/auth'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -27,7 +26,7 @@ const BatchUploadList = () => { }, [serial, authState?.authenticated]); function deleteBatch(batchId) { - dispatch({ type: BATCH_DELETE_REQUEST, payload: { id: batchId } }); + dispatch(BatchActions.delete(batchId)); } function renderError() { diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index d7e1e3f48..ffe34bec3 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index f56e47627..1b7d6c0e2 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -30,7 +30,7 @@ class BatchActions { static readonly update = createAction(`${this.PREFIX}/update`); static readonly updateSuccess = createAction(`${this.PREFIX}/updateSuccess`); - static readonly delete = createAction(`${this.PREFIX}/delete`); + static readonly delete = createAction(`${this.PREFIX}/delete`); static readonly deleteSuccess = createAction(`${this.PREFIX}/deleteSuccess`); static readonly deleteError = createAction(`${this.PREFIX}/deleteError`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 02c92bbc2..9665925a5 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -2,7 +2,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { BATCH_DELETE_ERROR, - BATCH_DELETE_REQUEST, BATCH_DELETE_SUCCESS, BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, @@ -100,6 +99,10 @@ function createBatchReducer() { draftState.working = false; draftState.error = false; draftState.item = null; + } else if (BatchActions.delete.match(action)) { + draftState.working = true; + draftState.error = false; + draftState.item = null; } else { switch (action.type) { case BATCH_EXECUTE_SUCCESS: @@ -118,11 +121,6 @@ function createBatchReducer() { draftState.error = false; draftState.item = null; break; - case BATCH_DELETE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; case BATCH_DELETE_SUCCESS: draftState.working = false; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index e45543ff4..9a0b53638 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -2,7 +2,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { BATCH_DELETE_ERROR, - BATCH_DELETE_REQUEST, BATCH_DELETE_SUCCESS, BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, @@ -77,9 +76,9 @@ function* updateBatch(action: PayloadAction) { yield put(BatchActions.retrieve(id)); } -function* deleteBatch(action: any) { +function* deleteBatch(action: PayloadAction) { const configuration = yield select(selectConfiguration); - const { id } = action.payload; + const id = action.payload; const res = yield fetch(configuration.API_BASE + `/api/batch/${id}`, { method: 'DELETE', @@ -87,7 +86,7 @@ function* deleteBatch(action: any) { Authorization: yield getCurrentJWT(), 'Content-Type': 'application/json' }, - body: JSON.stringify(action.payload) + body: JSON.stringify({ id }) }); const data = yield res.json(); @@ -176,7 +175,7 @@ function* batchSaga() { takeEvery(BatchActions.list, listBatches), takeLatest(BatchActions.retrieve, getBatch), takeEvery(BatchActions.update, updateBatch), - takeEvery(BATCH_DELETE_REQUEST, deleteBatch), + takeEvery(BatchActions.delete, deleteBatch), takeEvery(BATCH_DELETE_SUCCESS, listBatches), takeLatest(BATCH_TEMPLATE_LIST_REQUEST, listTemplates), takeEvery(BATCH_TEMPLATE_DOWNLOAD_REQUEST, templateDetail), From 0c1cd9d57216afd933e074b1721ce2a006d8a1aa Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:27:18 -0800 Subject: [PATCH 13/24] Batch.deleteSuccess/Error --- app/src/state/actions.tsx | 2 -- app/src/state/reducers/batch.ts | 22 +++++++++------------- app/src/state/sagas/batch.ts | 8 +++----- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index ffe34bec3..fab15ea1f 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,5 +1,3 @@ -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'; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 9665925a5..55c417d2a 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -1,8 +1,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { - BATCH_DELETE_ERROR, - BATCH_DELETE_SUCCESS, BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, @@ -103,6 +101,15 @@ function createBatchReducer() { draftState.working = true; draftState.error = false; draftState.item = null; + } else if (BatchActions.deleteSuccess.match(action)) { + draftState.working = false; + draftState.error = false; + draftState.item = null; + } else if (BatchActions.deleteError.match(action)) { + draftState.working = false; + draftState.error = true; + draftState.errorMessage = 'Could not delete batch'; + draftState.item = null; } else { switch (action.type) { case BATCH_EXECUTE_SUCCESS: @@ -121,17 +128,6 @@ function createBatchReducer() { draftState.error = false; draftState.item = null; break; - case BATCH_DELETE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = null; - break; - case BATCH_DELETE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.errorMessage = 'Could not delete batch'; - draftState.item = null; - break; case BATCH_TEMPLATE_LIST_REQUEST: draftState.working = true; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 9a0b53638..3720a3667 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,8 +1,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { - BATCH_DELETE_ERROR, - BATCH_DELETE_SUCCESS, BATCH_EXECUTE_ERROR, BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, @@ -92,10 +90,10 @@ function* deleteBatch(action: PayloadAction) { const data = yield res.json(); if (!res.ok) { - yield put({ type: BATCH_DELETE_ERROR, payload: data }); + yield put(BatchActions.deleteError()); return; } - yield put({ type: BATCH_DELETE_SUCCESS, payload: data }); + yield put(BatchActions.deleteSuccess()); } function* listTemplates(action) { @@ -176,7 +174,7 @@ function* batchSaga() { takeLatest(BatchActions.retrieve, getBatch), takeEvery(BatchActions.update, updateBatch), takeEvery(BatchActions.delete, deleteBatch), - takeEvery(BATCH_DELETE_SUCCESS, listBatches), + takeEvery(BatchActions.deleteSuccess, listBatches), takeLatest(BATCH_TEMPLATE_LIST_REQUEST, listTemplates), takeEvery(BATCH_TEMPLATE_DOWNLOAD_REQUEST, templateDetail), takeLatest(BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, templateCSV), From c6ff321ba1d0639e3a8efc3e28086f8abd619fca Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:48:39 -0800 Subject: [PATCH 14/24] BatchActions.execute --- .../UI/Overlay/Batch/batch-upload/BatchDetail.tsx | 10 ++++------ app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 7 ++++++- app/src/state/reducers/batch.ts | 11 +++++------ app/src/state/sagas/batch.ts | 13 ++++++------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx index 09089f5b9..6c3a752d1 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchDetail.tsx @@ -7,7 +7,6 @@ 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 } from 'state/actions'; import BatchActions from 'state/actions/batch/BatchActions'; const StyledSelect = { @@ -40,14 +39,13 @@ const BatchMetadata = ({ batch }) => { } function doBatchExec() { - dispatch({ - type: BATCH_EXECUTE_REQUEST, - payload: { + dispatch( + BatchActions.execute({ id: batch.id, desiredActivityState: execFinalState, treatmentOfErrorRows: execErrorRowsTreatment - } - }); + }) + ); } const [fileData, setFileData] = useState(); diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index fab15ea1f..029af2a32 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 1b7d6c0e2..50e143701 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -15,6 +15,11 @@ export interface IBatchUpdate { id: string; csvData: string; } +export interface IBatchExecute { + id: string; + desiredActivityState: string; + treatmentOfErrorRows: string; +} class BatchActions { private static readonly PREFIX = 'Batch'; @@ -34,7 +39,7 @@ class BatchActions { static readonly deleteSuccess = createAction(`${this.PREFIX}/deleteSuccess`); static readonly deleteError = createAction(`${this.PREFIX}/deleteError`); - static readonly execute = createAction(`${this.PREFIX}/execute`); + static readonly execute = createAction(`${this.PREFIX}/execute`); static readonly executeSuccess = createAction(`${this.PREFIX}/executeSuccess`); static readonly executeError = createAction(`${this.PREFIX}/executeError`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 55c417d2a..53b8edd8d 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -2,7 +2,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { BATCH_EXECUTE_ERROR, - BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, @@ -110,6 +109,10 @@ function createBatchReducer() { draftState.error = true; draftState.errorMessage = 'Could not delete batch'; draftState.item = null; + } else if (BatchActions.execute.match(action)) { + draftState.working = true; + draftState.error = false; + draftState.item = null; } else { switch (action.type) { case BATCH_EXECUTE_SUCCESS: @@ -123,11 +126,7 @@ function createBatchReducer() { draftState.errorMessage = `Could not execute batch ${JSON.stringify(action.payload?.message, null, 2)}`; draftState.item = null; break; - case BATCH_EXECUTE_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.item = null; - break; + case BATCH_TEMPLATE_LIST_REQUEST: draftState.working = true; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 3720a3667..b59388de9 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -2,7 +2,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { BATCH_EXECUTE_ERROR, - BATCH_EXECUTE_REQUEST, BATCH_EXECUTE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST, @@ -11,7 +10,7 @@ import { BATCH_TEMPLATE_LIST_SUCCESS } from 'state/actions'; -import BatchActions, { IBatchUpdate } from 'state/actions/batch/BatchActions'; +import BatchActions, { IBatchExecute, IBatchUpdate } from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; import { getCurrentJWT } from 'state/sagas/auth/auth'; @@ -142,9 +141,9 @@ function* templateDetail(action) { }); } -function* executeBatch(action) { +function* executeBatch(action: PayloadAction) { const configuration = yield select(selectConfiguration); - const { id } = action.payload; + const { id, desiredActivityState, treatmentOfErrorRows } = action.payload; const res = yield fetch(configuration.API_BASE + `/api/batch/${id}/execute`, { method: 'POST', @@ -153,8 +152,8 @@ function* executeBatch(action) { 'Content-Type': 'application/json' }, body: JSON.stringify({ - desiredActivityState: action.payload.desiredActivityState, - treatmentOfErrorRows: action.payload.treatmentOfErrorRows + desiredActivityState: desiredActivityState, + treatmentOfErrorRows: treatmentOfErrorRows }) }); @@ -179,7 +178,7 @@ function* batchSaga() { takeEvery(BATCH_TEMPLATE_DOWNLOAD_REQUEST, templateDetail), takeLatest(BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, templateCSV), takeLatest(BatchActions.createWithCallback, createBatchWithCallback), - takeLatest(BATCH_EXECUTE_REQUEST, executeBatch) + takeLatest(BatchActions.execute, executeBatch) ]); } From 809885e27d2d53554d1b2e9a4359094daa043e3a Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:08:39 -0800 Subject: [PATCH 15/24] BatchActions.executeSuccess --- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 2 +- app/src/state/reducers/batch.ts | 10 ++++------ app/src/state/sagas/batch.ts | 3 +-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 029af2a32..49903b9aa 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 50e143701..f3543c246 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -40,7 +40,7 @@ class BatchActions { static readonly deleteError = createAction(`${this.PREFIX}/deleteError`); static readonly execute = createAction(`${this.PREFIX}/execute`); - static readonly executeSuccess = createAction(`${this.PREFIX}/executeSuccess`); + static readonly executeSuccess = createAction(`${this.PREFIX}/executeSuccess`); static readonly executeError = createAction(`${this.PREFIX}/executeError`); static readonly templateList = createAction(`${this.PREFIX}/templateList`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 53b8edd8d..4c75e7c58 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -2,7 +2,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { BATCH_EXECUTE_ERROR, - BATCH_EXECUTE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, @@ -113,13 +112,12 @@ function createBatchReducer() { draftState.working = true; draftState.error = false; draftState.item = null; + } else if (BatchActions.executeSuccess.match(action)) { + draftState.working = false; + draftState.error = false; + draftState.item = action.payload; } else { switch (action.type) { - case BATCH_EXECUTE_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.item = action.payload.result; - break; case BATCH_EXECUTE_ERROR: draftState.working = false; draftState.error = true; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index b59388de9..69974eb39 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -2,7 +2,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { BATCH_EXECUTE_ERROR, - BATCH_EXECUTE_SUCCESS, BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, @@ -160,7 +159,7 @@ function* executeBatch(action: PayloadAction) { const data = yield res.json(); if (data.code === 200) { - yield put({ type: BATCH_EXECUTE_SUCCESS, payload: data }); + yield put(BatchActions.executeSuccess(data.result)); yield put(BatchActions.retrieve(id)); } else { yield put({ type: BATCH_EXECUTE_ERROR, payload: data }); From 7b4a042c7c5f1f420ab89c9e920876eea699f477 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:38:36 -0800 Subject: [PATCH 16/24] BatchActions.executeError --- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 2 +- app/src/state/reducers/batch.ts | 13 +++++-------- app/src/state/sagas/batch.ts | 3 +-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 49903b9aa..d783155f0 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index f3543c246..24d2b812a 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -41,7 +41,7 @@ class BatchActions { static readonly execute = createAction(`${this.PREFIX}/execute`); static readonly executeSuccess = createAction(`${this.PREFIX}/executeSuccess`); - static readonly executeError = createAction(`${this.PREFIX}/executeError`); + static readonly executeError = createAction(`${this.PREFIX}/executeError`); static readonly templateList = createAction(`${this.PREFIX}/templateList`); static readonly templateListSuccess = createAction(`${this.PREFIX}/templateListSuccess`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 4c75e7c58..b3e3666b8 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -1,7 +1,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; import { - BATCH_EXECUTE_ERROR, BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, @@ -116,15 +115,13 @@ function createBatchReducer() { draftState.working = false; draftState.error = false; draftState.item = action.payload; + } else if (BatchActions.executeError.match(action)) { + draftState.working = false; + draftState.error = true; + draftState.errorMessage = `Could not execute batch: ${action.payload}`; + draftState.item = null; } else { switch (action.type) { - case BATCH_EXECUTE_ERROR: - draftState.working = false; - draftState.error = true; - draftState.errorMessage = `Could not execute batch ${JSON.stringify(action.payload?.message, null, 2)}`; - draftState.item = null; - break; - case BATCH_TEMPLATE_LIST_REQUEST: draftState.working = true; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 69974eb39..b94f6dcf1 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,7 +1,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; import { - BATCH_EXECUTE_ERROR, BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, @@ -162,7 +161,7 @@ function* executeBatch(action: PayloadAction) { yield put(BatchActions.executeSuccess(data.result)); yield put(BatchActions.retrieve(id)); } else { - yield put({ type: BATCH_EXECUTE_ERROR, payload: data }); + yield put(BatchActions.executeError(data.message ?? '')); } } From 997d95c1513b0c8da15332bbe788d0f9dd9f1c8f Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:48:29 -0800 Subject: [PATCH 17/24] BatchActions.templateList --- app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx | 4 +--- .../Batch/batch-upload/TemplateDownloadList.tsx | 5 ++--- app/src/state/actions.tsx | 1 - app/src/state/reducers/batch.ts | 10 ++++------ app/src/state/sagas/batch.ts | 5 ++--- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx b/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx index 891dec497..510107c4e 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/BatchCreate.tsx @@ -5,7 +5,6 @@ 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_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'; @@ -29,8 +28,7 @@ const BatchCreate = () => { if (!authState?.authenticated) { return; } - - dispatch({ type: BATCH_TEMPLATE_LIST_REQUEST }); + dispatch(BatchActions.templateList()); }, [authState?.authenticated]); const acceptData = (d) => { diff --git a/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx b/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx index 4ee6c12f5..634df5f92 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx @@ -4,9 +4,9 @@ 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(); @@ -17,8 +17,7 @@ const TemplateDownloadList = () => { if (!authState?.authenticated) { return; } - - dispatch({ type: BATCH_TEMPLATE_LIST_REQUEST }); + dispatch(BatchActions.templateList()); }, [authState?.authenticated]); if (working) { diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index d783155f0..fa4ba8709 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index b3e3666b8..db2d75ddf 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -5,7 +5,6 @@ import { BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, BATCH_TEMPLATE_LIST_ERROR, - BATCH_TEMPLATE_LIST_REQUEST, BATCH_TEMPLATE_LIST_SUCCESS } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -120,13 +119,12 @@ function createBatchReducer() { draftState.error = true; draftState.errorMessage = `Could not execute batch: ${action.payload}`; draftState.item = null; + } else if (BatchActions.templateList.match(action)) { + draftState.working = true; + draftState.error = false; + draftState.templates = []; } else { switch (action.type) { - case BATCH_TEMPLATE_LIST_REQUEST: - draftState.working = true; - draftState.error = false; - draftState.templates = []; - break; case BATCH_TEMPLATE_LIST_SUCCESS: draftState.working = false; draftState.error = false; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index b94f6dcf1..25ad2312a 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -4,7 +4,6 @@ import { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, - BATCH_TEMPLATE_LIST_REQUEST, BATCH_TEMPLATE_LIST_SUCCESS } from 'state/actions'; @@ -93,7 +92,7 @@ function* deleteBatch(action: PayloadAction) { yield put(BatchActions.deleteSuccess()); } -function* listTemplates(action) { +function* listTemplates(action: PayloadAction) { const configuration = yield select(selectConfiguration); const res = yield fetch(configuration.API_BASE + `/api/batch/templates`, { @@ -172,7 +171,7 @@ function* batchSaga() { takeEvery(BatchActions.update, updateBatch), takeEvery(BatchActions.delete, deleteBatch), takeEvery(BatchActions.deleteSuccess, listBatches), - takeLatest(BATCH_TEMPLATE_LIST_REQUEST, listTemplates), + takeLatest(BatchActions.templateList, listTemplates), takeEvery(BATCH_TEMPLATE_DOWNLOAD_REQUEST, templateDetail), takeLatest(BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, templateCSV), takeLatest(BatchActions.createWithCallback, createBatchWithCallback), From cdd6820e497c0e1fdbca178286b999fe875e1edd Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:01:03 -0800 Subject: [PATCH 18/24] BatchActions.templateListSuccess --- .../batch-upload/TemplateDownloadList.tsx | 2 +- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 7 +++- app/src/state/reducers/batch.ts | 38 +++---------------- app/src/state/sagas/batch.ts | 6 +-- 5 files changed, 14 insertions(+), 40 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx b/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx index 634df5f92..60751be3e 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/TemplateDownloadList.tsx @@ -1,5 +1,5 @@ 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'; diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index fa4ba8709..02ad4b4df 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 24d2b812a..69e9a71bd 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -20,6 +20,11 @@ export interface IBatchExecute { desiredActivityState: string; treatmentOfErrorRows: string; } + +export interface IBatchListTemplate { + name: string; + key: string; +} class BatchActions { private static readonly PREFIX = 'Batch'; @@ -44,7 +49,7 @@ class BatchActions { static readonly executeError = createAction(`${this.PREFIX}/executeError`); static readonly templateList = createAction(`${this.PREFIX}/templateList`); - static readonly templateListSuccess = createAction(`${this.PREFIX}/templateListSuccess`); + static readonly templateListSuccess = createAction(`${this.PREFIX}/templateListSuccess`); static readonly templateListError = createAction(`${this.PREFIX}/templateListError`); static readonly downloadTemplate = createAction(`${this.PREFIX}/downloadTemplate`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index db2d75ddf..6d8974cd2 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -4,8 +4,7 @@ import { BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS, - BATCH_TEMPLATE_LIST_ERROR, - BATCH_TEMPLATE_LIST_SUCCESS + BATCH_TEMPLATE_LIST_ERROR } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -123,39 +122,12 @@ function createBatchReducer() { draftState.working = true; draftState.error = false; draftState.templates = []; + } else if (BatchActions.templateListSuccess.match(action)) { + draftState.working = false; + draftState.error = false; + draftState.templates = action.payload; } else { switch (action.type) { - case BATCH_TEMPLATE_LIST_SUCCESS: - draftState.working = false; - draftState.error = false; - draftState.templates = action.payload.filter((template) => - [ - 'observation_aquatic_plant', - 'observation_aquatic_plant_temp', - 'observation_terrestrial_plant', - 'observation_terrestrial_plant_temp', - 'treatment_mechanical_terrestrial_plant', - 'treatment_mechanical_terrestrial_plant_temp', - 'treatment_mechanical_aquatic_plant', - 'treatment_mechanical_aquatic_plant_temp', - 'treatment_chemical_terrestrial_plant', - 'treatment_chemical_terrestrial_plant_temp', - 'treatment_chemical_aquatic_plant', - 'treatment_chemical_aquatic_plant_temp', - 'biocontrol_release', - 'biocontrol_release_temp', - 'biocontrol_collection', - 'biocontrol_collection_temp', - 'monitoring_biocontrol_dispersal_terrestrial_plant', - 'monitoring_biocontrol_dispersal_terrestrial_plant_temp', - 'monitoring_biocontrol_release_terrestrial_plant', - 'monitoring_chemical_treatment', - 'monitoring_chemical_treatment_temp', - 'monitoring_mechanical_treatment', - 'monitoring_mechanical_treatment_temp' - ].includes(template.key) - ); - break; case BATCH_TEMPLATE_LIST_ERROR: draftState.working = false; draftState.error = true; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 25ad2312a..8f5d62793 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -3,8 +3,7 @@ import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effect import { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_REQUEST, - BATCH_TEMPLATE_DOWNLOAD_SUCCESS, - BATCH_TEMPLATE_LIST_SUCCESS + BATCH_TEMPLATE_DOWNLOAD_SUCCESS } from 'state/actions'; import BatchActions, { IBatchExecute, IBatchUpdate } from 'state/actions/batch/BatchActions'; @@ -100,8 +99,7 @@ function* listTemplates(action: PayloadAction) { Authorization: yield getCurrentJWT() } }); - - yield put({ type: BATCH_TEMPLATE_LIST_SUCCESS, payload: yield res.json() }); + yield put(BatchActions.templateListSuccess(yield res.json())); } function* templateCSV(action) { From bcecd38a2528f50f4da0c10cafce6b2fa760ce58 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:02:18 -0800 Subject: [PATCH 19/24] remove BATCH_TEMPLATE_LIST_ERROR --- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 1 - app/src/state/reducers/batch.ts | 8 +------- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 02ad4b4df..73ae534be 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 69e9a71bd..bbc755ca2 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -50,7 +50,6 @@ class BatchActions { static readonly templateList = createAction(`${this.PREFIX}/templateList`); static readonly templateListSuccess = createAction(`${this.PREFIX}/templateListSuccess`); - static readonly templateListError = createAction(`${this.PREFIX}/templateListError`); static readonly downloadTemplate = createAction(`${this.PREFIX}/downloadTemplate`); static readonly downloadTemplateSuccess = createAction(`${this.PREFIX}/downloadTemplateSuccess`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 6d8974cd2..76e414a6f 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -3,8 +3,7 @@ import { Draft } from 'immer'; import { BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_REQUEST, - BATCH_TEMPLATE_DOWNLOAD_SUCCESS, - BATCH_TEMPLATE_LIST_ERROR + BATCH_TEMPLATE_DOWNLOAD_SUCCESS } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -128,11 +127,6 @@ function createBatchReducer() { draftState.templates = action.payload; } else { switch (action.type) { - case BATCH_TEMPLATE_LIST_ERROR: - draftState.working = false; - draftState.error = true; - draftState.templates = []; - break; case BATCH_TEMPLATE_DOWNLOAD_REQUEST: draftState.templateDetail = { ...state.templateDetail, From e86b7f527df2e1b2b5e3f05ab259405072dc24ee Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:51:34 -0800 Subject: [PATCH 20/24] BatchActions.downloadTemplate --- .../Batch/batch-upload/TemplatePreview.tsx | 12 +++------ app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 3 ++- app/src/state/reducers/batch.ts | 27 ++++++++----------- app/src/state/sagas/batch.ts | 16 +++++------ 5 files changed, 23 insertions(+), 36 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx b/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx index 8c4983613..7aa7bde3f 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx @@ -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'; @@ -8,8 +8,9 @@ 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 { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST } from 'state/actions'; import Spinner from 'UI/Spinner/Spinner'; +import BatchActions from 'state/actions/batch/BatchActions'; const TemplatePreview = ({ name, id }) => { const dispatch = useDispatch(); @@ -23,12 +24,7 @@ const TemplatePreview = ({ name, id }) => { useEffect(() => { if (expanded && !detail) { - dispatch({ - type: BATCH_TEMPLATE_DOWNLOAD_REQUEST, - payload: { - key: id - } - }); + dispatch(BatchActions.downloadTemplate(id)); } }, [id, expanded]); diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 73ae534be..67a5a26a0 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index bbc755ca2..9ea0650ef 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -25,6 +25,7 @@ export interface IBatchListTemplate { name: string; key: string; } + class BatchActions { private static readonly PREFIX = 'Batch'; @@ -51,7 +52,7 @@ class BatchActions { static readonly templateList = createAction(`${this.PREFIX}/templateList`); static readonly templateListSuccess = createAction(`${this.PREFIX}/templateListSuccess`); - static readonly downloadTemplate = createAction(`${this.PREFIX}/downloadTemplate`); + static readonly downloadTemplate = createAction(`${this.PREFIX}/downloadTemplate`); static readonly downloadTemplateSuccess = createAction(`${this.PREFIX}/downloadTemplateSuccess`); static readonly downloadTemplateError = createAction(`${this.PREFIX}/downloadTemplateError`); static readonly downloadTemplateCsv = createAction(`${this.PREFIX}/downloadTemplateCsv`); diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 76e414a6f..808b6996b 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -1,10 +1,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; -import { - BATCH_TEMPLATE_DOWNLOAD_ERROR, - BATCH_TEMPLATE_DOWNLOAD_REQUEST, - BATCH_TEMPLATE_DOWNLOAD_SUCCESS -} from '../actions'; +import { BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_SUCCESS } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; export interface DeepBatch { @@ -40,7 +36,7 @@ interface Batch { templates: ShallowTemplate[]; templateDetail: { [name: string]: { - data: DeepTemplate; + data: DeepTemplate | null; error: boolean; working: boolean; }; @@ -125,18 +121,17 @@ function createBatchReducer() { draftState.working = false; draftState.error = false; draftState.templates = action.payload; + } else if (BatchActions.downloadTemplate.match(action)) { + draftState.templateDetail = { + ...state.templateDetail, + [action.payload]: { + working: true, + error: false, + data: null + } + }; } else { switch (action.type) { - case BATCH_TEMPLATE_DOWNLOAD_REQUEST: - draftState.templateDetail = { - ...state.templateDetail, - [action.payload.key]: { - working: true, - error: false, - data: null - } - }; - break; case BATCH_TEMPLATE_DOWNLOAD_SUCCESS: draftState.templateDetail = { ...state.templateDetail, diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 8f5d62793..06ae7e550 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,10 +1,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; -import { - BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, - BATCH_TEMPLATE_DOWNLOAD_REQUEST, - BATCH_TEMPLATE_DOWNLOAD_SUCCESS -} from 'state/actions'; +import { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS } from 'state/actions'; import BatchActions, { IBatchExecute, IBatchUpdate } from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; @@ -117,10 +113,10 @@ function* templateCSV(action) { yield call(resolve, yield res.text()); } -function* templateDetail(action) { +function* templateDetail(action: PayloadAction) { const configuration = yield select(selectConfiguration); - - const res = yield fetch(configuration.API_BASE + `/api/batch/templates/${action.payload.key}`, { + const key = action.payload; + const res = yield fetch(configuration.API_BASE + `/api/batch/templates/${key}`, { headers: { Authorization: yield getCurrentJWT(), Accept: 'application/json' @@ -130,7 +126,7 @@ function* templateDetail(action) { yield put({ type: BATCH_TEMPLATE_DOWNLOAD_SUCCESS, payload: { - key: action.payload.key, + key: key, data: yield res.json() } }); @@ -170,7 +166,7 @@ function* batchSaga() { takeEvery(BatchActions.delete, deleteBatch), takeEvery(BatchActions.deleteSuccess, listBatches), takeLatest(BatchActions.templateList, listTemplates), - takeEvery(BATCH_TEMPLATE_DOWNLOAD_REQUEST, templateDetail), + takeEvery(BatchActions.downloadTemplate, templateDetail), takeLatest(BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, templateCSV), takeLatest(BatchActions.createWithCallback, createBatchWithCallback), takeLatest(BatchActions.execute, executeBatch) From 7d46168c8146ae704999053076a0e74f71c02f3f Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:03:49 -0800 Subject: [PATCH 21/24] BatchActions.downloadTemplateSuccess --- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 10 ++++++++-- app/src/state/reducers/batch.ts | 21 ++++++++++----------- app/src/state/sagas/batch.ts | 11 +++++------ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 67a5a26a0..4964accb2 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -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'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 9ea0650ef..1f46ca7f8 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -1,5 +1,5 @@ import { createAction } from '@reduxjs/toolkit'; -import { DeepBatch, ShallowBatch } from 'state/reducers/batch'; +import { DeepBatch, DeepTemplate, ShallowBatch } from 'state/reducers/batch'; interface IBatchCreateWithCallback { csvData: Record | null; @@ -26,6 +26,10 @@ export interface IBatchListTemplate { key: string; } +export interface IBatchDownloadTemplate { + key: string; + data: DeepTemplate; +} class BatchActions { private static readonly PREFIX = 'Batch'; @@ -53,7 +57,9 @@ class BatchActions { static readonly templateListSuccess = createAction(`${this.PREFIX}/templateListSuccess`); static readonly downloadTemplate = createAction(`${this.PREFIX}/downloadTemplate`); - static readonly downloadTemplateSuccess = createAction(`${this.PREFIX}/downloadTemplateSuccess`); + static readonly downloadTemplateSuccess = createAction( + `${this.PREFIX}/downloadTemplateSuccess` + ); static readonly downloadTemplateError = createAction(`${this.PREFIX}/downloadTemplateError`); static readonly downloadTemplateCsv = createAction(`${this.PREFIX}/downloadTemplateCsv`); } diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 808b6996b..793ac7738 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -1,6 +1,6 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; -import { BATCH_TEMPLATE_DOWNLOAD_ERROR, BATCH_TEMPLATE_DOWNLOAD_SUCCESS } from '../actions'; +import { BATCH_TEMPLATE_DOWNLOAD_ERROR } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; export interface DeepBatch { @@ -130,18 +130,17 @@ function createBatchReducer() { data: null } }; + } else if (BatchActions.downloadTemplateSuccess.match(action)) { + draftState.templateDetail = { + ...state.templateDetail, + [action.payload.key]: { + working: false, + error: false, + data: action.payload.data + } + }; } else { switch (action.type) { - case BATCH_TEMPLATE_DOWNLOAD_SUCCESS: - draftState.templateDetail = { - ...state.templateDetail, - [action.payload.key]: { - working: false, - error: false, - data: action.payload.data - } - }; - break; case BATCH_TEMPLATE_DOWNLOAD_ERROR: draftState.templateDetail = { ...state.templateDetail, diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 06ae7e550..583931000 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,6 +1,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; -import { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, BATCH_TEMPLATE_DOWNLOAD_SUCCESS } from 'state/actions'; +import { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST } from 'state/actions'; import BatchActions, { IBatchExecute, IBatchUpdate } from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; @@ -123,13 +123,12 @@ function* templateDetail(action: PayloadAction) { } }); - yield put({ - type: BATCH_TEMPLATE_DOWNLOAD_SUCCESS, - payload: { + yield put( + BatchActions.downloadTemplateSuccess({ key: key, data: yield res.json() - } - }); + }) + ); } function* executeBatch(action: PayloadAction) { From 22b236d8e9a8376645eafe9c8e28872cc251ee6f Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:05:15 -0800 Subject: [PATCH 22/24] remove BATCH_TEMPLATE_DOWNLOAD_ERROR --- app/src/state/actions.tsx | 1 - app/src/state/actions/batch/BatchActions.ts | 1 - app/src/state/reducers/batch.ts | 11 ----------- 3 files changed, 13 deletions(-) diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index 4964accb2..c59d69ff8 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,4 +1,3 @@ -export const BATCH_TEMPLATE_DOWNLOAD_ERROR = 'BATCH_TEMPLATE_DOWNLOAD_ERROR'; export const BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST = 'BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST'; export const SET_APP_MODE = 'SET_APP_MODE'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index 1f46ca7f8..d912c3975 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -60,7 +60,6 @@ class BatchActions { static readonly downloadTemplateSuccess = createAction( `${this.PREFIX}/downloadTemplateSuccess` ); - static readonly downloadTemplateError = createAction(`${this.PREFIX}/downloadTemplateError`); static readonly downloadTemplateCsv = createAction(`${this.PREFIX}/downloadTemplateCsv`); } diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index 793ac7738..b462aeed5 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -1,6 +1,5 @@ import { createNextState } from '@reduxjs/toolkit'; import { Draft } from 'immer'; -import { BATCH_TEMPLATE_DOWNLOAD_ERROR } from '../actions'; import BatchActions from 'state/actions/batch/BatchActions'; export interface DeepBatch { @@ -141,16 +140,6 @@ function createBatchReducer() { }; } else { switch (action.type) { - case BATCH_TEMPLATE_DOWNLOAD_ERROR: - draftState.templateDetail = { - ...state.templateDetail, - [action.payload.key]: { - working: false, - error: true, - data: null - } - }; - break; default: break; } From 5eb4b061ffae1e6576a671a1f05b57abefe96c27 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:21:28 -0800 Subject: [PATCH 23/24] BatchActions.downloadTemplateCsv --- .../UI/Overlay/Batch/batch-upload/TemplatePreview.tsx | 10 ++++------ app/src/state/actions.tsx | 2 -- app/src/state/actions/batch/BatchActions.ts | 7 ++++++- app/src/state/sagas/batch.ts | 8 +++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx b/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx index 7aa7bde3f..b54a66451 100644 --- a/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx +++ b/app/src/UI/Overlay/Batch/batch-upload/TemplatePreview.tsx @@ -8,7 +8,6 @@ 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 } from 'state/actions'; import Spinner from 'UI/Spinner/Spinner'; import BatchActions from 'state/actions/batch/BatchActions'; @@ -40,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'); diff --git a/app/src/state/actions.tsx b/app/src/state/actions.tsx index c59d69ff8..37e9d8458 100644 --- a/app/src/state/actions.tsx +++ b/app/src/state/actions.tsx @@ -1,5 +1,3 @@ -export const BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST = 'BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST'; - export const SET_APP_MODE = 'SET_APP_MODE'; export const TOGGLE_PANEL = 'TOGGLE_PANEL'; export const OVERLAY_MENU_TOGGLE = 'OVERLAY_MENU_TOGGLE'; diff --git a/app/src/state/actions/batch/BatchActions.ts b/app/src/state/actions/batch/BatchActions.ts index d912c3975..7015f82e1 100644 --- a/app/src/state/actions/batch/BatchActions.ts +++ b/app/src/state/actions/batch/BatchActions.ts @@ -30,6 +30,11 @@ export interface IBatchDownloadTemplate { key: string; data: DeepTemplate; } + +export interface IBatchDownloadTemplateCsv { + key: string; + resolve: any; +} class BatchActions { private static readonly PREFIX = 'Batch'; @@ -60,7 +65,7 @@ class BatchActions { static readonly downloadTemplateSuccess = createAction( `${this.PREFIX}/downloadTemplateSuccess` ); - static readonly downloadTemplateCsv = createAction(`${this.PREFIX}/downloadTemplateCsv`); + static readonly downloadTemplateCsv = createAction(`${this.PREFIX}/downloadTemplateCsv`); } export default BatchActions; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 583931000..11a8039ab 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -1,8 +1,6 @@ import { PayloadAction } from '@reduxjs/toolkit'; import { all, call, put, select, takeEvery, takeLatest } from 'redux-saga/effects'; -import { BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST } from 'state/actions'; - -import BatchActions, { IBatchExecute, IBatchUpdate } from 'state/actions/batch/BatchActions'; +import BatchActions, { IBatchDownloadTemplateCsv, IBatchExecute, IBatchUpdate } from 'state/actions/batch/BatchActions'; import { selectConfiguration } from 'state/reducers/configuration'; import { getCurrentJWT } from 'state/sagas/auth/auth'; @@ -98,7 +96,7 @@ function* listTemplates(action: PayloadAction) { yield put(BatchActions.templateListSuccess(yield res.json())); } -function* templateCSV(action) { +function* templateCSV(action: PayloadAction) { const configuration = yield select(selectConfiguration); const { key, resolve } = action.payload; @@ -166,7 +164,7 @@ function* batchSaga() { takeEvery(BatchActions.deleteSuccess, listBatches), takeLatest(BatchActions.templateList, listTemplates), takeEvery(BatchActions.downloadTemplate, templateDetail), - takeLatest(BATCH_TEMPLATE_DOWNLOAD_CSV_REQUEST, templateCSV), + takeLatest(BatchActions.downloadTemplateCsv, templateCSV), takeLatest(BatchActions.createWithCallback, createBatchWithCallback), takeLatest(BatchActions.execute, executeBatch) ]); From ca1296c61e20ea990953d9d195905b87fca0b582 Mon Sep 17 00:00:00 2001 From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:30:08 -0800 Subject: [PATCH 24/24] Remove switch statement, unused variable --- app/src/state/reducers/batch.ts | 5 ----- app/src/state/sagas/batch.ts | 2 -- 2 files changed, 7 deletions(-) diff --git a/app/src/state/reducers/batch.ts b/app/src/state/reducers/batch.ts index b462aeed5..30be991c4 100644 --- a/app/src/state/reducers/batch.ts +++ b/app/src/state/reducers/batch.ts @@ -138,11 +138,6 @@ function createBatchReducer() { data: action.payload.data } }; - } else { - switch (action.type) { - default: - break; - } } }); }; diff --git a/app/src/state/sagas/batch.ts b/app/src/state/sagas/batch.ts index 11a8039ab..fa4d55507 100644 --- a/app/src/state/sagas/batch.ts +++ b/app/src/state/sagas/batch.ts @@ -76,8 +76,6 @@ function* deleteBatch(action: PayloadAction) { body: JSON.stringify({ id }) }); - const data = yield res.json(); - if (!res.ok) { yield put(BatchActions.deleteError()); return;