|
| 1 | +3. **`findExistingCombiner(allNodes, targetReferences)`** |
| 2 | + |
| 3 | + - Finds existing combiner with matching sources |
| 4 | + - Uses existing `arrayWithSameObjects` utility |
| 5 | + - Handles sources in any order |
| 6 | + - Pure function, fully testable |
| 7 | + |
| 8 | +4. **`filterCombinerCandidates(selectedNodes, adapterTypes)`** |
| 9 | + |
| 10 | + - Filters nodes to only combiner-eligible ones |
| 11 | + - Wraps `isNodeCombinerCandidate` for array filtering |
| 12 | + - Returns undefined if no candidates found |
| 13 | + |
| 14 | +5. **`isAssetMapperCombiner(nodes)`** |
| 15 | + - Checks if combiner should be an asset mapper |
| 16 | + - Detects presence of pulse nodes |
| 17 | + - Simple boolean check |
| 18 | + |
| 19 | +**Type Exports:** |
| 20 | + |
| 21 | +- `CombinerEligibleNode` - Union type for valid combiner source nodes |
| 22 | + |
| 23 | +#### 2. Created Comprehensive Tests ✅ |
| 24 | + |
| 25 | +**File**: `src/modules/Workspace/utils/toolbar.utils.spec.ts` |
| 26 | + |
| 27 | +**Test Coverage:** |
| 28 | + |
| 29 | +- ✅ 29 test cases covering all functions |
| 30 | +- ✅ All tests passing |
| 31 | +- ✅ Edge cases covered: |
| 32 | + - Nodes with/without COMBINE capability |
| 33 | + - Missing adapter types |
| 34 | + - Different node types (adapters, bridges, pulse, edge) |
| 35 | + - Empty arrays |
| 36 | + - Undefined parameters |
| 37 | + - Source order variations |
| 38 | + - Different source lengths |
| 39 | + - Multiple matching combiners |
| 40 | + |
| 41 | +**Test Results:** |
| 42 | + |
| 43 | +``` |
| 44 | +Test Files 1 passed (1) |
| 45 | +Tests 29 passed (29) |
| 46 | +Duration 1.04s |
| 47 | +``` |
| 48 | + |
| 49 | +#### 3. Refactored ContextualToolbar Component ✅ |
| 50 | + |
| 51 | +**File**: `src/modules/Workspace/components/nodes/ContextualToolbar.tsx` |
| 52 | + |
| 53 | +**Changes Made:** |
| 54 | + |
| 55 | +1. **Updated Imports** |
| 56 | + |
| 57 | + - Removed: `EntityType`, `arrayWithSameObjects`, `CombinerEligibleNode` type |
| 58 | + - Added: All new toolbar utility functions |
| 59 | + |
| 60 | +2. **Simplified `selectedCombinerCandidates` Memoized Selector** |
| 61 | + |
| 62 | + - **Before**: Complex inline filter with adapter type checking (8 lines) |
| 63 | + - **After**: Single line call to `filterCombinerCandidates(selectedNodes, data?.items)` |
| 64 | + |
| 65 | +3. **Simplified `isAssetManager` Memoized Selector** |
| 66 | + |
| 67 | + - **Before**: `.find()` check for pulse nodes (3 lines) |
| 68 | + - **After**: Single line call to `isAssetMapperCombiner(selectedCombinerCandidates)` |
| 69 | + |
| 70 | +4. **Simplified `onManageTransformationNode` Function** |
| 71 | + - **Before**: Complex inline logic for: |
| 72 | + - Building entity references (15 lines) |
| 73 | + - Finding existing combiner (11 lines) |
| 74 | + - **After**: Clean, readable function calls: |
| 75 | + ```typescript |
| 76 | + const entityReferences = buildEntityReferencesFromNodes(selectedCombinerCandidates) |
| 77 | + const existingCombiner = findExistingCombiner(nodes, entityReferences) |
| 78 | + ``` |
| 79 | + |
| 80 | +**Benefits Achieved:** |
| 81 | + |
| 82 | +- ✅ Reduced complexity in component |
| 83 | +- ✅ Extracted logic is now unit testable |
| 84 | +- ✅ Better separation of concerns |
| 85 | +- ✅ More maintainable code |
| 86 | +- ✅ Preserved all existing functionality |
| 87 | +- ✅ No breaking changes |
| 88 | + |
| 89 | +#### 4. Validation ✅ |
| 90 | + |
| 91 | +- ✅ All utility tests passing (29/29) |
| 92 | +- ✅ TypeScript type checking passed |
| 93 | +- ✅ No compilation errors |
| 94 | +- ✅ Component successfully refactored |
| 95 | +- ✅ All functions properly exported and imported |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Summary of Phase 1 |
| 100 | + |
| 101 | +**Files Created:** |
| 102 | + |
| 103 | +1. `src/modules/Workspace/utils/toolbar.utils.ts` (100 lines) |
| 104 | +2. `src/modules/Workspace/utils/toolbar.utils.spec.ts` (500+ lines) |
| 105 | + |
| 106 | +**Files Modified:** |
| 107 | + |
| 108 | +1. `src/modules/Workspace/components/nodes/ContextualToolbar.tsx` (simplified ~40 lines) |
| 109 | + |
| 110 | +**Test Coverage:** |
| 111 | + |
| 112 | +- 5 new utility functions |
| 113 | +- 29 comprehensive test cases |
| 114 | +- 100% coverage of utility functions |
| 115 | +- All tests passing ✅ |
| 116 | + |
| 117 | +**Code Quality Improvements:** |
| 118 | + |
| 119 | +- Reduced cyclomatic complexity in component |
| 120 | +- Improved readability with descriptive function names |
| 121 | +- Better testability with pure functions |
| 122 | +- Maintained existing UX and functionality |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## Next Steps |
| 127 | + |
| 128 | +Phase 1 is complete! Ready to move to Phase 2 when user is ready: |
| 129 | + |
| 130 | +**Phase 2: Improve UX** |
| 131 | + |
| 132 | +- Enhance duplicate detection messaging |
| 133 | +- Improve toast notifications |
| 134 | +- Consider visual feedback options |
| 135 | +- Possibly add user choice modal |
| 136 | + |
| 137 | +**Phase 3: Add Component Tests** |
| 138 | + |
| 139 | +- Cypress component tests for ContextualToolbar |
| 140 | +- Test toolbar rendering with different selections |
| 141 | +- Test button states and interactions |
| 142 | +- Test toast notifications |
| 143 | +- Test navigation behavior |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## Notes |
| 148 | + |
| 149 | +- All existing functionality preserved |
| 150 | +- No breaking changes introduced |
| 151 | +- UX remains the same (as requested) |
| 152 | +- Ready for Phase 2 UX improvements |
0 commit comments