Skip to content

Commit 45cd8c5

Browse files
committed
f
1 parent 28eaa26 commit 45cd8c5

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
3+
interface ConfigItemProps {
4+
id: string;
5+
label: string;
6+
dataTestId?: string;
7+
helpText?: string;
8+
children: React.ReactElement;
9+
}
10+
11+
const ConfigItem: React.FC<ConfigItemProps> = ({
12+
id,
13+
label,
14+
dataTestId,
15+
helpText,
16+
children,
17+
}) => {
18+
// Clone the child element and inject the common props
19+
const enhancedChild = React.cloneElement(children, {
20+
id,
21+
label,
22+
dataTestId,
23+
helpText,
24+
} as any);
25+
26+
return (
27+
<div className="mb-4">
28+
{enhancedChild}
29+
</div>
30+
);
31+
};
32+
33+
// Helper function to create a ConfigItem-wrapped component
34+
export const withConfigItem = <P extends object>(
35+
WrappedComponent: React.ComponentType<P>
36+
) => {
37+
return React.forwardRef<any, P & Omit<ConfigItemProps, 'children'>>((props, ref) => {
38+
const { id, label, dataTestId, helpText, ...wrappedComponentProps } = props;
39+
return (
40+
<ConfigItem
41+
id={id}
42+
label={label}
43+
dataTestId={dataTestId}
44+
helpText={helpText}
45+
>
46+
<WrappedComponent {...(wrappedComponentProps as P)} ref={ref} />
47+
</ConfigItem>
48+
);
49+
});
50+
};
51+
52+
export default ConfigItem;

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,54 +163,52 @@ const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ onNext }) => {
163163
};
164164

165165
const renderConfigItem = (item: AppConfigItem) => {
166+
const sharedProps = {
167+
id: item.name,
168+
label: item.title,
169+
helpText: item.help_text,
170+
}
171+
166172
switch (item.type) {
167173
case 'text':
168174
return (
169175
<Input
170-
id={item.name}
171-
label={item.title}
176+
{...sharedProps}
172177
value={getDisplayValue(item)}
173178
onChange={handleInputChange}
174179
dataTestId={`text-input-${item.name}`}
175-
helpText={item.help_text}
176180
/>
177181
);
178182

179183
case 'textarea':
180184
return (
181185
<Textarea
182-
id={item.name}
183-
label={item.title}
186+
{...sharedProps}
184187
value={getDisplayValue(item)}
185188
onChange={handleInputChange}
186189
dataTestId={`textarea-input-${item.name}`}
187-
helpText={item.help_text}
188190
/>
189191
);
190192

191193
case 'bool':
192194
return (
193195
<Checkbox
194-
id={item.name}
195-
label={item.title}
196+
{...sharedProps}
196197
checked={getEffectiveValue(item) === '1'}
197198
onChange={handleCheckboxChange}
198199
dataTestId={`bool-input-${item.name}`}
199-
helpText={item.help_text}
200200
/>
201201
);
202202

203203
case 'radio':
204204
if (item.items) {
205205
return (
206206
<Radio
207-
id={item.name}
208-
label={item.title}
207+
{...sharedProps}
209208
value={getEffectiveValue(item)}
210-
onChange={e => handleRadioChange(item.name, e)}
211209
options={item.items}
210+
onChange={e => handleRadioChange(item.name, e)}
212211
dataTestId={`radio-input-${item.name}`}
213-
helpText={item.help_text}
214212
/>
215213
);
216214
}

0 commit comments

Comments
 (0)