Handle "in:true,false" variable rules as checkbox (#4334)
This commit is contained in:
parent
8e1a21563e
commit
b04a47a4a4
1 changed files with 12 additions and 3 deletions
|
@ -52,7 +52,10 @@ const VariableBox = ({ variable }: Props) => {
|
||||||
.then(() => setLoading(false));
|
.then(() => setLoading(false));
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
const useSwitch = variable.rules.some((v) => v === 'boolean' || v === 'in:0,1');
|
const useSwitch = variable.rules.some(
|
||||||
|
(v) => v === 'boolean' || v === 'in:0,1' || v === 'in:1,0' || v === 'in:true,false' || v === 'in:false,true'
|
||||||
|
);
|
||||||
|
const isStringSwitch = variable.rules.some((v) => v === 'string');
|
||||||
const selectValues = variable.rules.find((v) => v.startsWith('in:'))?.split(',') || [];
|
const selectValues = variable.rules.find((v) => v.startsWith('in:'))?.split(',') || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -73,11 +76,17 @@ const VariableBox = ({ variable }: Props) => {
|
||||||
<Switch
|
<Switch
|
||||||
readOnly={!canEdit || !variable.isEditable}
|
readOnly={!canEdit || !variable.isEditable}
|
||||||
name={variable.envVariable}
|
name={variable.envVariable}
|
||||||
defaultChecked={variable.serverValue === '1'}
|
defaultChecked={
|
||||||
|
isStringSwitch ? variable.serverValue === 'true' : variable.serverValue === '1'
|
||||||
|
}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
if (canEdit && variable.isEditable) {
|
if (canEdit && variable.isEditable) {
|
||||||
|
if (isStringSwitch) {
|
||||||
|
setVariableValue(variable.serverValue === 'true' ? 'false' : 'true');
|
||||||
|
} else {
|
||||||
setVariableValue(variable.serverValue === '1' ? '0' : '1');
|
setVariableValue(variable.serverValue === '1' ? '0' : '1');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue