cdd-cli 3.1.6 → 3.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.eslintrc.json +1 -1
  2. package/.github/workflows/ci.yml +3 -0
  3. package/.github/workflows/docs.yml +8 -1
  4. package/CHANGELOG.md +23 -0
  5. package/CONTRIBUTING.md +28 -15
  6. package/README.md +56 -88
  7. package/babel.config.cjs +18 -1
  8. package/dist/components/ContainerRow.js +5 -78
  9. package/dist/components/LogViewer.js +4 -9
  10. package/dist/helpers/containerOptionsBuilder.js +58 -0
  11. package/dist/hooks/creation/useContainerCreation.js +16 -1
  12. package/dist/hooks/debug/useDebugLogs.js +46 -0
  13. package/dist/hooks/navigation/useContainerSelection.js +36 -0
  14. package/dist/hooks/useContainerCommandRouter.js +151 -0
  15. package/dist/{helpers/actionHelpers.js → hooks/useContainerStats.js} +76 -78
  16. package/dist/hooks/useControls.js +83 -342
  17. package/dist/hooks/useEraseConfirmation.js +47 -0
  18. package/dist/hooks/useExitHandler.js +68 -0
  19. package/jest.config.cjs +1 -1
  20. package/package.json +4 -5
  21. package/src/components/ContainerRow.jsx +3 -38
  22. package/src/components/LogViewer.jsx +4 -10
  23. package/src/helpers/containerOptionsBuilder.js +42 -0
  24. package/src/hooks/creation/useContainerCreation.js +15 -0
  25. package/src/hooks/debug/useDebugLogs.js +29 -0
  26. package/src/hooks/navigation/useContainerSelection.js +25 -0
  27. package/src/hooks/useContainerCommandRouter.js +110 -0
  28. package/src/hooks/useContainerStats.js +44 -0
  29. package/src/hooks/useControls.js +68 -272
  30. package/src/hooks/useEraseConfirmation.js +39 -0
  31. package/src/hooks/useExitHandler.js +66 -0
  32. package/test/useContainerCreation.dom.test.js +3 -0
  33. package/.babelrc +0 -6
  34. package/FIXES_APPLIED.md +0 -419
  35. package/SECURITY.md +0 -5
  36. package/dist/hooks/useLogsStream.js +0 -41
  37. package/docs/_config.yml +0 -13
  38. package/docs/components_ContainerCreationPrompt.jsx.html +0 -114
  39. package/docs/components_ContainerRow.jsx.html +0 -151
  40. package/docs/components_ContainerSection.jsx.html +0 -75
  41. package/docs/components_Footer.jsx.html +0 -66
  42. package/docs/components_Header.jsx.html +0 -84
  43. package/docs/components_LogViewer.jsx.html +0 -91
  44. package/docs/components_MessageFeedback.jsx.html +0 -76
  45. package/docs/components_PromptField.jsx.html +0 -99
  46. package/docs/components_StatsBar.jsx.html +0 -105
  47. package/docs/components_UsageMenu.jsx.html +0 -73
  48. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  49. package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
  50. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  51. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  52. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  53. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  54. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  55. package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
  56. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  57. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  58. package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
  59. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  60. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  61. package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  62. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  63. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  64. package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
  65. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  66. package/docs/global.html +0 -6145
  67. package/docs/helpers_actionHelpers.js.html +0 -94
  68. package/docs/helpers_constants.js.html +0 -81
  69. package/docs/helpers_dockerService_dockerService.js.html +0 -79
  70. package/docs/helpers_dockerService_serviceComponents_containerActions.js.html +0 -153
  71. package/docs/helpers_dockerService_serviceComponents_containerList.js.html +0 -81
  72. package/docs/helpers_dockerService_serviceComponents_containerLogs.js.html +0 -85
  73. package/docs/helpers_dockerService_serviceComponents_containerStats.js.html +0 -107
  74. package/docs/helpers_dockerService_serviceComponents_imageUtils.js.html +0 -82
  75. package/docs/helpers_exitWithMessage.js.html +0 -77
  76. package/docs/helpers_safeCall.js.html +0 -68
  77. package/docs/helpers_validationHelpers.js.html +0 -96
  78. package/docs/hooks_creation_useContainerActions.js.html +0 -120
  79. package/docs/hooks_creation_useContainerCreation.js.html +0 -152
  80. package/docs/hooks_creation_useLogsViewer.js.html +0 -102
  81. package/docs/hooks_useControls.js.html +0 -298
  82. package/docs/hooks_useLogsStream.js.html +0 -82
  83. package/docs/index.html +0 -65
  84. package/docs/index.js.html +0 -65
  85. package/docs/module-index.html +0 -171
  86. package/docs/scripts/linenumber.js +0 -25
  87. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  88. package/docs/scripts/prettify/lang-css.js +0 -2
  89. package/docs/scripts/prettify/prettify.js +0 -28
  90. package/docs/styles/jsdoc-default.css +0 -358
  91. package/docs/styles/prettify-jsdoc.css +0 -111
  92. package/docs/styles/prettify-tomorrow.css +0 -132
  93. package/esbuild.config.cjs +0 -11
  94. package/src/helpers/actionHelpers.js +0 -52
  95. package/src/hooks/useLogsStream.js +0 -31
  96. package/test/actionHelpers.test.js +0 -106
