Skip to content

Commit cc738c5

Browse files
committed
fix: padding issue in progress bar UX
1 parent 3978d53 commit cc738c5

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

packages/contentstack-utilities/src/progress-summary/cli-progress-manager.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ export default class CLIProgressManager {
170170
this.callbacks = { ...this.callbacks, ...callbacks };
171171
}
172172

173+
/**
174+
* Convert module name from UPPERCASE to PascalCase
175+
*/
176+
private formatModuleName(name: string): string {
177+
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
178+
}
179+
173180
private initializeProgress(): void {
174181
if (this.showConsoleLogs) {
175182
return;
@@ -202,8 +209,10 @@ export default class CLIProgressManager {
202209
barIncompleteChar: '\u2591',
203210
hideCursor: true,
204211
});
212+
const formattedName = this.formatModuleName(this.moduleName);
213+
const displayName = formattedName.length > 20 ? formattedName.substring(0, 17) + '...' : formattedName;
205214
this.progressBar.start(this.total, 0, {
206-
label: chalk.gray(` └─ ${this.moduleName}`.padEnd(18)),
215+
label: chalk.gray(` └─ ${displayName}`.padEnd(25)),
207216
status: chalk.gray('Starting...'),
208217
percentage: '0',
209218
});
@@ -229,7 +238,8 @@ export default class CLIProgressManager {
229238
};
230239

231240
if (!this.showConsoleLogs) {
232-
const indentedLabel = ` ├─ ${processName}`.padEnd(18);
241+
const truncatedName = processName.length > 20 ? processName.substring(0, 17) + '...' : processName;
242+
const indentedLabel = ` ├─ ${truncatedName}`.padEnd(25);
233243
process.progressBar = this.multiBar.create(total, 0, {
234244
label: chalk.gray(indentedLabel),
235245
status: chalk.gray('Pending'),
@@ -251,10 +261,11 @@ export default class CLIProgressManager {
251261
if (process) {
252262
process.status = 'active';
253263
if (!this.showConsoleLogs && process.progressBar) {
254-
const indentedLabel = ` ├─ ${processName}`.padEnd(18);
264+
const truncatedName = processName.length > 20 ? processName.substring(0, 17) + '...' : processName;
265+
const indentedLabel = ` ├─ ${truncatedName}`.padEnd(25);
255266
process.progressBar.update(0, {
256267
label: chalk.yellow(indentedLabel),
257-
status: chalk.yellow(this.moduleName),
268+
status: chalk.yellow('Processing'),
258269
percentage: '0',
259270
});
260271
}
@@ -277,7 +288,8 @@ export default class CLIProgressManager {
277288
const statusText = success
278289
? chalk.green(`✓ Complete (${process.successCount}/${process.current})`)
279290
: chalk.red(`✗ Failed (${process.successCount}/${process.current})`);
280-
const indentedLabel = ` ├─ ${processName}`.padEnd(18);
291+
const truncatedName = processName.length > 20 ? processName.substring(0, 17) + '...' : processName;
292+
const indentedLabel = ` ├─ ${truncatedName}`.padEnd(25);
281293
process.progressBar.update(process.total, {
282294
label: success ? chalk.green(indentedLabel) : chalk.red(indentedLabel),
283295
status: statusText,
@@ -297,7 +309,8 @@ export default class CLIProgressManager {
297309
const process = this.processes.get(processName);
298310
if (process && process.progressBar) {
299311
const percentage = Math.round((process.current / process.total) * 100);
300-
const indentedLabel = ` ├─ ${processName}`.padEnd(18);
312+
const truncatedName = processName.length > 20 ? processName.substring(0, 17) + '...' : processName;
313+
const indentedLabel = ` ├─ ${truncatedName}`.padEnd(25);
301314
process.progressBar.update(process.current, {
302315
label: chalk.yellow(indentedLabel),
303316
status: chalk.yellow(message),
@@ -306,8 +319,10 @@ export default class CLIProgressManager {
306319
}
307320
} else if (this.progressBar) {
308321
const percentage = Math.round(this.progressBar.getProgress() * 100);
322+
const formattedName = this.formatModuleName(this.moduleName);
323+
const displayName = formattedName.length > 20 ? formattedName.substring(0, 17) + '...' : formattedName;
309324
this.progressBar.update(this.progressBar.getProgress() * this.total, {
310-
label: chalk.yellow(` └─ ${this.moduleName}`.padEnd(18)),
325+
label: chalk.yellow(` └─ ${displayName}`.padEnd(25)),
311326
status: chalk.yellow(message),
312327
percentage: percentage.toString(),
313328
});
@@ -355,7 +370,8 @@ export default class CLIProgressManager {
355370
const percentage = Math.round((process.current / process.total) * 100);
356371
const statusText = `${process.successCount}${process.failureCount}✗`;
357372

358-
const indentedLabel = ` ├─ ${targetProcess}`.padEnd(18);
373+
const truncatedName = targetProcess.length > 20 ? targetProcess.substring(0, 17) + '...' : targetProcess;
374+
const indentedLabel = ` ├─ ${truncatedName}`.padEnd(25);
359375
process.progressBar.increment(1, {
360376
label: chalk.cyan(indentedLabel),
361377
status: chalk.cyan(statusText),
@@ -381,8 +397,10 @@ export default class CLIProgressManager {
381397
const labelColor =
382398
totalProcessed >= this.total ? (this.failureCount === 0 ? chalk.green : chalk.yellow) : chalk.cyan;
383399

400+
const formattedName = this.formatModuleName(this.moduleName);
401+
const displayName = formattedName.length > 20 ? formattedName.substring(0, 17) + '...' : formattedName;
384402
this.progressBar.increment(1, {
385-
label: labelColor(` └─ ${this.moduleName}`.padEnd(18)),
403+
label: labelColor(` └─ ${displayName}`.padEnd(25)),
386404
status: statusText,
387405
percentage: percentage.toString(),
388406
});

0 commit comments

Comments
 (0)