Handle "in:true,false" variable rules as checkbox (#4334)

This commit is contained in:
Boy132 2022-09-25 21:18:13 +02:00 committed by GitHub
parent 8e1a21563e
commit b04a47a4a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,10 +76,16 @@ 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) {
setVariableValue(variable.serverValue === '1' ? '0' : '1'); if (isStringSwitch) {
setVariableValue(variable.serverValue === 'true' ? 'false' : 'true');
} else {
setVariableValue(variable.serverValue === '1' ? '0' : '1');
}
} }
}} }}
/> />