package/FIXES_APPLIED.md DELETED
@@ -1,419 +0,0 @@
1
- # Applied Fixes - CDD CLI
2
-
3
- **Date:** 2025-10-17
4
- **Project:** CDD-CLI (CLI Docker Dashboard)
5
-
6
- ---
7
-
8
- ## Fixes Summary
9
-
10
- A total of 11 critical fixes were applied to address security, stability, and portability issues identified during the code audit.
11
-
12
- ---
13
-
14
- ## 1. APPLIED CRITICAL FIXES
15
-
16
- ### ✅ 1.1. Import Order Fix
17
-
18
- **File:** `src/helpers/dockerService/serviceComponents/containerActions.js`
19
-
20
- **Issue:** Imports were declared after exports.
21
-
22
- **Applied fix:**
23
- ```javascript
24
- // BEFORE (incorrect):
25
- export async function removeContainer(containerId) { ... }
26
- import { docker } from "../dockerService";
27
-
28
- // AFTER (correct):
29
- import { docker } from "../dockerService";
30
- import { imageExists, pullImage } from "./imageUtils.js";
31
- export async function removeContainer(containerId) { ... }
32
- ```
33
-
34
- **Impact:** Removes potential reference errors and follows ES6 standards.
35
-
36
- ---
37
-
38
- ### ✅ 1.2. Optional Ports in Container Creation
39
-
40
- **File:** `src/hooks/creation/useContainerCreation.js`
41
-
42
- **Issue:** Users were forced to specify ports, but many containers don’t need them.
43
-
44
- **Applied fix:**
45
- ```javascript
46
- // BEFORE:
47
- if (!portInput.trim()) {
48
- setMessage("You must specify at least one port to expose");
49
- return;
50
- }
51
-
52
- // AFTER:
53
- // Ports are optional — only validate if provided
54
- if (portInput.trim() && !validatePorts(portInput)) {
55
- setMessage("Port format must be host:container...");
56
- return;
57
- }
58
- ```
59
-
60
- **Impact:** Allows creating containers without exposed ports (workers, internal services, etc.).
61
-
62
- ---
63
-
64
- ### ✅ 1.3. Error Handling in getLogsStream
65
-
66
- **File:** `src/helpers/dockerService/serviceComponents/containerLogs.js`
67
-
68
- **Issue:** No try-catch to handle synchronous exceptions.
69
-
70
- **Applied fix:**
71
- ```javascript
72
- export function getLogsStream(containerId, onData, onEnd, onError) {
73
- try {
74
- const container = docker.getContainer(containerId);
75
- // ... rest of the code
76
- } catch (err) {
77
- onError?.(err);
78
- }
79
- }
80
- ```
81
-
82
- **Impact:** Prevents crashes when the container doesn’t exist or connection errors occur.
83
-
84
- ---
85
-
86
- ### ✅ 1.4. Cross-Platform Docker Socket Configuration
87
-
88
- **File:** `src/helpers/dockerService/dockerService.js`
89
-
90
- **Issue:** Hardcoded path `/var/run/docker.sock` only works on Linux/macOS.
91
-
92
- **Applied fix:**
93
- ```javascript
94
- // BEFORE:
95
- const docker = new Docker({ socketPath: "/var/run/docker.sock" });
96
-
97
- // AFTER:
98
- // Use default configuration that automatically handles:
99
- // - /var/run/docker.sock on Linux/macOS
100
- // - //./pipe/docker_engine on Windows
101
- const docker = new Docker();
102
- ```
103
-
104
- **Impact:** Works on Windows, Linux, and macOS without manual changes.
105
-
106
- ---
107
-
108
- ### ✅ 1.5. Race Condition Prevention in Stats
109
-
110
- **File:** `src/components/ContainerRow.jsx`
111
-
112
- **Issue:** State updates on unmounted components caused memory leaks.
113
-
114
- **Applied fix:**
115
- ```javascript
116
- useEffect(() => {
117
- if (state !== "running") return;
118
-
119
- let isMounted = true; // ← Mount flag
120
-
121
- const fetchStats = async () => {
122
- try {
123
- const s = await getStats(id);
124
- if (isMounted) { // ← Only update if mounted
125
- setStats(s);
126
- }
127
- } catch (err) {
128
- if (isMounted) {
129
- setStatsError("Error fetching stats");
130
- }
131
- }
132
- };
133
-
134
- fetchStats();
135
- const timer = setInterval(fetchStats, 1500);
136
-
137
- return () => {
138
- isMounted = false; // ← Cleanup
139
- clearInterval(timer);
140
- };
141
- }, [id, state]);
142
- ```
143
-
144
- **Impact:** Eliminates React warnings and prevents memory leaks.
145
-
146
- ---
147
-
148
- ### ✅ 1.6. Environment Variables Validation
149
-
150
- **File:** `src/helpers/validationHelpers.js`
151
-
152
- **Issue:** `validateEnvVars` always returned `true`.
153
-
154
- **Applied fix:**
155
- ```javascript
156
- export function validateEnvVars(envInput) {
157
- if (!envInput || !envInput.trim()) return true; // Empty is valid
158
-
159
- const vars = envInput.split(",").map(v => v.trim()).filter(Boolean);
160
- const invalid = vars.find(v => {
161
- const parts = v.split("=");
162
- if (parts.length < 2) return true; // Must be VAR=value
163
- const varName = parts[0].trim();
164
- // Names must be alphanumeric with underscores
165
- if (!/^[A-Z_][A-Z0-9_]*$/i.test(varName)) return true;
166
- return false;
167
- });
168
-
169
- return !invalid;
170
- }
171
- ```
172
-
173
- **Impact:** Detects malformed variables before sending them to Docker.
174
-
175
- ---
176
-
177
- ### ✅ 1.7. CPU Stats Calculation Fix
178
-
179
- **File:** `src/helpers/dockerService/serviceComponents/containerStats.js`
180
-
181
- **Issue:** Not normalized by number of CPUs, producing wrong values on multi-core hosts.
182
-
183
- **Applied fix:**
184
- ```javascript
185
- // Determine number of CPUs
186
- const numCpus = stream.cpu_stats.online_cpus ||
187
- stream.cpu_stats.cpu_usage.percpu_usage?.length || 1;
188
-
189
- // Compute normalized percentage
190
- const cpuPercent = systemDelta > 0
191
- ? ((cpuDelta / systemDelta) * numCpus * 100)
192
- : 0;
193
- ```
194
-
195
- **Impact:** Correct CPU stats on multi-core systems.
196
-
197
- ---
198
-
199
- ### ✅ 1.8. Timeouts in Docker Operations
200
-
201
- **File:** `src/helpers/dockerService/serviceComponents/containerActions.js`
202
-
203
- **Issue:** Operations without timeouts could freeze the UI indefinitely.
204
-
205
- **Applied fix:**
206
- ```javascript
207
- function withTimeout(promise, ms = 30000) {
208
- return Promise.race([
209
- promise,
210
- new Promise((_, reject) =>
211
- setTimeout(() => reject(new Error('Operation timed out')), ms)
212
- )
213
- ]);
214
- }
215
-
216
- export async function startContainer(containerId) {
217
- const container = docker.getContainer(containerId);
218
- await withTimeout(container.start(), 30000);
219
- }
220
- ```
221
-
222
- **Impact:** Prevents frozen UI during long or failing operations.
223
-
224
- ---
225
-
226
- ### ✅ 1.9. In-Memory Log Limit
227
-
228
- **File:** `src/hooks/useControls.js`
229
-
230
- **Issue:** Logs accumulated indefinitely causing a memory leak.
231
-
232
- **Applied fix:**
233
- ```javascript
234
- getLogsStream(
235
- containers[selected].id,
236
- (data) => logsViewer.setLogs((prev) => {
237
- const newLogs = [...prev, ...data.split("\n").filter(Boolean)];
238
- // Limit to last 1000 lines
239
- return newLogs.slice(-1000);
240
- }),
241
- // ...
242
- );
243
- ```
244
-
245
- **Impact:** Prevents memory leaks on long-running log streams.
246
-
247
- ---
248
-
249
- ### ✅ 1.10. Duplicate Message Fix
250
-
251
- **File:** `src/helpers/actionHelpers.js`
252
-
253
- **Issue:** Success message was identical to the start message.
254
-
255
- **Applied fix:**
256
- ```javascript
257
- // BEFORE:
258
- setMessage(`${actionLabel} container...`); // start
259
- await actionFn(c.id);
260
- setMessage(`${actionLabel} container...`); // success (duplicate)
261
-
262
- // AFTER:
263
- setMessage(`${actionLabel} container...`); // start
264
- await actionFn(c.id);
265
- setMessage(`${actionLabel} container completed successfully`); // success
266
- ```
267
-
268
- **Impact:** Clear feedback that the operation completed.
269
-
270
- ---
271
-
272
- ### ✅ 1.11. Container Names Validation
273
-
274
- **File:** `src/helpers/dockerService/serviceComponents/containerList.js`
275
-
276
- **Issue:** Didn’t validate when `Names` was empty.
277
-
278
- **Applied fix:**
279
- ```javascript
280
- // BEFORE:
281
- name: container.Names[0].replace("/", ""),
282
-
283
- // AFTER:
284
- name: (container.Names && container.Names[0] || 'Unknown').replace("/", ""),
285
- ```
286
-
287
- **Impact:** Prevents crashes when Docker returns unexpected data.
288
-
289
- ---
290
-
291
- ## 2. TEST IMPROVEMENTS
292
-
293
- ### ✅ Tests for validateEnvVars
294
-
295
- **File:** `test/validationHelpers.test.js`
296
-
297
- **New tests added:**
298
- - Empty input is valid
299
- - Valid single env var
300
- - Valid multiple env vars
301
- - Valid env var with underscores
302
- - Invalid env var without equals sign
303
- - Invalid env var with invalid name
304
- - Invalid env var with special characters in name
305
-
306
- **Result:**
307
- ```
308
- Test Suites: 1 passed, 1 total
309
- Tests: 12 passed, 12 total (previously: 5)
310
- ```
311
-
312
- ---
313
-
314
- ## 3. SECURITY ANALYSIS
315
-
316
- ### ✅ CodeQL Security Scan
317
-
318
- **Result:** ✅ 0 vulnerabilities found
319
-
320
- ```
321
- Analysis Result for 'javascript'. Found 0 alert(s):
322
- - javascript: No alerts found.
323
- ```
324
-
325
- ---
326
-
327
- ## 4. BUILD VERIFICATION
328
-
329
- ### ✅ Successful Build
330
-
331
- ```bash
332
- $ npm run build
333
- Successfully compiled 28 files with Babel (815ms).
334
- ```
335
-
336
- ---
337
-
338
- ## 5. OVERALL IMPACT OF FIXES
339
-
340
- ### Security
341
- - ✅ No security vulnerabilities detected
342
- - ✅ Improved input validation
343
- - ✅ Robust error handling
344
-
345
- ### Stability
346
- - ✅ Memory leak prevention
347
- - ✅ Race condition prevention
348
- - ✅ Crash prevention due to unhandled errors
349
- - ✅ Timeouts for potentially long operations
350
-
351
- ### Portability
352
- - ✅ Windows compatibility
353
- - ✅ Linux compatibility
354
- - ✅ macOS compatibility
355
-
356
- ### User Experience
357
- - ✅ Optional ports in container creation
358
- - ✅ Clearer feedback messages
359
- - ✅ Correct CPU statistics
360
- - ✅ Better error handling with informative messages
361
-
362
- ### Code Quality
363
- - ✅ ES6 compliant
364
- - ✅ Better test coverage (5 → 12 tests)
365
- - ✅ More maintainable code
366
-
367
- ---
368
-
369
- ## 6. MODIFIED FILES
370
-
371
- 1. `src/helpers/dockerService/serviceComponents/containerActions.js`
372
- 2. `src/hooks/creation/useContainerCreation.js`
373
- 3. `src/helpers/dockerService/serviceComponents/containerLogs.js`
374
- 4. `src/helpers/dockerService/dockerService.js`
375
- 5. `src/components/ContainerRow.jsx`
376
- 6. `src/helpers/validationHelpers.js`
377
- 7. `src/helpers/dockerService/serviceComponents/containerStats.js`
378
- 8. `src/hooks/useControls.js`
379
- 9. `src/helpers/actionHelpers.js`
380
- 10. `src/helpers/dockerService/serviceComponents/containerList.js`
381
- 11. `test/validationHelpers.test.js`
382
-
383
- ---
384
-
385
- ## 7. FUTURE RECOMMENDATIONS
386
-
387
- While the critical issues have been addressed, the internal audit yielded additional recommendations for future improvements:
388
-
389
- ### Medium Priority
390
- - Add more unit tests
391
- - Implement PropTypes or migrate to TypeScript
392
- - Extract magic numbers into constants
393
- - Improve the logging system
394
-
395
- ### Low Priority
396
- - Implement i18n (internationalization)
397
- - Improve JSDoc documentation
398
- - Consider websockets for real-time updates
399
- - Implement retry logic for Docker reconnection
400
-
401
- ---
402
-
403
- ## 8. CONCLUSION
404
-
405
- We applied 11 critical fixes that significantly improve:
406
-
407
- - Security: 0 vulnerabilities
408
- - Stability: Prevention of memory leaks and race conditions
409
- - Portability: Works on Windows, Linux, and macOS
410
- - Quality: +140% more tests (5 → 12)
411
-
412
- All fixes have been tested and verified via:
413
- - ✅ Unit tests (12/12 passing)
414
- - ✅ Successful build
415
- - ✅ CodeQL security analysis (0 alerts)
416
-
417
- ---
418
-
419
- **End of fixes document**
package/SECURITY.md DELETED
@@ -1,5 +0,0 @@
1
- # Security
2
-
3
- If you discover a security vulnerability, please report it privately to the repository owner.
4
-
5
- Do not disclose vulnerabilities publicly until they are resolved.
@@ -1,41 +0,0 @@
1
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
2
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
5
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
6
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
7
- import React, { useRef, useCallback } from "react";
8
- import { getLogsStream } from "../helpers/dockerService/serviceComponents/containerLogs.js";
9
- import { safeCall } from "../helpers/safeCall.js";
10
-
11
- /**
12
- * Hook that manages opening and closing a logs stream for a container.
13
- *
14
- * @returns {Object} { openLogs, closeLogs }
15
- */
16
- export function useLogsStream() {
17
- var logsStreamRef = useRef(null);
18
- var openLogs = useCallback(function (containerId, setLogs) {
19
- setLogs([]);
20
- logsStreamRef.current = getLogsStream(containerId, function (data) {
21
- return setLogs(function (prev) {
22
- return [].concat(_toConsumableArray(prev), _toConsumableArray(data.split("\n").filter(Boolean)));
23
- });
24
- }, function () {}, function (err) {
25
- return setLogs(function (prev) {
26
- return [].concat(_toConsumableArray(prev), ["Error: ".concat(err.message)]);
27
- });
28
- });
29
- }, []);
30
- var closeLogs = useCallback(function () {
31
- if (logsStreamRef.current) {
32
- var _logsStreamRef$curren;
33
- safeCall((_logsStreamRef$curren = logsStreamRef.current.destroy) === null || _logsStreamRef$curren === void 0 ? void 0 : _logsStreamRef$curren.bind(logsStreamRef.current));
34
- logsStreamRef.current = null;
35
- }
36
- }, []);
37
- return {
38
- openLogs: openLogs,
39
- closeLogs: closeLogs
40
- };
41
- }
package/docs/_config.yml DELETED
@@ -1,13 +0,0 @@
1
- title: CDD Documentation
2
- # Disable the default GitHub Pages theme so Jekyll just copies our static output
3
- # (the static HTML is generated by JSDoc and already styled).
4
- theme: null
5
-
6
- # Explicitly include asset folders that Jekyll might otherwise ignore.
7
- include:
8
- - fonts
9
- - scripts
10
- - styles
11
-
12
- # No Jekyll plugins are required for this pre-rendered site.
13
- plugins: []
@@ -1,114 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>JSDoc: Source: components/ContainerCreationPrompt.jsx</title>
6
-
7
- <script src="scripts/prettify/prettify.js"> </script>
8
- <script src="scripts/prettify/lang-css.js"> </script>
9
- <!--[if lt IE 9]>
10
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11
- <![endif]-->
12
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14
- </head>
15
-
16
- <body>
17
-
18
- <div id="main">
19
-
20
- <h1 class="page-title">Source: components/ContainerCreationPrompt.jsx</h1>
21
-
22
-
23
-
24
-
25
-
26
-
27
- <section>
28
- <article>
29
- <pre class="prettyprint source linenums"><code>import React from "react";
30
- import { Box, Text } from "ink";
31
- import { PromptField, PromptMessage } from "./PromptField.jsx";
32
- import PropTypes from 'prop-types';
33
-
34
- /**
35
- * Prompt UI shown when creating a new container.
36
- * Presents a step-by-step form (image, name, ports, env) and displays
37
- * a contextual message provided by the creation hook.
38
- *
39
- * @param {Object} props
40
- * @param {number} props.step - Current step index (0..3)
41
- * @param {string} props.imageName - Value for the image name field
42
- * @param {string} props.containerName - Value for the container name field
43
- * @param {string} props.portInput - Value for the ports input field
44
- * @param {string} props.envInput - Value for the environment variables field
45
- * @param {string} props.message - Contextual message to display (errors/hints)
46
- * @param {string} props.messageColor - Color for the contextual message
47
- * @returns {JSX.Element}
48
- */
49
- export default function ContainerCreationPrompt(props) {
50
- const { step, imageName, containerName, portInput, envInput, message, messageColor } = props;
51
- const prompts = [
52
- {
53
- label: "Name of the image to create (e.g., nginx:latest):",
54
- value: imageName,
55
- required: true,
56
- },
57
- {
58
- label: "Name of the container (optional):",
59
- value: containerName,
60
- required: false,
61
- },
62
- {
63
- label: "Ports (optional, format 8080:80,443:443):",
64
- value: portInput,
65
- required: false,
66
- },
67
- {
68
- label: "Environment variables (optional, format VAR1=val1,VAR2=val2):",
69
- value: envInput,
70
- required: false,
71
- },
72
- ];
73
- const { label, value, required } = prompts[step] || {};
74
- return (
75
- &lt;Box flexDirection="column" borderStyle="round" borderColor="yellow" padding={1}>
76
- &lt;PromptField label={label} value={value} required={required} />
77
- &lt;PromptMessage message={message} color={messageColor} />
78
- &lt;Text dimColor>Press Enter to continue, Escape to cancel&lt;/Text>
79
- &lt;/Box>
80
- );
81
- }
82
-
83
- ContainerCreationPrompt.propTypes = {
84
- step: PropTypes.number.isRequired,
85
- imageName: PropTypes.string,
86
- containerName: PropTypes.string,
87
- portInput: PropTypes.string,
88
- envInput: PropTypes.string,
89
- message: PropTypes.string,
90
- messageColor: PropTypes.string,
91
- };
92
- </code></pre>
93
- </article>
94
- </section>
95
-
96
-
97
-
98
-
99
- </div>
100
-
101
- <nav>
102
- <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-index.html">index</a></li></ul><h3>Global</h3><ul><li><a href="global.html#EXIT_DELAY">EXIT_DELAY</a></li><li><a href="global.html#MESSAGE_TIMEOUTS">MESSAGE_TIMEOUTS</a></li><li><a href="global.html#PromptField">PromptField</a></li><li><a href="global.html#PromptMessage">PromptMessage</a></li><li><a href="global.html#REFRESH_INTERVALS">REFRESH_INTERVALS</a></li><li><a href="global.html#TIMEOUTS">TIMEOUTS</a></li><li><a href="global.html#colorize">colorize</a></li><li><a href="global.html#createContainer">createContainer</a></li><li><a href="global.html#docker">docker</a></li><li><a href="global.html#exitWithMessage">exitWithMessage</a></li><li><a href="global.html#getContainers">getContainers</a></li><li><a href="global.html#getLogsStream">getLogsStream</a></li><li><a href="global.html#getStats">getStats</a></li><li><a href="global.html#handleAction">handleAction</a></li><li><a href="global.html#imageExists">imageExists</a></li><li><a href="global.html#makeBar">makeBar</a></li><li><a href="global.html#pullImage">pullImage</a></li><li><a href="global.html#removeContainer">removeContainer</a></li><li><a href="global.html#restartContainer">restartContainer</a></li><li><a href="global.html#safeCall">safeCall</a></li><li><a href="global.html#startContainer">startContainer</a></li><li><a href="global.html#stopContainer">stopContainer</a></li><li><a href="global.html#useContainerActions">useContainerActions</a></li><li><a href="global.html#useContainerCreation">useContainerCreation</a></li><li><a href="global.html#useControls">useControls</a></li><li><a href="global.html#useLogsStream">useLogsStream</a></li><li><a href="global.html#useLogsViewer">useLogsViewer</a></li><li><a href="global.html#validateEnvVars">validateEnvVars</a></li><li><a href="global.html#validatePorts">validatePorts</a></li><li><a href="global.html#withTimeout">withTimeout</a></li></ul>
103
- </nav>
104
-
105
- <br class="clear">
106
-
107
- <footer>
108
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Fri Oct 17 2025 16:07:18 GMT-0500 (hora estándar de Colombia)
109
- </footer>
110
-
111
- <script> prettyPrint(); </script>
112
- <script src="scripts/linenumber.js"> </script>
113
- </body>
114
- </html>