🎨 feat(ui): dynamic multi-key controls in Channel editor
Summary 1. Load `channel_info` when editing: • Detect if the channel is in multi-key mode (`is_multi_key`). • Auto-initialize `batch`, `multiToSingle`, and `multiKeyMode` from backend data. 2. Visibility logic • Creation page: “Batch create / Multi-key mode” always available. • Edit page: show these controls **only when** the channel itself is multi-key. 3. State consistency • `multi_key_mode` added to `inputs`; `setValues(inputs)` now preserves the user’s selection. Result Single-key channels no longer display irrelevant “key aggregation” options, while multi-key channels open with the correct defaults, providing a cleaner and more accurate editing experience.
This commit is contained in:
@@ -108,7 +108,6 @@ const EditChannel = (props) => {
|
|||||||
const [multiToSingle, setMultiToSingle] = useState(false);
|
const [multiToSingle, setMultiToSingle] = useState(false);
|
||||||
const [multiKeyMode, setMultiKeyMode] = useState('random');
|
const [multiKeyMode, setMultiKeyMode] = useState('random');
|
||||||
const [autoBan, setAutoBan] = useState(true);
|
const [autoBan, setAutoBan] = useState(true);
|
||||||
// const [autoBan, setAutoBan] = useState(true);
|
|
||||||
const [inputs, setInputs] = useState(originInputs);
|
const [inputs, setInputs] = useState(originInputs);
|
||||||
const [originModelOptions, setOriginModelOptions] = useState([]);
|
const [originModelOptions, setOriginModelOptions] = useState([]);
|
||||||
const [modelOptions, setModelOptions] = useState([]);
|
const [modelOptions, setModelOptions] = useState([]);
|
||||||
@@ -122,6 +121,7 @@ const EditChannel = (props) => {
|
|||||||
const [vertexKeys, setVertexKeys] = useState([]);
|
const [vertexKeys, setVertexKeys] = useState([]);
|
||||||
const [vertexFileList, setVertexFileList] = useState([]);
|
const [vertexFileList, setVertexFileList] = useState([]);
|
||||||
const vertexErroredNames = useRef(new Set()); // 避免重复报错
|
const vertexErroredNames = useRef(new Set()); // 避免重复报错
|
||||||
|
const [isMultiKeyChannel, setIsMultiKeyChannel] = useState(false);
|
||||||
const getInitValues = () => ({ ...originInputs });
|
const getInitValues = () => ({ ...originInputs });
|
||||||
const handleInputChange = (name, value) => {
|
const handleInputChange = (name, value) => {
|
||||||
if (formApiRef.current) {
|
if (formApiRef.current) {
|
||||||
@@ -219,6 +219,19 @@ const EditChannel = (props) => {
|
|||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const chInfo = data.channel_info || {};
|
||||||
|
const isMulti = chInfo.is_multi_key === true;
|
||||||
|
setIsMultiKeyChannel(isMulti);
|
||||||
|
if (isMulti) {
|
||||||
|
setBatch(true);
|
||||||
|
setMultiToSingle(true);
|
||||||
|
const modeVal = chInfo.multi_key_mode || 'random';
|
||||||
|
setMultiKeyMode(modeVal);
|
||||||
|
data.multi_key_mode = modeVal;
|
||||||
|
} else {
|
||||||
|
setBatch(false);
|
||||||
|
setMultiToSingle(false);
|
||||||
|
}
|
||||||
setInputs(data);
|
setInputs(data);
|
||||||
if (formApiRef.current) {
|
if (formApiRef.current) {
|
||||||
formApiRef.current.setValues(data);
|
formApiRef.current.setValues(data);
|
||||||
@@ -545,7 +558,7 @@ const EditChannel = (props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const batchAllowed = !isEdit;
|
const batchAllowed = !isEdit || isMultiKeyChannel;
|
||||||
const batchExtra = batchAllowed ? (
|
const batchExtra = batchAllowed ? (
|
||||||
<Space>
|
<Space>
|
||||||
<Checkbox checked={batch} onChange={() => {
|
<Checkbox checked={batch} onChange={() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user