refactor: extract ModalValidator from ExportConfigModal

Extract validation orchestration logic into dedicated ModalValidator class
as part of Phase 4 modal refactoring to improve maintainability.

Changes:
- Create src/ui/modal/ModalValidator.ts with validateAllSections() method
- Remove validateAllSections() method from ExportConfigModal.ts
- Update ExportConfigModal to delegate validation to ModalValidator
- Fix TypeScript handling of optional warnings property
- Maintain exact same validation behavior and error handling

Build: ✅ npm run build passes
Size: ExportConfigModal.ts reduced by ~20 lines

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jarvis committed 2025-09-10 12:37:24 +02:00
1 parent 41e70e389e
commit 53dd1b5903
2 files changed
+48 -22

No files matched your search

+7 -22
View File
@@ -13,6 +13,7 @@ import { PageSetupSection } from './sections/PageSetupSection';
import { BehaviorSection } from './sections/BehaviorSection';
import { TemplateManager } from '../../templates/TemplateManager';
import { ModalRenderer, ModalRendererCallbacks } from './ModalRenderer';
import { ModalValidator } from './ModalValidator';
export class ExportConfigModal extends Modal {
plugin: obsidianTypstPDFExport;
@@ -21,6 +22,7 @@ export class ExportConfigModal extends Modal {
private onSubmit: (config: ExportConfig) => void;
private onCancel?: () => void;
private renderer: ModalRenderer;
private validator: ModalValidator;
constructor(
app: App,
@@ -48,6 +50,9 @@ export class ExportConfigModal extends Modal {
};
this.renderer = new ModalRenderer(this.state, this.sections, callbacks, this.app);
// Initialize validator
this.validator = new ModalValidator();
// Listen for state changes
this.state.onChange(() => this.handleStateChange());
}
@@ -143,7 +148,7 @@ export class ExportConfigModal extends Modal {
private async handleSubmit(): Promise<void> {
// Validate all sections
const validationResults = this.validateAllSections();
const validationResults = this.validator.validateAllSections(Array.from(this.sections.values()));
if (!validationResults.isValid) {
this.showValidationErrors(validationResults.errors);
@@ -151,7 +156,7 @@ export class ExportConfigModal extends Modal {
}
// Show any warnings
if (validationResults.warnings.length > 0) {
if (validationResults.warnings && validationResults.warnings.length > 0) {
this.showValidationWarnings(validationResults.warnings);
}
@@ -193,26 +198,6 @@ export class ExportConfigModal extends Modal {
}
}
private validateAllSections(): { isValid: boolean; errors: string[]; warnings: string[] } {
const errors: string[] = [];
const warnings: string[] = [];
this.sections.forEach(section => {
if (section.validate) {
const result = section.validate();
errors.push(...result.errors);
if (result.warnings) {
warnings.push(...result.warnings);
}
}
});
return {
isValid: errors.length === 0,
errors,
warnings
};
}
private showValidationErrors(errors: string[]): void {
this.renderer.showValidationErrors(errors);
+41
View File
@@ -0,0 +1,41 @@
/**
* Modal validation orchestration
*
* This class handles validation logic for the export configuration modal,
* coordinating validation across all modal sections.
*/
import { ModalSection, ValidationResult } from './modalTypes';
/**
* Handles validation orchestration for modal sections
*/
export class ModalValidator {
/**
* Validates all sections and aggregates the results
*
* @param sections - Array of modal sections to validate
* @returns ValidationResult with aggregated errors and warnings
*/
public validateAllSections(sections: ModalSection[]): ValidationResult {
const errors: string[] = [];
const warnings: string[] = [];
sections.forEach(section => {
if (section.validate) {
const result = section.validate();
errors.push(...result.errors);
if (result.warnings) {
warnings.push(...result.warnings);
}
}
});
return {
isValid: errors.length === 0,
errors,
warnings
};
}
}