Remove dead and debug-only code from elements index
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import axios from "axios";
|
||||
|
||||
import _ from "lodash";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import { useRouter } from "next/router";
|
||||
@@ -7,13 +5,9 @@ import React, { useEffect } from "react";
|
||||
import "react-datepicker/dist/react-datepicker.css";
|
||||
import { Field } from "redux-form";
|
||||
import fieldLookup from "../../data/crmfieldlookuptranslations.json";
|
||||
import pickListLookup from "../../data/picklistLookups.json";
|
||||
|
||||
import { setFileCount } from "../../store/appealType/action";
|
||||
|
||||
import "react-quill-new/dist/quill.snow.css";
|
||||
|
||||
import { useStore as store, useSelector } from "react-redux";
|
||||
import { validateField } from "./validationUtils"; // Import the validation function
|
||||
import { getFieldTranslation } from "./helpers/translationHelpers";
|
||||
import { RenderRichMultiline } from "./fields/renderRichMultiline";
|
||||
@@ -75,33 +69,6 @@ export function Textfield(props) {
|
||||
hint
|
||||
} = props;
|
||||
|
||||
const required = (value) => {
|
||||
let errors;
|
||||
|
||||
// Check for the required field
|
||||
if (!value) {
|
||||
errors = t("newappeal:is-required-label");
|
||||
} else {
|
||||
// Check for emojis using a regular expression
|
||||
const emojiRegex =
|
||||
/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu;
|
||||
|
||||
if (emojiRegex.test(value)) {
|
||||
errors = "Emojis are not allowed";
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
const postcode = (value) =>
|
||||
value &&
|
||||
!/^([A-Z][A-HJ-Y]?[0-9][A-Z0-9]? ?[0-9][A-Z]{2}|GIR ?0A{2})$/i.test(
|
||||
value
|
||||
)
|
||||
? t("newappeal:invalid-postcode-label")
|
||||
: undefined;
|
||||
|
||||
let { t } = useTranslation();
|
||||
|
||||
if (name == "pinswg_name") {
|
||||
@@ -238,25 +205,6 @@ export function MultiLinefield(props) {
|
||||
hint
|
||||
} = props;
|
||||
|
||||
const required = (value) => {
|
||||
let errors;
|
||||
|
||||
// Check for the required field
|
||||
if (!value) {
|
||||
errors = t("newappeal:is-required-label");
|
||||
} else {
|
||||
// Check for emojis using a regular expression
|
||||
const emojiRegex =
|
||||
/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu;
|
||||
|
||||
if (emojiRegex.test(value)) {
|
||||
errors = t("newappeal:emojis-not-allowed-label");
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
var showIfHasParentShowValue = isVisibleByInclusion({
|
||||
parentField,
|
||||
form,
|
||||
@@ -365,9 +313,6 @@ export function RichMultiLinefield(props) {
|
||||
validation,
|
||||
maxFieldLength
|
||||
} = props;
|
||||
const required = (value) =>
|
||||
value ? undefined : t("newappeal:is-required-label");
|
||||
|
||||
var showIfHasParentShowValue = isVisibleByInclusion({
|
||||
parentField,
|
||||
form,
|
||||
@@ -475,7 +420,6 @@ export function DateFieldPicker(props) {
|
||||
let dateStart = props.dateStart;
|
||||
let dateEnd = props.dateEnd;
|
||||
let { t } = useTranslation();
|
||||
const required = (value) => (value ? undefined : "Required");
|
||||
var showIfHasParentShowValue = isVisibleByEquality({
|
||||
parentField,
|
||||
form,
|
||||
@@ -651,7 +595,6 @@ export function YesNofield(props) {
|
||||
} = props;
|
||||
const yesNo = router.locale == "cy" ? ["Ydw", "Na"] : ["Yes", "No"];
|
||||
const required = (value) => (value ? undefined : "Required");
|
||||
|
||||
var showIfHasParentShowValue = isVisibleByInclusion({
|
||||
parentField,
|
||||
form,
|
||||
@@ -718,7 +661,6 @@ export function Radiofield(props) {
|
||||
} = props;
|
||||
|
||||
const router = useRouter();
|
||||
const required = (value) => (value ? undefined : "Required");
|
||||
// console.log(props.options);
|
||||
let { t } = useTranslation();
|
||||
|
||||
@@ -803,8 +745,7 @@ export function Radiofield(props) {
|
||||
export function CheckBoxfield(props) {
|
||||
const router = useRouter();
|
||||
|
||||
console.log(props);
|
||||
const required = (value) => (value ? undefined : "Required");
|
||||
let { t } = useTranslation();
|
||||
const fieldOptions =
|
||||
router.locale == "cy" ? ["Ydw", "Na", "2323"] : ["Yes", "No", "23232"];
|
||||
return (
|
||||
@@ -955,21 +896,6 @@ export function DecimalField(props) {
|
||||
|
||||
let { t } = useTranslation();
|
||||
|
||||
const required = (value) =>
|
||||
value ? undefined : t("newappeal:is-required-label");
|
||||
|
||||
const isNumber = (value) => {
|
||||
const regex = /^\d*\.?\d{0,1}$/;
|
||||
return regex.test(value)
|
||||
? undefined
|
||||
: t("newappeal:invalid-number-label");
|
||||
};
|
||||
|
||||
const maxLength = (max) => (value) =>
|
||||
value && value.length > max
|
||||
? `Must be ${max} characters or less`
|
||||
: undefined;
|
||||
|
||||
//parentFieldShowOnValue
|
||||
var showIfHasParentShowValue = isVisibleByInclusion({
|
||||
parentField,
|
||||
@@ -983,10 +909,6 @@ export function DecimalField(props) {
|
||||
|
||||
//console.log("parentField:", parentField, showIfHasParentShowValue);
|
||||
|
||||
const normalizeDecimal = (value) => {
|
||||
return value ? parseFloat(value) : value;
|
||||
};
|
||||
|
||||
const validateDecimal = (value) => {
|
||||
if (!value) return t("newappeal:is-required-label");
|
||||
|
||||
@@ -1059,8 +981,6 @@ export function DecimalField(props) {
|
||||
);
|
||||
}
|
||||
|
||||
const RenderCaseID = {};
|
||||
|
||||
export function ReadOnlyfield(props) {
|
||||
const { name, label, value } = props;
|
||||
//console.log(props.value.refno);
|
||||
@@ -1098,13 +1018,6 @@ export const FieldsTranslations = (label) => {
|
||||
};
|
||||
|
||||
export function FileUploadField(props) {
|
||||
const uploadCount =
|
||||
typeof props.uploadCount === "number" ? props.uploadCount : 0;
|
||||
const setFileCount =
|
||||
typeof props.setFileCount === "function"
|
||||
? props.setFileCount
|
||||
: () => {};
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2 className="govuk-heading-s">
|
||||
|
||||
@@ -3612,3 +3612,33 @@ Validation:
|
||||
Follow-ups:
|
||||
|
||||
- Continue bounded no-behavior-change slices by extracting one additional low-risk wrapper (e.g., `CheckBoxfield`) or removing dead locals/debug logging in place.
|
||||
|
||||
---
|
||||
|
||||
### CL-102: 22500 `components/elements/index.js` dead/debug-only cleanup slice
|
||||
|
||||
date: 2026-04-08
|
||||
author: Cline
|
||||
scope: `components/elements/index.js`
|
||||
type: change
|
||||
rationale: Execute requested bounded cleanup slice by removing dead code and debug-only artifacts from the elements monolith without changing behavior.
|
||||
impact: No intended behavior change; EN/CY and accessibility behavior preserved while reducing noise and unused code paths.
|
||||
status: completed
|
||||
|
||||
Summary:
|
||||
|
||||
- Removed debug-only runtime log in `CheckBoxfield` (`console.log(props)`).
|
||||
- Removed unused/dead locals and helpers inside `components/elements/index.js`, including:
|
||||
- top-level unused imports (`axios`, `pickListLookup`, `setFileCount` action import, redux hooks import)
|
||||
- unused local validators and helpers in wrappers (e.g., unused `required`/`postcode`/`normalizeDecimal` variants)
|
||||
- unused placeholder constant `RenderCaseID`
|
||||
- unused local fallbacks in `FileUploadField` (`uploadCount`, local `setFileCount`)
|
||||
- Kept functional field wiring, labels/translations, and validation behavior in active render paths unchanged.
|
||||
|
||||
Validation:
|
||||
|
||||
- `npx eslint components/elements/index.js` -> pass
|
||||
|
||||
Follow-ups:
|
||||
|
||||
- Continue bounded no-behavior-change slices only (e.g., extract one additional low-risk wrapper such as `CheckBoxfield`).
|
||||
|
||||
Reference in New Issue
Block a user