From d40be6a694f1b084e9038863137bfc7f25424745 Mon Sep 17 00:00:00 2001 From: Caitlin Barnard <54268863+CaitBarnard@users.noreply.github.com> Date: Tue, 11 Feb 2025 11:03:39 +0000 Subject: [PATCH] FFT-173 Remove toggle from Edit Forecast and related code (#616) --- forecast/templates/forecast/edit/edit.html | 4 -- forecast/views/edit_forecast.py | 13 +----- .../src/Components/EditForecast/index.jsx | 30 ++---------- front_end/src/Components/Table/index.jsx | 3 +- front_end/src/Components/TableCell/index.jsx | 34 ++++---------- front_end/src/Util.js | 46 +------------------ front_end/styles/styles.scss | 1 - 7 files changed, 14 insertions(+), 117 deletions(-) diff --git a/forecast/templates/forecast/edit/edit.html b/forecast/templates/forecast/edit/edit.html index 07497769..c990341d 100644 --- a/forecast/templates/forecast/edit/edit.html +++ b/forecast/templates/forecast/edit/edit.html @@ -41,16 +41,12 @@ {% endblock %} {% block scripts %} - {{ view.get_payroll_forecast_report|json_script:'payroll_forecast_data' }} - {% can_access_edit_payroll user as user_can_access_edit_payroll %} {% vite_dev_client %} {% vite_js 'src/index.jsx' %} diff --git a/forecast/views/edit_forecast.py b/forecast/views/edit_forecast.py index cfb3d68d..983aa20c 100644 --- a/forecast/views/edit_forecast.py +++ b/forecast/views/edit_forecast.py @@ -7,7 +7,7 @@ from django.db import transaction from django.db.models import Exists, OuterRef, Prefetch, Q, Sum from django.http import JsonResponse -from django.shortcuts import get_object_or_404, redirect +from django.shortcuts import redirect from django.urls import reverse from django.views.generic.base import TemplateView from django.views.generic.edit import FormView @@ -53,7 +53,6 @@ NoCostCentreCodeInURLError, NoFinancialYearInURLError, ) -from payroll.services import payroll as payroll_service UNAVAILABLE_FORECAST_EDIT_TITLE = "Forecast editing is locked" @@ -531,16 +530,6 @@ def get_context_data(self, **kwargs): return context - def get_payroll_forecast_report(self): - cost_centre_obj = get_object_or_404(CostCentre, pk=self.cost_centre_code) - financial_year_obj = get_object_or_404(FinancialYear, pk=self.financial_year) - queryset = payroll_service.payroll_forecast_report( - cost_centre_obj, financial_year_obj - ) - data = list(queryset) - - return data - @cached_property def future_year_display(self): if self._future_year_display is None: diff --git a/front_end/src/Components/EditForecast/index.jsx b/front_end/src/Components/EditForecast/index.jsx index 0b3bb4e9..412f05c2 100644 --- a/front_end/src/Components/EditForecast/index.jsx +++ b/front_end/src/Components/EditForecast/index.jsx @@ -14,7 +14,6 @@ import { UNSELECT_ALL, } from "../../Reducers/Selected"; import { getCellId, postData, processForecastData } from "../../Util"; -import ToggleCheckbox from "../Common/ToggleCheckbox"; function EditForecast() { const dispatch = useDispatch(); @@ -27,23 +26,12 @@ function EditForecast() { const editCellId = useSelector((state) => state.edit.cellId); const [sheetUpdating, setSheetUpdating] = useState(false); - const [isPayrollEnabled, setIsPayrollEnabled] = useState(false); - - const handleIsPayrollEnabled = () => { - setIsPayrollEnabled(!isPayrollEnabled); - - localStorage.setItem("isPayrollEnabled", JSON.stringify(!isPayrollEnabled)); - }; useEffect(() => { const timer = () => { setTimeout(() => { if (window.table_data) { - let rows = processForecastData( - window.table_data, - window.payroll_forecast_data, - isPayrollEnabled, - ); + let rows = processForecastData(window.table_data); dispatch(SET_CELLS({ cells: rows })); } else { timer(); @@ -52,7 +40,7 @@ function EditForecast() { }; timer(); - }, [dispatch, isPayrollEnabled]); + }, [dispatch]); useEffect(() => { const capturePaste = (event) => { @@ -328,15 +316,6 @@ function EditForecast() { return ( - {window.can_access_edit_payroll === "True" && ( - - )} {errorMessage != null && (
)} - +
); } diff --git a/front_end/src/Components/Table/index.jsx b/front_end/src/Components/Table/index.jsx index c0fe245b..639b7d7f 100644 --- a/front_end/src/Components/Table/index.jsx +++ b/front_end/src/Components/Table/index.jsx @@ -24,7 +24,7 @@ import { UNSELECT_ALL, } from "../../Reducers/Selected"; -function Table({ rowData, sheetUpdating, payrollData }) { +function Table({ sheetUpdating }) { const dispatch = useDispatch(); const rows = useSelector((state) => state.allCells.cells); @@ -194,7 +194,6 @@ function Table({ rowData, sheetUpdating, payrollData }) { { - const isPayrollEnabled = JSON.parse(localStorage.getItem("isPayrollEnabled")); - +const TableCell = ({ rowIndex, cellId, cellKey, sheetUpdating }) => { const dispatch = useDispatch(); const row = useSelector((state) => state.allCells.cells[rowIndex]); const cell = row[cellKey]; const isEditing = useSelector((state) => state.edit.cellId === cellId); - const isOverride = () => { - // Is override if cell exists, has an override amount and is not an actual - return cell && cell.overrideAmount !== null && cell.isEditable; - }; - - if (isOverride()) { - cell.amount = cell.overrideAmount; - } - const [isUpdating, setIsUpdating] = useState(false); const isRowSelected = useSelector( @@ -72,7 +55,6 @@ const TableCell = ({ if (!cell) return classes.join(" "); if (cell && cell.amount < 0) classes.push("negative"); - if (isOverride()) classes.push("override"); if (wasEdited()) classes.push("edited"); isActual ? classes.push("is-actual") : classes.push("is-forecast"); @@ -131,11 +113,7 @@ const TableCell = ({ setIsUpdating(false); if (response.status === 200) { // TODO (FFT-100): Test paste to excel with locked payroll forecast rows - let rows = processForecastData( - response.data, - payrollData, - isPayrollEnabled, - ); + let rows = processForecastData(response.data); dispatch(SET_CELLS({ cells: rows })); } else { dispatch( @@ -225,8 +203,12 @@ const TableCell = ({ className={getClasses()} id={getId()} onDoubleClick={() => { - if (isEditable && !isOverride()) { - dispatch(SET_EDITING_CELL({ cellId: cellId })); + if (isEditable) { + dispatch( + SET_EDITING_CELL({ + cellId: cellId, + }), + ); } }} > diff --git a/front_end/src/Util.js b/front_end/src/Util.js index 1c857f18..cc31ec12 100644 --- a/front_end/src/Util.js +++ b/front_end/src/Util.js @@ -123,17 +123,8 @@ export async function postData(url = "", data = {}) { }; } -export const processForecastData = ( - forecastData, - payrollData = null, - isPayrollEnabled = false, -) => { +export const processForecastData = (forecastData) => { let rows = []; - let mappedPayrollData = null; - - if (isPayrollEnabled) { - mappedPayrollData = processPayrollData(payrollData); - } let financialCodeCols = [ "analysis1_code", @@ -167,35 +158,16 @@ export const processForecastData = ( colIndex++; } - const forecastKey = makeFinancialCodeKey( - "", - rowData.programme, - rowData.natural_account_code, - { - analysis1: rowData.analysis1_code, - analysis2: rowData.analysis2_code, - project: rowData.project_code, - }, - ); - // eslint-disable-next-line for (const [key, monthlyFigure] of Object.entries( rowData["monthly_figures"], )) { - let overrideAmount = null; - - if (isPayrollEnabled && mappedPayrollData[forecastKey]) { - const period = months[parseInt(key)]; - overrideAmount = mappedPayrollData[forecastKey][period]; - } - row[monthlyFigure.month] = { rowIndex: rowIndex, colIndex: colIndex, key: monthlyFigure.month, amount: monthlyFigure.amount, startingAmount: monthlyFigure.starting_amount, - overrideAmount: overrideAmount, }; colIndex++; @@ -207,22 +179,6 @@ export const processForecastData = ( return rows; }; -const processPayrollData = (payrollData) => { - const results = {}; - - for (const [key, value] of Object.entries(payrollData)) { - const generatedKey = makeFinancialCodeKey( - "", - value.programme_code, - value.natural_account_code, - ); - - results[generatedKey] = value; - } - - return results; -}; - export const makeFinancialCodeKey = ( costCentre, programme, diff --git a/front_end/styles/styles.scss b/front_end/styles/styles.scss index 7c273e99..fa49d985 100644 --- a/front_end/styles/styles.scss +++ b/front_end/styles/styles.scss @@ -223,7 +223,6 @@ th { background-color: rgba(86, 148, 202, 0.25); } -.override, .not-editable.is-forecast { background-color: rgba(201, 155, 75, 0.25);