@@ -4,6 +4,27 @@ import Select from "../../common/Select";
4
4
import { useBranding } from "../../../contexts/BrandingContext" ;
5
5
import { ChevronDown , ChevronRight } from "lucide-react" ;
6
6
7
+ /**
8
+ * Maps internal field names to user-friendly display names.
9
+ * Used for:
10
+ * - Input IDs: <Input id="adminConsolePort" />
11
+ * - Labels: <Input label={fieldNames.adminConsolePort} />
12
+ * - Error formatting: formatErrorMessage("adminConsolePort invalid") -> "Admin Console Port invalid"
13
+ */
14
+ const fieldNames = {
15
+ adminConsolePort : "Admin Console Port" ,
16
+ dataDirectory : "Data Directory" ,
17
+ localArtifactMirrorPort : "Local Artifact Mirror Port" ,
18
+ httpProxy : "HTTP Proxy" ,
19
+ httpsProxy : "HTTPS Proxy" ,
20
+ noProxy : "Proxy Bypass List" ,
21
+ networkInterface : "Network Interface" ,
22
+ podCidr : "Pod CIDR" ,
23
+ serviceCidr : "Service CIDR" ,
24
+ globalCidr : "Reserved Network Range (CIDR)" ,
25
+ cidr : "CIDR" ,
26
+ }
27
+
7
28
interface LinuxSetupProps {
8
29
config : {
9
30
dataDirectory ?: string ;
@@ -43,7 +64,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
43
64
44
65
const getFieldError = ( fieldName : string ) => {
45
66
const fieldError = fieldErrors . find ( ( err ) => err . field === fieldName ) ;
46
- return fieldError ? .message ;
67
+ return fieldError ? formatErrorMessage ( fieldError . message ) : undefined ;
47
68
} ;
48
69
49
70
return (
@@ -52,7 +73,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
52
73
< h2 className = "text-lg font-medium text-gray-900" > System Configuration</ h2 >
53
74
< Input
54
75
id = "dataDirectory"
55
- label = "Data Directory"
76
+ label = { fieldNames . dataDirectory }
56
77
value = { config . dataDirectory || "" }
57
78
onChange = { onInputChange }
58
79
placeholder = "/var/lib/embedded-cluster"
@@ -63,7 +84,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
63
84
64
85
< Input
65
86
id = "adminConsolePort"
66
- label = "Admin Console Port"
87
+ label = { fieldNames . adminConsolePort }
67
88
value = { config . adminConsolePort ?. toString ( ) || "" }
68
89
onChange = { onInputChange }
69
90
placeholder = "30000"
@@ -74,7 +95,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
74
95
75
96
< Input
76
97
id = "localArtifactMirrorPort"
77
- label = "Local Artifact Mirror Port"
98
+ label = { fieldNames . localArtifactMirrorPort }
78
99
value = { config . localArtifactMirrorPort ?. toString ( ) || "" }
79
100
onChange = { onInputChange }
80
101
placeholder = "50000"
@@ -89,7 +110,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
89
110
< div className = "space-y-4" >
90
111
< Input
91
112
id = "httpProxy"
92
- label = "HTTP Proxy"
113
+ label = { fieldNames . httpProxy }
93
114
value = { config . httpProxy || "" }
94
115
onChange = { onInputChange }
95
116
placeholder = "http://proxy.example.com:3128"
@@ -99,7 +120,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
99
120
100
121
< Input
101
122
id = "httpsProxy"
102
- label = "HTTPS Proxy"
123
+ label = { fieldNames . httpsProxy }
103
124
value = { config . httpsProxy || "" }
104
125
onChange = { onInputChange }
105
126
placeholder = "https://proxy.example.com:3128"
@@ -109,7 +130,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
109
130
110
131
< Input
111
132
id = "noProxy"
112
- label = "Proxy Bypass List"
133
+ label = { fieldNames . noProxy }
113
134
value = { config . noProxy || "" }
114
135
onChange = { onInputChange }
115
136
placeholder = "localhost,127.0.0.1,.example.com"
@@ -133,7 +154,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
133
154
< div className = "space-y-6" >
134
155
< Select
135
156
id = "networkInterface"
136
- label = "Network Interface"
157
+ label = { fieldNames . networkInterface }
137
158
value = { config . networkInterface || "" }
138
159
onChange = { onSelectChange }
139
160
options = { [
@@ -155,7 +176,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
155
176
156
177
< Input
157
178
id = "globalCidr"
158
- label = "Reserved Network Range (CIDR)"
179
+ label = { fieldNames . globalCidr }
159
180
value = { config . globalCidr || "" }
160
181
onChange = { onInputChange }
161
182
placeholder = "10.244.0.0/16"
@@ -170,4 +191,21 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
170
191
) ;
171
192
} ;
172
193
194
+ /**
195
+ * Formats error messages by replacing technical field names with more user-friendly display names.
196
+ * Example: "adminConsolePort" becomes "Admin Console Port".
197
+ *
198
+ * @param message - The error message to format
199
+ * @returns The formatted error message with replaced field names
200
+ */
201
+ export function formatErrorMessage ( message : string ) {
202
+ let finalMsg = message
203
+ for ( const [ field , fieldName ] of Object . entries ( fieldNames ) ) {
204
+ // Case-insensitive regex that matches whole words only
205
+ // Example: "podCidr", "PodCidr", "PODCIDR" all become "Pod CIDR"
206
+ finalMsg = finalMsg . replace ( new RegExp ( `\\b${ field } \\b` , 'gi' ) , fieldName )
207
+ }
208
+ return finalMsg
209
+ }
210
+
173
211
export default LinuxSetup ;
0 commit comments