Skip to content

Commit bd25805

Browse files
authored
Support the radio config item type (#2441)
* Support the radio config item type * remove log
1 parent dff1177 commit bd25805

File tree

3 files changed

+335
-29
lines changed

3 files changed

+335
-29
lines changed

web/src/components/common/Input.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface InputProps {
1616
className?: string;
1717
labelClassName?: string;
1818
icon?: React.ReactNode;
19+
dataTestId?: string;
1920
}
2021

2122
const Input: React.FC<InputProps> = ({
@@ -33,6 +34,7 @@ const Input: React.FC<InputProps> = ({
3334
className = '',
3435
labelClassName = '',
3536
icon,
37+
dataTestId,
3638
}) => {
3739
const { settings } = useSettings();
3840
const themeColor = settings.themeColor;
@@ -67,6 +69,7 @@ const Input: React.FC<InputProps> = ({
6769
'--tw-ring-color': themeColor,
6870
'--tw-ring-offset-color': themeColor,
6971
} as React.CSSProperties}
72+
data-testid={dataTestId}
7073
/>
7174
</div>
7275
{error && <p className="mt-1 text-sm text-red-500">{error}</p>}

web/src/components/wizard/config/ConfigurationStep.tsx

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,45 +130,80 @@ const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ onNext }) => {
130130
updateConfigValue(id, checked ? '1' : '0');
131131
};
132132

133-
const renderConfigItem = (item: AppConfigItem) => {
134-
const key = item.name;
135-
const value = item.value || item.default || '';
136-
137-
const commonProps = {
138-
id: key,
139-
label: item.title,
140-
value: value.toString(),
141-
};
133+
const handleRadioChange = (parentId: string, e: React.ChangeEvent<HTMLInputElement>) => {
134+
const { id, checked } = e.target;
135+
if (!checked) return;
136+
updateConfigValue(parentId, id);
137+
};
142138

139+
const renderConfigItem = (item: AppConfigItem) => {
143140
switch (item.type) {
144141
case 'text':
145142
return (
146143
<Input
147-
{...commonProps}
144+
id={item.name}
145+
label={item.title}
146+
value={item.value || ''}
147+
placeholder={item.default}
148148
onChange={handleInputChange}
149-
placeholder={item.default?.toString() || ''}
149+
dataTestId={`text-input-${item.name}`}
150150
/>
151151
);
152152

153153
case 'bool':
154154
return (
155155
<div className="flex items-center space-x-3">
156156
<input
157-
id={key}
157+
id={item.name}
158158
type="checkbox"
159-
checked={value === '1'}
159+
checked={(item.value || item.default) === '1'}
160160
onChange={handleCheckboxChange}
161161
className="h-4 w-4 focus:ring-offset-2 border-gray-300 rounded"
162+
data-testid={`bool-input-${item.name}`}
162163
style={{
163164
color: themeColor,
164165
'--tw-ring-color': themeColor,
165166
} as React.CSSProperties}
166167
/>
167-
<label htmlFor={key} className="text-sm text-gray-700">
168+
<label htmlFor={item.name} className="text-sm text-gray-700">
168169
{item.title}
169170
</label>
170171
</div>
171172
);
173+
174+
case 'radio':
175+
if (item.items) {
176+
return (
177+
<div className="space-y-2">
178+
<label className="block text-sm font-medium text-gray-700">
179+
{item.title}
180+
</label>
181+
<div className="space-y-2">
182+
{item.items.map(child => (
183+
<div key={child.name} className="flex items-center">
184+
<input
185+
type="radio"
186+
id={child.name}
187+
value={child.name}
188+
checked={(item.value || item.default) === child.name}
189+
onChange={e => handleRadioChange(item.name, e)}
190+
className="h-4 w-4 focus:ring-offset-2 border-gray-300"
191+
data-testid={`radio-input-${child.name}`}
192+
style={{
193+
color: themeColor,
194+
'--tw-ring-color': themeColor,
195+
} as React.CSSProperties}
196+
/>
197+
<label htmlFor={child.name} className="ml-3 text-sm text-gray-700">
198+
{child.title}
199+
</label>
200+
</div>
201+
))}
202+
</div>
203+
</div>
204+
);
205+
}
206+
return null;
172207
}
173208
};
174209

0 commit comments

Comments
 (0)