@@ -4,12 +4,14 @@ import TitledGreyBox from '@/components/elements/TitledGreyBox';
44import { usePermissions } from '@/plugins/usePermissions' ;
55import InputSpinner from '@/components/elements/InputSpinner' ;
66import Input from '@/components/elements/Input' ;
7+ import Switch from '@/components/elements/Switch' ;
78import tw from 'twin.macro' ;
89import { debounce } from 'debounce' ;
910import updateStartupVariable from '@/api/server/updateStartupVariable' ;
1011import useFlash from '@/plugins/useFlash' ;
1112import FlashMessageRender from '@/components/FlashMessageRender' ;
1213import getServerStartup from '@/api/swr/getServerStartup' ;
14+ import Select from '@/components/elements/Select' ;
1315import isEqual from 'react-fast-compare' ;
1416import { ServerContext } from '@/state/server' ;
1517
@@ -43,6 +45,9 @@ const VariableBox = ({ variable }: Props) => {
4345 . then ( ( ) => setLoading ( false ) ) ;
4446 } , 500 ) ;
4547
48+ const useSwitch = variable . rules . some ( v => v === 'boolean' || v === 'in:0,1' ) ;
49+ const selectValues = variable . rules . find ( v => v . startsWith ( 'in:' ) ) ?. split ( ',' ) || [ ] ;
50+
4651 return (
4752 < TitledGreyBox
4853 title = {
@@ -56,17 +61,52 @@ const VariableBox = ({ variable }: Props) => {
5661 >
5762 < FlashMessageRender byKey = { FLASH_KEY } css = { tw `mb-2 md:mb-4` } />
5863 < InputSpinner visible = { loading } >
59- < Input
60- onKeyUp = { e => {
61- if ( canEdit && variable . isEditable ) {
62- setVariableValue ( e . currentTarget . value ) ;
64+ { useSwitch ?
65+ < >
66+ < Switch
67+ readOnly = { ! canEdit || ! variable . isEditable }
68+ name = { variable . envVariable }
69+ defaultChecked = { variable . serverValue === '1' }
70+ onChange = { ( ) => {
71+ if ( canEdit && variable . isEditable ) {
72+ setVariableValue ( variable . serverValue === '1' ? '0' : '1' ) ;
73+ }
74+ } }
75+ />
76+ </ >
77+ :
78+ < >
79+ { selectValues . length > 0 ?
80+ < >
81+ < Select
82+ onChange = { e => setVariableValue ( e . target . value ) }
83+ name = { variable . envVariable }
84+ defaultValue = { variable . serverValue }
85+ disabled = { ! canEdit || ! variable . isEditable }
86+ >
87+ { selectValues . map ( selectValue => (
88+ < option key = { selectValue . replace ( 'in:' , '' ) } value = { selectValue . replace ( 'in:' , '' ) } > { selectValue . replace ( 'in:' , '' ) } </ option >
89+ ) ) }
90+ </ Select >
91+
92+ </ >
93+ :
94+ < >
95+ < Input
96+ onKeyUp = { e => {
97+ if ( canEdit && variable . isEditable ) {
98+ setVariableValue ( e . currentTarget . value ) ;
99+ }
100+ } }
101+ readOnly = { ! canEdit || ! variable . isEditable }
102+ name = { variable . envVariable }
103+ defaultValue = { variable . serverValue }
104+ placeholder = { variable . defaultValue }
105+ />
106+ </ >
63107 }
64- } }
65- readOnly = { ! canEdit || ! variable . isEditable }
66- name = { variable . envVariable }
67- defaultValue = { variable . serverValue }
68- placeholder = { variable . defaultValue }
69- />
108+ </ >
109+ }
70110 </ InputSpinner >
71111 < p css = { tw `mt-1 text-xs text-neutral-300` } >
72112 { variable . description }
0 commit comments