rrScratch3 - Progress Commit
This commit is contained in:
@@ -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 (
|
||||
<Card title={t("jobs.labels.dms.postingform")}>
|
||||
<Form
|
||||
@@ -224,7 +257,25 @@ export default function RRPostForm({
|
||||
|
||||
{/* RR OpCode (prefix / base / suffix) */}
|
||||
<Col xs={24} sm={12} md={12} lg={8}>
|
||||
<Form.Item label={t("jobs.fields.dms.rr_opcode", "RR OpCode")}>
|
||||
<Form.Item
|
||||
required
|
||||
label={
|
||||
<Space size="small" align="center">
|
||||
{t("jobs.fields.dms.rr_opcode", "RR OpCode")}
|
||||
{isCustomOpCode && (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<RollbackOutlined />}
|
||||
onClick={handleResetOpCode}
|
||||
style={{ padding: 0 }}
|
||||
>
|
||||
{t("jobs.fields.dms.rr_opcode_reset", "Reset")}
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Space.Compact block>
|
||||
<Form.Item name="opPrefix" noStyle>
|
||||
<Input
|
||||
|
||||
Reference in New Issue
Block a user