|
4 | 4 |
|
5 | 5 | namespace Relaticle\Flowforge; |
6 | 6 |
|
| 7 | +use Filament\Actions\Action; |
7 | 8 | use Filament\Actions\Contracts\HasActions; |
| 9 | +use Filament\Actions\Exceptions\ActionNotResolvableException; |
8 | 10 | use Filament\Forms\Contracts\HasForms; |
9 | 11 | use Filament\Resources\Pages\Page; |
10 | 12 | use Relaticle\Flowforge\Concerns\BaseBoard; |
|
13 | 15 | /** |
14 | 16 | * Board page for Filament resource pages. |
15 | 17 | * Extends Filament's resource Page class with kanban board functionality. |
| 18 | + * |
| 19 | + * CRITICAL: This class doesn't use InteractsWithRecord trait itself, but child |
| 20 | + * classes might. To handle the trait conflict, we override getDefaultActionRecord() |
| 21 | + * to intelligently route to either board card records or resource records based |
| 22 | + * on whether a recordKey is present in the mounted action context. |
16 | 23 | */ |
17 | 24 | abstract class BoardResourcePage extends Page implements HasActions, HasBoard, HasForms |
18 | 25 | { |
19 | 26 | use BaseBoard; |
20 | 27 |
|
21 | 28 | protected string $view = 'flowforge::filament.pages.board-page'; |
| 29 | + |
| 30 | + /** |
| 31 | + * Override Filament's action resolution to detect and route board actions. |
| 32 | + * |
| 33 | + * This method intercepts the action resolution flow to check if an action |
| 34 | + * is a board action (has recordKey in context). If so, it routes to |
| 35 | + * resolveBoardAction() which properly handles the record resolution, |
| 36 | + * similar to how table actions are handled via resolveTableAction(). |
| 37 | + * |
| 38 | + * This mirrors the logic in InteractsWithActions::resolveActions() but adds |
| 39 | + * board action detection. |
| 40 | + * |
| 41 | + * @param array<array<string, mixed>> $actions |
| 42 | + * @return array<Action> |
| 43 | + * |
| 44 | + * @throws ActionNotResolvableException |
| 45 | + */ |
| 46 | + protected function resolveActions(array $actions): array |
| 47 | + { |
| 48 | + $resolvedActions = []; |
| 49 | + |
| 50 | + foreach ($actions as $actionNestingIndex => $action) { |
| 51 | + if (blank($action['name'] ?? null)) { |
| 52 | + throw new \Filament\Actions\Exceptions\ActionNotResolvableException('An action tried to resolve without a name.'); |
| 53 | + } |
| 54 | + |
| 55 | + // Check if this is a board CARD action (has recordKey in context) |
| 56 | + // Column actions have 'column' in arguments, not recordKey |
| 57 | + // This detection happens BEFORE schema/table action detection |
| 58 | + $recordKey = $action['context']['recordKey'] ?? null; |
| 59 | + $columnId = $action['arguments']['column'] ?? null; |
| 60 | + |
| 61 | + // Only route to resolveBoardAction for card actions (not column actions) |
| 62 | + if (filled($recordKey) && blank($columnId)) { |
| 63 | + $resolvedAction = $this->resolveBoardAction($action, $resolvedActions); |
| 64 | + } elseif (filled($action['context']['schemaComponent'] ?? null)) { |
| 65 | + $resolvedAction = $this->resolveSchemaComponentAction($action, $resolvedActions); |
| 66 | + } elseif (filled($action['context']['table'] ?? null)) { |
| 67 | + $resolvedAction = $this->resolveTableAction($action, $resolvedActions); |
| 68 | + } else { |
| 69 | + $resolvedAction = $this->resolveAction($action, $resolvedActions); |
| 70 | + } |
| 71 | + |
| 72 | + if (! $resolvedAction) { |
| 73 | + continue; |
| 74 | + } |
| 75 | + |
| 76 | + $resolvedAction->nestingIndex($actionNestingIndex); |
| 77 | + $resolvedAction->boot(); |
| 78 | + |
| 79 | + $resolvedActions[] = $resolvedAction; |
| 80 | + |
| 81 | + $this->cacheSchema( |
| 82 | + "mountedActionSchema{$actionNestingIndex}", |
| 83 | + $this->getMountedActionSchema($actionNestingIndex, $resolvedAction), |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + return $resolvedActions; |
| 88 | + } |
22 | 89 | } |
0 commit comments