diff --git a/client/src/components/dms-post-form/rr-dms-post-form.jsx b/client/src/components/dms-post-form/rr-dms-post-form.jsx index 669bac7fd..6cdea243e 100644 --- a/client/src/components/dms-post-form/rr-dms-post-form.jsx +++ b/client/src/components/dms-post-form/rr-dms-post-form.jsx @@ -1,4 +1,4 @@ -import { ReloadOutlined } from "@ant-design/icons"; +import { ReloadOutlined, RollbackOutlined } from "@ant-design/icons"; import { Button, Card, @@ -27,8 +27,8 @@ import dayjs from "../../utils/day"; * @param job * @param logsRef * @param allocationsSummary - * @param opCodeParts - * @param onChangeOpCodeParts + * @param opCodeParts // { prefix, base, suffix } from container + * @param onChangeOpCodeParts // (partsWithFlags) => void * @returns {JSX.Element} * @constructor */ @@ -44,12 +44,18 @@ export default function RRPostForm({ const [form] = Form.useForm(); const { t } = useTranslation(); + // Capture the baseline/default OpCode parts ONCE per mount (tied to resetKey in container) + const [baselineOpCodeParts] = useState(() => ({ + prefix: opCodeParts?.prefix ?? "", + base: opCodeParts?.base ?? "", + suffix: opCodeParts?.suffix ?? "" + })); + // Advisors const [advisors, setAdvisors] = useState([]); const [advLoading, setAdvLoading] = useState(false); const getAdvisorNumber = (a) => a?.advisorId; - const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim(); const fetchRrAdvisors = (refresh = false) => { @@ -121,15 +127,34 @@ export default function RRPostForm({ const opBaseWatch = Form.useWatch("opBase", form); const opSuffixWatch = Form.useWatch("opSuffix", form); + // Detect if current form values differ from baseline defaults + const isCustomOpCode = useMemo(() => { + const current = { + prefix: opPrefixWatch !== undefined ? opPrefixWatch : (baselineOpCodeParts.prefix ?? ""), + base: opBaseWatch !== undefined ? opBaseWatch : (baselineOpCodeParts.base ?? ""), + suffix: opSuffixWatch !== undefined ? opSuffixWatch : (baselineOpCodeParts.suffix ?? "") + }; + + return ( + current.prefix !== (baselineOpCodeParts.prefix ?? "") || + current.base !== (baselineOpCodeParts.base ?? "") || + current.suffix !== (baselineOpCodeParts.suffix ?? "") + ); + }, [opPrefixWatch, opBaseWatch, opSuffixWatch, baselineOpCodeParts]); + + // Push changes up to container with some metadata useEffect(() => { if (!onChangeOpCodeParts) return; - onChangeOpCodeParts({ + const parts = { prefix: opPrefixWatch || "", base: opBaseWatch || "", - suffix: opSuffixWatch || "" - }); - }, [opPrefixWatch, opBaseWatch, opSuffixWatch, onChangeOpCodeParts]); + suffix: opSuffixWatch || "", + isCustom: isCustomOpCode + }; + + onChangeOpCodeParts(parts); + }, [opPrefixWatch, opBaseWatch, opSuffixWatch, isCustomOpCode, onChangeOpCodeParts]); const handleFinish = (values) => { if (!socket) return; @@ -175,6 +200,14 @@ export default function RRPostForm({ ); }, [allocationsSummary]); + const handleResetOpCode = () => { + form.setFieldsValue({ + opPrefix: baselineOpCodeParts.prefix, + opBase: baselineOpCodeParts.base, + opSuffix: baselineOpCodeParts.suffix + }); + }; + return (
- + + {t("jobs.fields.dms.rr_opcode", "RR OpCode")} + {isCustomOpCode && ( + + )} + + } + >