Skip to content

Commit

Permalink
FFT-175 Bump node dependencies and refactor react code (#612)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Dudley <[email protected]>
  • Loading branch information
DenisDDBT and SamDudley authored Feb 10, 2025
1 parent 20e64e4 commit f6729d3
Show file tree
Hide file tree
Showing 17 changed files with 885 additions and 665 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,9 @@ ner_output_file.txt

# DB
.dumps/

# hide all .env.* file
.env.*
# except for the ones we explicit allow and need to checkin
!.env.example
!.env.ci
8 changes: 7 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

from django.conf import settings
from django.contrib import admin
from django.urls import include, path
from django.http import HttpResponse
from django.urls import include, path, re_path
from django.views.generic.base import RedirectView


def empty_favicon(request):
return HttpResponse(status=204)


urlpatterns = [
path("auth/", include("authbroker_client.urls", namespace="authbroker")),
path("", include("core.urls")), # default to core with no path
Expand All @@ -38,6 +43,7 @@
path("payroll/", include("payroll.urls")),
path("admin/", admin.site.urls),
# TODO - split below out into develop only?
path("favicon.ico", empty_favicon),
path(
"assets/<path:asset_path>",
RedirectView.as_view(url="/static/govuk/assets/%(asset_path)s"),
Expand Down
10 changes: 2 additions & 8 deletions front_end/src/Components/EditForecast/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ function EditForecast() {
window.payroll_forecast_data,
isPayrollEnabled,
);
dispatch({
type: SET_CELLS,
cells: rows,
});
dispatch(SET_CELLS({ cells: rows }));
} else {
timer();
}
Expand Down Expand Up @@ -96,10 +93,7 @@ function EditForecast() {
if (response.status === 200) {
setSheetUpdating(false);
let rows = processForecastData(response.data);
dispatch({
type: SET_CELLS,
cells: rows,
});
dispatch(SET_CELLS({ cells: rows }));
} else {
setSheetUpdating(false);
dispatch(
Expand Down
47 changes: 8 additions & 39 deletions front_end/src/Components/InfoCell/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,24 @@ const InfoCell = ({
className,
ignoreSelection,
}) => {
const selectedRow = useSelector((state) => state.selected.selectedRow);
const allSelected = useSelector((state) => state.selected.all);
let changed = false;

const checkValue = (hiddenCols) => {
if (hiddenCols.indexOf(cellKey) > -1) {
changed = true;
return false;
} else if (changed) {
changed = false;
return false;
}

return true;
};

const hiddenCols = useSelector(
(state) => state.hiddenCols.hiddenCols,
checkValue,
const isRowSelected = useSelector(
(state) => state.selected.all || state.selected.selectedRow === rowIndex,
);
const isColHidden = useSelector(
(state) => state.hiddenCols.hiddenCols.indexOf(cellKey) > -1,
);

const isSelected = () => {
if (ignoreSelection) return false;

if (allSelected) {
return true;
}

return selectedRow === rowIndex;
};

const getClasses = () => {
return (
"govuk-table__cell forecast-month-cell not-editable " +
className +
" " +
(isSelected() ? "selected " : "") +
(hiddenCols.indexOf(cellKey) > -1 ? "hidden" : "")
(!ignoreSelection && isRowSelected ? "selected " : "") +
(isColHidden ? "hidden" : "")
);
};

return <td className={getClasses()}>{children}</td>;
};

const comparisonFn = function (prevProps, nextProps) {
return (
prevProps.selectedRow === nextProps.selectedRow &&
prevProps.allSelected === nextProps.allSelected
);
};

export default memo(InfoCell, comparisonFn);
export default InfoCell;
61 changes: 8 additions & 53 deletions front_end/src/Components/TableCell/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,13 @@ const TableCell = ({
sheetUpdating,
payrollData,
}) => {
let editing = false;
const isPayrollEnabled = JSON.parse(localStorage.getItem("isPayrollEnabled"));

const checkValue = (val) => {
if (cellId === val) {
editing = true;
return false;
} else if (editing) {
// Turn off editing
editing = false;
return false;
}

return true;
};

let selectChanged = false;

const checkSelectRow = (selectedRow) => {
if (selectedRow === rowIndex) {
selectChanged = true;
return false;
} else if (selectChanged) {
selectChanged = false;
return false;
}

return true;
};

const dispatch = useDispatch();

const row = useSelector((state) => state.allCells.cells[rowIndex]);
const cell = row[cellKey];
const editCellId = useSelector((state) => state.edit.cellId, checkValue);
const isEditing = useSelector((state) => state.edit.cellId === cellId);

const isOverride = () => {
// Is override if cell exists, has an override amount and is not an actual
Expand All @@ -59,11 +31,9 @@ const TableCell = ({

const [isUpdating, setIsUpdating] = useState(false);

const selectedRow = useSelector(
(state) => state.selected.selectedRow,
checkSelectRow,
const isRowSelected = useSelector(
(state) => state.selected.all || state.selected.selectedRow === rowIndex,
);
const allSelected = useSelector((state) => state.selected.all);

let isLocked = row._meta.isLocked;
// window.actuals = [1, 2];
Expand All @@ -88,14 +58,6 @@ const TableCell = ({
}
}, [cell]);

const isSelected = () => {
if (allSelected) {
return true;
}

return selectedRow === rowIndex;
};

const wasEdited = () => {
if (!isEditable) return false;

Expand All @@ -106,7 +68,7 @@ const TableCell = ({
const classes = ["govuk-table__cell", "forecast-month-cell", "figure-cell"];

if (!isEditable) classes.push("not-editable");
if (isSelected()) classes.push("selected");
if (isRowSelected) classes.push("selected");
if (!cell) return classes.join(" ");

if (cell && cell.amount < 0) classes.push("negative");
Expand Down Expand Up @@ -174,10 +136,7 @@ const TableCell = ({
payrollData,
isPayrollEnabled,
);
dispatch({
type: SET_CELLS,
cells: rows,
});
dispatch(SET_CELLS({ cells: rows }));
} else {
dispatch(
SET_ERROR({
Expand Down Expand Up @@ -225,7 +184,7 @@ const TableCell = ({

if (isUpdating) return true;

if (sheetUpdating && isSelected()) {
if (sheetUpdating && isRowSelected) {
return true;
}

Expand All @@ -240,7 +199,7 @@ const TableCell = ({
</Fragment>
);
} else {
if (editCellId === cellId) {
if (isEditing) {
return (
<input
ref={(input) => input && input.focus()}
Expand All @@ -267,11 +226,7 @@ const TableCell = ({
id={getId()}
onDoubleClick={() => {
if (isEditable && !isOverride()) {
dispatch(
SET_EDITING_CELL({
cellId: cellId,
}),
);
dispatch(SET_EDITING_CELL({ cellId: cellId }));
}
}}
>
Expand Down
26 changes: 3 additions & 23 deletions front_end/src/Components/TableHeader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@ import React from "react";
import { useSelector } from "react-redux";

const TableHeader = ({ children, colName }) => {
let changed = false;

const checkValue = (hiddenCols) => {
if (hiddenCols.indexOf(colName) > -1) {
changed = true;
return false;
} else if (changed) {
changed = false;
return false;
}

return true;
};

const hiddenCols = useSelector(
(state) => state.hiddenCols.hiddenCols,
checkValue,
const isColHidden = useSelector(
(state) => state.hiddenCols.hiddenCols.indexOf(colName) > -1,
);

return (
<th
className={
"govuk-table__header " +
(hiddenCols.indexOf(colName) > -1 ? "hidden" : "")
}
>
<th className={"govuk-table__header " + (isColHidden ? "hidden" : "")}>
{children}
</th>
);
Expand Down
51 changes: 6 additions & 45 deletions front_end/src/Components/ToggleCell/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,18 @@ import React from "react";
import { useSelector } from "react-redux";

const ToggleCell = ({ rowIndex, colName, children }) => {
let changed = false;

const checkValue = (hiddenCols) => {
if (hiddenCols.indexOf(colName) > -1) {
changed = true;
return false;
} else if (changed) {
changed = false;
return false;
}

return true;
};

let selectChanged = false;

const checkSelectRow = (selectedRow) => {
if (selectedRow === rowIndex) {
selectChanged = true;
return false;
} else if (selectChanged) {
selectChanged = false;
return false;
}

return true;
};

const selectedRow = useSelector(
(state) => state.selected.selectedRow,
checkSelectRow,
const isRowSelected = useSelector(
(state) => state.selected.all || state.selected.selectedRow === rowIndex,
);
const allSelected = useSelector((state) => state.selected.all);
const hiddenCols = useSelector(
(state) => state.hiddenCols.hiddenCols,
checkValue,
const isColHidden = useSelector(
(state) => state.hiddenCols.hiddenCols.indexOf(colName) > -1,
);

const isSelected = () => {
if (allSelected) {
return true;
}

return selectedRow === rowIndex;
};

const getClasses = () => {
return (
"govuk-table__cell forecast-month-cell not-editable " +
(isSelected() ? "selected " : "") +
(hiddenCols.indexOf(colName) > -1 ? "hidden" : "")
(isRowSelected ? "selected " : "") +
(isColHidden ? "hidden" : "")
);
};

Expand Down
1 change: 0 additions & 1 deletion front_end/src/Reducers/CellCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createSlice } from "@reduxjs/toolkit";

const cellCount = createSlice({
name: "cellCount",
slice: "cellCount",
initialState: {
cellCount: 0,
},
Expand Down
3 changes: 1 addition & 2 deletions front_end/src/Reducers/Cells.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { createSlice } from "@reduxjs/toolkit";

const allCells = createSlice({
name: "allCells",
slice: "allCells",
initialState: {
cells: [],
},
reducers: {
SET_CELLS: (state, action) => {
state.cells = action.cells;
state.cells = action.payload.cells;
},
},
});
Expand Down
1 change: 0 additions & 1 deletion front_end/src/Reducers/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createSlice } from "@reduxjs/toolkit";

const edit = createSlice({
name: "edit",
slice: "edit",
initialState: {
cellId: null,
},
Expand Down
1 change: 0 additions & 1 deletion front_end/src/Reducers/Error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createSlice } from "@reduxjs/toolkit";

const error = createSlice({
name: "error",
slice: "error",
initialState: {
errorMessage: null,
},
Expand Down
1 change: 0 additions & 1 deletion front_end/src/Reducers/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createSlice } from "@reduxjs/toolkit";

const filter = createSlice({
name: "filter",
slice: "edit",
initialState: {
open: false,
},
Expand Down
Loading

0 comments on commit f6729d3

Please sign in to comment.