Skip to content

Commit dd9bc27

Browse files
committed
UP
1 parent 6e103fc commit dd9bc27

File tree

14 files changed

+519
-93
lines changed

14 files changed

+519
-93
lines changed

README-REFACTORING.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Flowforge Refactoring Documentation
2+
3+
## Overview
4+
This document explains the refactoring of the `AbstractKanbanAdapter` class into trait-based components for better separation of concerns, maintainability, and testability.
5+
6+
## Refactoring Approach
7+
8+
The original monolithic `AbstractKanbanAdapter` class was responsible for multiple concerns:
9+
- Database queries
10+
- Card formatting
11+
- CRUD operations
12+
- Form handling
13+
- Livewire integration
14+
15+
Following the Single Responsibility Principle, these concerns have been extracted into focused traits:
16+
17+
### 1. QueryHandlingTrait
18+
- Handles all database query operations
19+
- Responsible for retrieving models, filtering by columns, counting items
20+
- Examples: `newQuery()`, `getItems()`, `getItemsForColumn()`, `getColumnItemsCount()`
21+
22+
### 2. CardFormattingTrait
23+
- Responsible for transforming Eloquent models into card data structures for the UI
24+
- Methods: `formatCardForDisplay()`, `formatCardsForDisplay()`
25+
26+
### 3. CrudOperationsTrait
27+
- Handles create, read, update, delete operations for cards
28+
- Also manages card ordering and column assignments
29+
- Methods: `createRecord()`, `updateCard()`, `deleteCard()`, `updateCardsOrderAndColumn()`
30+
31+
### 4. FormHandlingTrait
32+
- Generates and configures forms for creating and editing cards
33+
- Methods: `getConfig()`, `getCreateForm()`, `getEditForm()`
34+
35+
### 5. LivewireIntegrationTrait
36+
- Handles Livewire-specific serialization and deserialization
37+
- Methods: `toLivewire()`, `fromLivewire()`
38+
39+
## Benefits of This Approach
40+
41+
### Improved Maintainability
42+
- Each trait has a clear, focused responsibility
43+
- Changes to one aspect (e.g., card formatting) don't affect unrelated code
44+
- Easier to understand each component in isolation
45+
46+
### Enhanced Testability
47+
- Traits can be tested independently with mock dependencies
48+
- Reduced test complexity due to smaller focused components
49+
50+
### Better Code Organization
51+
- Clear separation between different types of operations
52+
- Easier to locate specific functionality
53+
- Reduced cognitive load when working with the codebase
54+
55+
### Extensibility
56+
- New adapters can selectively use only the traits they need
57+
- Custom adapters can override specific traits while keeping others
58+
59+
### Reduced Code Duplication
60+
- Common functionality is centralized in traits
61+
- Implementations can be shared across different adapter classes
62+
63+
## Implementation Notes
64+
65+
1. The traits are designed to work with the `$baseQuery` and `$config` properties from the main adapter class
66+
2. Type declarations and PHPDoc are preserved for better IDE support
67+
3. Each trait follows PSR-12 coding standards and maintains strict typing

resources/dist/flowforge.js

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/flowforge.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function flowforge({state}) {
99

1010
init: function () {
1111
// Listen for card creation
12-
this.$wire.$on('kanban-card-created', (data) => {
12+
this.$wire.$on('kanban-record-created', (data) => {
1313
const id = data[0].id;
1414
const column = data[0].column;
1515

@@ -28,26 +28,29 @@ export default function flowforge({state}) {
2828
});
2929

3030
// Listen for card update
31-
this.$wire.$on('kanban-card-updated', (data) => {
31+
this.$wire.$on('kanban-record-updated', (data) => {
3232

33+
console.log({
34+
data
35+
})
3336
const id = data[0].id;
3437

3538
this.$dispatch('close-modal', { id: 'edit-card-modal' });
3639

3740
// Highlight the updated card
38-
setTimeout(() => {
39-
const cardElement = document.querySelector(`[x-sortable-item="${id}"]`);
40-
if (cardElement) {
41-
cardElement.classList.add('animate-kanban-card-move');
42-
setTimeout(() => {
43-
cardElement.classList.remove('animate-kanban-card-move');
44-
}, 500);
45-
}
46-
}, 300);
41+
// setTimeout(() => {
42+
// const cardElement = document.querySelector(`[x-sortable-item="${id}"]`);
43+
// if (cardElement) {
44+
// cardElement.classList.add('animate-kanban-card-move');
45+
// setTimeout(() => {
46+
// cardElement.classList.remove('animate-kanban-card-move');
47+
// }, 500);
48+
// }
49+
// }, 300);
4750
});
4851

4952
// Listen for card deletion
50-
this.$wire.$on('kanban-card-deleted', (data) => {
53+
this.$wire.$on('kanban-record-deleted', (data) => {
5154
const id = data[0].id;
5255

5356
this.$dispatch('close-modal', { id: 'edit-card-modal' });

resources/views/livewire/column.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class="text-gray-400 hover:text-primary-500 dark:text-gray-500 dark:hover:text-p
3333
x-sortable
3434
x-sortable-group="cards"
3535
data-column-id="{{ $columnId }}"
36-
@end.stop="$wire.updateCardsOrderAndColumn($event.to.getAttribute('data-column-id'), $event.to.sortable.toArray())"
36+
@end.stop="$wire.updateRecordsOrderAndColumn($event.to.getAttribute('data-column-id'), $event.to.sortable.toArray())"
3737
class="p-3 flex-1 overflow-y-auto overflow-x-hidden"
3838
style="max-height: calc(100vh - 13rem);"
3939
>

0 commit comments

Comments
 (0)