Appearance
Form System Refactoring Plan
Overview
This document outlines a comprehensive refactoring plan for the form system in both Application-Frontend and Creative-Engine. The goal is to improve maintainability, reduce code duplication, and enhance type safety by creating dedicated components for each input type.
Current Architecture Analysis
Current Structure
- Single Component:
FormInputConfiguration.vuehandles all input types (331 lines) - Template Conditionals: Uses
v-ifstatements to show type-specific validation sections - Mixed Concerns: Combines common styling, layout, and type-specific validation in one file
- Centralized Logic: All input type handling in one component with complex conditional rendering
Issues Identified
- Large Component Size: 331 lines with growing complexity
- Template Complexity: Multiple nested
v-ifconditions for different input types - Maintenance Overhead: Adding new input types requires modifying the main component
- Code Duplication: Similar validation patterns repeated across input types
- Testing Complexity: Difficult to test individual input type configurations in isolation
Refactoring Strategy
Component Architecture
FormInputConfiguration.vue (Main Container)
├── BaseInputConfiguration.vue (Shared functionality)
├── TextInputConfiguration.vue (Text-specific validation)
├── NumberInputConfiguration.vue (Number-specific validation)
├── DateInputConfiguration.vue (Date-specific validation)
├── EmailInputConfiguration.vue (Email-specific validation)
├── SelectInputConfiguration.vue (Select/dropdown-specific)
└── CheckboxInputConfiguration.vue (Checkbox-specific)Shared vs Specific Functionality
BaseInputConfiguration (Shared)
- Basic Properties: Label, placeholder, display name
- Styling Sections: Background, border, border radius, layout
- Font Settings: Label font and input font configuration
- Common Layout: Flex alignment, position, padding, size
- Mixins: Configuration logic mixin integration
Type-Specific Components
- Validation Rules: Input type-specific validation fields
- Custom Properties: Type-specific configuration options
- Specialized UI: Input type-specific interface elements
Implementation Plan
Phase 1: Foundation Components
1.1 Create Validation Helpers
File: src/pages/Chatbots/components/BuilderVisuals/Configuration/helpers/validationHelpers.ts
typescript
// Validation helper functions
export const validateTextInput = (value: string, rules: TextValidationRules) => { ... }
export const validateNumberInput = (value: number, rules: NumberValidationRules) => { ... }
export const validateDateInput = (value: string, rules: DateValidationRules) => { ... }
// Prop validators
export const textValidationProps = { ... }
export const numberValidationProps = { ... }
export const dateValidationProps = { ... }1.2 Create BaseInputConfiguration Component
File: src/pages/Chatbots/components/BuilderVisuals/Configuration/components/form/BaseInputConfiguration.vue
Responsibilities:
- Common input properties (label, placeholder)
- Shared styling sections (background, border, layout)
- Font settings for both label and input
- Base template structure with slots for type-specific content
Props:
typescript
interface BaseInputProps {
blockData: FormInputBlock;
path: string;
}Slots:
validation-section: For type-specific validation UIadditional-properties: For type-specific additional properties
Phase 2: Type-Specific Components
2.1 TextInputConfiguration Component
File: src/pages/Chatbots/components/BuilderVisuals/Configuration/components/form/TextInputConfiguration.vue
Validation Fields:
minLength: Minimum character lengthmaxLength: Maximum character lengthpattern: Regular expression patterncustomErrorMessage: Custom validation error message
2.2 NumberInputConfiguration Component
File: src/pages/Chatbots/components/BuilderVisuals/Configuration/components/form/NumberInputConfiguration.vue
Validation Fields:
min: Minimum numeric valuemax: Maximum numeric valuestep: Numeric step incrementcustomErrorMessage: Custom validation error message
2.3 DateInputConfiguration Component
File: src/pages/Chatbots/components/BuilderVisuals/Configuration/components/form/DateInputConfiguration.vue
Validation Fields:
min: Minimum date (using date input)max: Maximum date (using date input)customErrorMessage: Custom validation error message
Phase 3: Integration and Testing
3.1 Update Main FormInputConfiguration
Approach: Use dynamic component loading based on input type
vue
<template>
<component
:is="inputConfigurationComponent"
:block-data="blockData"
:path="path"
v-bind="$attrs"
v-on="$listeners"
/>
</template>
<script>
computed: {
inputConfigurationComponent() {
const type = this.blockData.type || 'text'
const componentMap = {
'text': 'TextInputConfiguration',
'textarea': 'TextInputConfiguration',
'number': 'NumberInputConfiguration',
'date': 'DateInputConfiguration',
'email': 'TextInputConfiguration', // Uses text validation with email pattern
// ... other mappings
}
return componentMap[type] || 'TextInputConfiguration'
}
}
</script>3.2 Component Registration
Update component imports and registration in the main configuration file.
Benefits of This Approach
Maintainability
- Separation of Concerns: Each component handles only its specific input type
- Smaller Components: Easier to understand and modify individual components
- Focused Testing: Each component can be tested in isolation
Extensibility
- Easy Addition: New input types require only creating a new component
- Type Safety: Better prop validation and TypeScript support
- Reusability: Components can be reused in other contexts
Code Quality
- Reduced Duplication: Shared functionality extracted to base component
- Clear Structure: Explicit component hierarchy and responsibilities
- Better Documentation: Each component can have focused documentation
Migration Strategy
Incremental Implementation
- Start with TextInputConfiguration: Most common and straightforward
- Test Thoroughly: Ensure functionality matches current behavior
- Implement NumberInputConfiguration: Second most common type
- Continue with Remaining Types: Date, email, select, checkbox
- Update Main Component: Switch to dynamic component loading
- Remove Old Code: Clean up conditional rendering from main component
Backward Compatibility
- Maintain existing prop interfaces during transition
- Ensure all existing functionality is preserved
- Test with existing form configurations
Testing Strategy
- Unit Tests: Test each new component individually
- Integration Tests: Test dynamic component loading
- Visual Regression Tests: Ensure UI remains consistent
- Functional Tests: Verify form validation still works correctly
File Structure After Refactoring
src/pages/Chatbots/components/BuilderVisuals/Configuration/
├── components/
│ └── form/
│ ├── BaseInputConfiguration.vue
│ ├── TextInputConfiguration.vue
│ ├── NumberInputConfiguration.vue
│ ├── DateInputConfiguration.vue
│ ├── EmailInputConfiguration.vue
│ ├── SelectInputConfiguration.vue
│ └── CheckboxInputConfiguration.vue
├── helpers/
│ └── validationHelpers.ts
└── configs/
└── FormInputConfiguration.vue (Updated main component)Success Criteria
- Functionality Preservation: All existing form input configurations work identically
- Code Reduction: Main FormInputConfiguration.vue reduced by ~60% in size
- Component Isolation: Each input type component can be developed/tested independently
- Type Safety: Improved prop validation and TypeScript support
- Documentation: Clear documentation for each component's purpose and usage
- Performance: No performance regression in form configuration rendering
Next Steps for Application-Frontend
- Create validation helpers and prop validators
- Implement BaseInputConfiguration component
- Create TextInputConfiguration component and test thoroughly
- Implement remaining type-specific components incrementally
- Update main FormInputConfiguration to use dynamic components
- Comprehensive testing and documentation updates
Creative-Engine Modularization Plan
Current Issues in Creative-Engine
- Large Component:
CreativeFormBlock.vueis over 600 lines with growing complexity - Mixed Rendering Logic: All input types rendered in a single component with many conditionals
- Styling Complexity: Style generation for all input types in one computed property
- Limited Testability: Difficult to test individual input rendering in isolation
- Maintenance Challenges: Adding new input types requires modifying multiple sections
Proposed Architecture
CreativeFormBlock.vue (Main Container)
├── FormInputBase.vue (Shared input functionality)
├── inputs/
│ ├── TextInput.vue (Text input rendering)
│ ├── TextareaInput.vue (Textarea input rendering)
│ ├── SelectInput.vue (Dropdown input rendering)
│ ├── PhoneInput.vue (Phone input with country code)
│ ├── DateInput.vue (Date input rendering)
│ └── NumberInput.vue (Number input rendering)
└── FormSubmitButton.vue (Submit button component)Implementation Strategy
Phase 1: Extract Shared Logic
Create a
utils/formInputUtils.tsfile for shared form input utilities:- Input validation helpers
- Style generation functions
- Class name generation
Create a
mixins/FormInputMixin.tswith shared input functionality:- Common props and computed properties
- Event handling for input changes
- Validation state management
Phase 2: Component Extraction
Create
FormInputBase.vueas the base component for all inputs:- Common wrapper structure
- Label rendering
- Error message display
- Style application
Extract each input type to its own component:
inputs/TextInput.vueinputs/TextareaInput.vueinputs/SelectInput.vueinputs/PhoneInput.vueinputs/DateInput.vueinputs/NumberInput.vue
Update
CreativeFormBlock.vueto use dynamic components:
vue
<component
:is="getInputComponent(input.type)"
:input="input"
:index="index"
:form-store="formStore"
@update="handleInputUpdate"
/>Phase 3: Style System Improvements
Modularize style generation:
- Base styles in
FormInputBase.vue - Type-specific styles in each input component
- Common style utilities in a shared module
- Base styles in
Improve CSS class naming consistency:
- Use BEM methodology for component classes
- Maintain backward compatibility with existing selectors
Benefits
- Improved Maintainability: Each input type in its own file
- Better Organization: Clear separation of concerns
- Enhanced Testability: Components can be tested in isolation
- Easier Extensions: Adding new input types requires minimal changes
- Reduced Complexity: Smaller, focused components
- Better Performance: Potential for optimized rendering
Migration Approach
- Start with extracting utility functions and mixins
- Create the base input component
- Extract one input type at a time, starting with text input
- Test thoroughly after each extraction
- Update the main component to use dynamic components
- Refine the style system
- Add comprehensive documentation
This modularization will significantly improve the maintainability and extensibility of the form system in Creative-Engine while preserving all existing functionality.