@@ -4,6 +4,27 @@ import Select from "../../common/Select";
44import { useBranding } from "../../../contexts/BrandingContext" ;
55import { ChevronDown , ChevronRight } from "lucide-react" ;
66
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+
728interface LinuxSetupProps {
829 config : {
930 dataDirectory ?: string ;
@@ -43,7 +64,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
4364
4465 const getFieldError = ( fieldName : string ) => {
4566 const fieldError = fieldErrors . find ( ( err ) => err . field === fieldName ) ;
46- return fieldError ? .message ;
67+ return fieldError ? formatErrorMessage ( fieldError . message ) : undefined ;
4768 } ;
4869
4970 return (
@@ -52,7 +73,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
5273 < h2 className = "text-lg font-medium text-gray-900" > System Configuration</ h2 >
5374 < Input
5475 id = "dataDirectory"
55- label = "Data Directory"
76+ label = { fieldNames . dataDirectory }
5677 value = { config . dataDirectory || "" }
5778 onChange = { onInputChange }
5879 placeholder = "/var/lib/embedded-cluster"
@@ -63,7 +84,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
6384
6485 < Input
6586 id = "adminConsolePort"
66- label = "Admin Console Port"
87+ label = { fieldNames . adminConsolePort }
6788 value = { config . adminConsolePort ?. toString ( ) || "" }
6889 onChange = { onInputChange }
6990 placeholder = "30000"
@@ -74,7 +95,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
7495
7596 < Input
7697 id = "localArtifactMirrorPort"
77- label = "Local Artifact Mirror Port"
98+ label = { fieldNames . localArtifactMirrorPort }
7899 value = { config . localArtifactMirrorPort ?. toString ( ) || "" }
79100 onChange = { onInputChange }
80101 placeholder = "50000"
@@ -89,7 +110,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
89110 < div className = "space-y-4" >
90111 < Input
91112 id = "httpProxy"
92- label = "HTTP Proxy"
113+ label = { fieldNames . httpProxy }
93114 value = { config . httpProxy || "" }
94115 onChange = { onInputChange }
95116 placeholder = "http://proxy.example.com:3128"
@@ -99,7 +120,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
99120
100121 < Input
101122 id = "httpsProxy"
102- label = "HTTPS Proxy"
123+ label = { fieldNames . httpsProxy }
103124 value = { config . httpsProxy || "" }
104125 onChange = { onInputChange }
105126 placeholder = "https://proxy.example.com:3128"
@@ -109,7 +130,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
109130
110131 < Input
111132 id = "noProxy"
112- label = "Proxy Bypass List"
133+ label = { fieldNames . noProxy }
113134 value = { config . noProxy || "" }
114135 onChange = { onInputChange }
115136 placeholder = "localhost,127.0.0.1,.example.com"
@@ -133,7 +154,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
133154 < div className = "space-y-6" >
134155 < Select
135156 id = "networkInterface"
136- label = "Network Interface"
157+ label = { fieldNames . networkInterface }
137158 value = { config . networkInterface || "" }
138159 onChange = { onSelectChange }
139160 options = { [
@@ -155,7 +176,7 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
155176
156177 < Input
157178 id = "globalCidr"
158- label = "Reserved Network Range (CIDR)"
179+ label = { fieldNames . globalCidr }
159180 value = { config . globalCidr || "" }
160181 onChange = { onInputChange }
161182 placeholder = "10.244.0.0/16"
@@ -170,4 +191,21 @@ const LinuxSetup: React.FC<LinuxSetupProps> = ({
170191 ) ;
171192} ;
172193
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+
173211export default LinuxSetup ;
0 commit comments