-
Notifications
You must be signed in to change notification settings - Fork 3
Add formula field feature (Champ Formule) #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devpf
Are you sure you want to change the base?
Conversation
7739c9a to
88693a7
Compare
d8b8f9f to
ec2684e
Compare
ec2684e to
3ccad52
Compare
Code Review: Formula Field Feature (Champ Formule)Overall AssessmentThis is a well-structured implementation of a formula field feature that follows the project's architecture patterns. The code quality is high and demonstrates good understanding of the mes-demarches codebase structure. ✅ StrengthsArchitecture & Design:
Code Quality:
Security & Data Integrity:
🔍 Areas for ImprovementPerformance Considerations:
Code Structure:
UI/UX:
🔧 Technical IssuesGraphQL Schema:
Database:
Testing:
🛡️ Security Review
📝 Minor Suggestions
🎯 Compliance with Project Standards
🚀 RecommendationAPPROVE with minor optimizations to consider for future iterations. This is a solid implementation that adds significant value while maintaining code quality and following established patterns. The formula field feature is ready for deployment with the current implementation. The identified performance optimizations can be addressed in future iterations based on real-world usage patterns. |
Pull Request Review: Formula Field Feature (Champ Formule)SummaryThis PR implements a comprehensive formula field feature that allows administrators to create calculated fields in forms. The implementation follows the project's established patterns and includes proper test coverage. Code Quality ✅Strengths:
Architecture Assessment ✅Model Design:
Service Layer:
Security Considerations ✅Formula Evaluation Security:
Input Sanitization:
Performance Considerations
|
be177c5 to
464a052
Compare
Code Review - Formula Field Feature (Champ Formule)🎯 Overall AssessmentThis is a well-implemented feature that adds formula calculation capabilities to the form system. The implementation follows the established patterns in the codebase and includes comprehensive testing. However, there are several areas that need attention before deployment. 🚨 Security & Performance Concerns1. Formula Expression Injection Risk
2. Circular Reference Detection
3. Performance Impact
🐛 Potential Bugs1. Value Overriding in FormuleChamp
2. Missing Validation in Controller
3. JavaScript Error Handling
🏗️ Code Quality Issues1. Inconsistent Error Messages
2. Missing Edge Case Handling
3. Code Duplication
🧪 Test Coverage Analysis✅ Strengths:
🎨 Best Practices & Style✅ Good Practices:
🔧 Improvements Needed:
🚀 Performance ConsiderationsCurrent Issues:
Recommendations:
🔒 Security AssessmentLow Risk Items:
Medium Risk Items:
📋 Action Items Before MergeCritical (Must Fix):
Important (Should Fix):
Nice to Have:
🎯 Recommendations
📊 Final Score: 7.5/10This is a solid implementation that shows good understanding of the codebase architecture. The comprehensive testing and thoughtful UI design are commendable. However, the performance and validation concerns need to be addressed before production deployment. The feature flag approach shows good judgment for a complex feature like this. I'd recommend addressing the critical issues, then using the feature flag for a gradual rollout while monitoring performance impact. |
This specification document outlines the implementation of a new
formula field type that allows automatic calculation of values
based on other fields in the form.
Key features:
- Support for both numeric and text formulas using Dentaku
- Mustache syntax {Field Label} for field references
- Automatic text-to-numeric conversion for calculations
- Always returns text output (simplified approach)
- Uses INSTANCE_* constants for fork compatibility
- Real-time recalculation when dependent fields change
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Introduces FormuleChamp and FormuleTypeDeChamp classes to support formula-based calculations in form fields.
- Add formule to TYPE_CHAMPS enum - Configure formule as STANDARD category - Add formule_expression to INSTANCE_OPTIONS
Add translations for formule type and validation error messages.
Add factories for FormuleChamp and FormuleTypeDeChamp with various test scenarios including field references and text formulas.
Include tests for formula expression validation, calculation logic, field references, and error handling scenarios.
- Add EditableChamp::FormuleComponent for formula field display - Add FormulaValueDisplayComponent with smart value formatting (URLs, dates, numbers) - Add GraphQL FormuleChampDescriptorType and schema integration - Add _show template for formula field rendering - Include DSFR styling and accessibility features - Add French/English translations for formula components
…port
- Add FormulaCalculationService with comprehensive formula evaluation
- Support French Excel functions (SOMME, MOYENNE, SI, MIN, MAX, ABS, ARRONDI)
- Implement field reference resolution using field labels {Field Name}
- Add circular reference detection and error handling
- Create intelligent value formatting components with URL/date/number detection
- Add comprehensive test coverage for all calculation scenarios
- Ensure DSFR styling and accessibility compliance
- Add formula expression field to type_de_champ editor form - Include help text for field reference syntax and French functions - Add proper HTML attributes for accessibility (DSFR styling) - Add formule_expression parameter to controller whitelist - Update formule_champ_spec tests to match Dentaku implementation - Add formula editor component tests for UI validation
- Fix validation by using standard 'value' attribute instead of computed_value - Fix number/date display confusion in FormulaValueDisplayComponent - Simplify formula field UI component (remove flashy callout) - Clean up redundant test mocks for better maintainability - Ensure decimal results without fractional part display as integers
Replace delegation to type_de_champ with direct type_champ comparisons for visa?, te_fenua?, lexpol?, formule? methods to avoid expensive lookup operations.
- Add dependent_stable_ids to track field dependencies in formulas - Add formule_user_expression methods for user-friendly display - Auto-refresh dependent formula fields when referenced fields change - Add FormulaExpressionService for stable_id/libelle conversion
- Fix factory to use value instead of deprecated computed_value - Add comprehensive tests for dependent formula champs functionality - Update GraphQL schema with formula field changes
Conditionally enable formule field based on procedure feature flag to control rollout of this new field type.
- Remove duplicate used_by_routing_rules? method that was causing rubocop error - Fix validation method name from validate_champ_value_or_prefill? to validate_champ_value?
The TypeDeChamp model doesn't have a revision attribute directly, it gets it through associations. The test was incorrectly trying to pass revision to the factory.
The table_id method from TypeDeChamp was not accessible from Champ instances, causing failures in TableRowSelectorComponent. Add table_id to the explicit delegation alongside accredited_user_list.
Add the formule feature to the list of features initialized by Flipper. This allows the formula field type to be controlled via feature flags.
- Add Stimulus controller to convert labels to stable_ids in real-time - Store formulas with stable_ids for robust dependency tracking - Show user-friendly labels in UI, convert to stable_ids before save - Add validation feedback for invalid field references - Add automatic refresh of dependent formulas when values change - Add .worktrees to gitignore 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Server-side validation now detects unresolved variables ({Variable} patterns)
- Client keeps original expression when conversion fails (preserves user work)
- Clear error messages showing which fields are unknown
- Fix SI function to treat 0 as false for Excel-like behavior
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
- Remove formule_user_expression= setter as conversion is handled client-side - Remove formule_user_expression from controller permitted params - Update specs to use revisions array instead of single revision mock - Fix rubocop offenses (trailing whitespace) The formula field conversion from labels to stable IDs is now exclusively handled by the JavaScript controller, making the server-side setter redundant. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…state - Document completed implementation (MVP functional with Dentaku) - Add hybrid labels/stable_ids architecture documentation - Define order constraints and public/private context rules - Update roadmap based on existing implementation - Prioritize critical missing features (order validation) - Clarify stable_ids are essential for robustness (field renaming immunity)
- Move formula field configuration section after description field - Maintain consistency with integer and date fields ordering - Follow standard pattern: name, description, specific parameters 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
464a052 to
0202c0c
Compare
d67fd3d to
770f813
Compare
Summary
• Add new formula field type to support calculated values in forms
• Formula fields can perform mathematical calculations and text concatenation
• Automatic recalculation when dependent fields change
• Support for field references using {Field Name} syntax
Technical Implementation
• Add FormuleChamp and FormuleTypeDeChamp models
• Configure formule type in TypeDeChamp constants
• Add French translations for the new field type
• Include comprehensive test suite with factories
• Foundation for Dentaku integration (gem to be added)
Test Plan
Next Steps