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 {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
@@ -27,8 +27,8 @@ import dayjs from "../../utils/day";
|
|||||||
* @param job
|
* @param job
|
||||||
* @param logsRef
|
* @param logsRef
|
||||||
* @param allocationsSummary
|
* @param allocationsSummary
|
||||||
* @param opCodeParts
|
* @param opCodeParts // { prefix, base, suffix } from container
|
||||||
* @param onChangeOpCodeParts
|
* @param onChangeOpCodeParts // (partsWithFlags) => void
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
@@ -44,12 +44,18 @@ export default function RRPostForm({
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const { t } = useTranslation();
|
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
|
// Advisors
|
||||||
const [advisors, setAdvisors] = useState([]);
|
const [advisors, setAdvisors] = useState([]);
|
||||||
const [advLoading, setAdvLoading] = useState(false);
|
const [advLoading, setAdvLoading] = useState(false);
|
||||||
|
|
||||||
const getAdvisorNumber = (a) => a?.advisorId;
|
const getAdvisorNumber = (a) => a?.advisorId;
|
||||||
|
|
||||||
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
|
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
|
||||||
|
|
||||||
const fetchRrAdvisors = (refresh = false) => {
|
const fetchRrAdvisors = (refresh = false) => {
|
||||||
@@ -121,15 +127,34 @@ export default function RRPostForm({
|
|||||||
const opBaseWatch = Form.useWatch("opBase", form);
|
const opBaseWatch = Form.useWatch("opBase", form);
|
||||||
const opSuffixWatch = Form.useWatch("opSuffix", 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(() => {
|
useEffect(() => {
|
||||||
if (!onChangeOpCodeParts) return;
|
if (!onChangeOpCodeParts) return;
|
||||||
|
|
||||||
onChangeOpCodeParts({
|
const parts = {
|
||||||
prefix: opPrefixWatch || "",
|
prefix: opPrefixWatch || "",
|
||||||
base: opBaseWatch || "",
|
base: opBaseWatch || "",
|
||||||
suffix: opSuffixWatch || ""
|
suffix: opSuffixWatch || "",
|
||||||
});
|
isCustom: isCustomOpCode
|
||||||
}, [opPrefixWatch, opBaseWatch, opSuffixWatch, onChangeOpCodeParts]);
|
};
|
||||||
|
|
||||||
|
onChangeOpCodeParts(parts);
|
||||||
|
}, [opPrefixWatch, opBaseWatch, opSuffixWatch, isCustomOpCode, onChangeOpCodeParts]);
|
||||||
|
|
||||||
const handleFinish = (values) => {
|
const handleFinish = (values) => {
|
||||||
if (!socket) return;
|
if (!socket) return;
|
||||||
@@ -175,6 +200,14 @@ export default function RRPostForm({
|
|||||||
);
|
);
|
||||||
}, [allocationsSummary]);
|
}, [allocationsSummary]);
|
||||||
|
|
||||||
|
const handleResetOpCode = () => {
|
||||||
|
form.setFieldsValue({
|
||||||
|
opPrefix: baselineOpCodeParts.prefix,
|
||||||
|
opBase: baselineOpCodeParts.base,
|
||||||
|
opSuffix: baselineOpCodeParts.suffix
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card title={t("jobs.labels.dms.postingform")}>
|
<Card title={t("jobs.labels.dms.postingform")}>
|
||||||
<Form
|
<Form
|
||||||
@@ -224,7 +257,25 @@ export default function RRPostForm({
|
|||||||
|
|
||||||
{/* RR OpCode (prefix / base / suffix) */}
|
{/* RR OpCode (prefix / base / suffix) */}
|
||||||
<Col xs={24} sm={12} md={12} lg={8}>
|
<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>
|
<Space.Compact block>
|
||||||
<Form.Item name="opPrefix" noStyle>
|
<Form.Item name="opPrefix" noStyle>
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
Reference in New Issue
Block a user