From 926264c8d15c56fc74332a2cd9fbd319695cb5e5 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Fri, 9 Jan 2026 16:38:39 +0100 Subject: [PATCH] feat(046): add include dependencies toggle - Add modal toggle include_dependencies (default on)\n- Persist into selection payload deterministically\n- Update quickstart, tasks, and tests --- app/Filament/Pages/InventoryLanding.php | 11 ++++++++ specs/046-inventory-sync-button/quickstart.md | 1 + specs/046-inventory-sync-button/tasks.md | 1 + .../Inventory/InventorySyncButtonTest.php | 25 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/app/Filament/Pages/InventoryLanding.php b/app/Filament/Pages/InventoryLanding.php index 425f5e8..19d7265 100644 --- a/app/Filament/Pages/InventoryLanding.php +++ b/app/Filament/Pages/InventoryLanding.php @@ -16,6 +16,7 @@ use Filament\Actions\Action as HintAction; use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Select; +use Filament\Forms\Components\Toggle; use Filament\Notifications\Notification; use Filament\Pages\Page; use Filament\Support\Enums\Size; @@ -89,6 +90,13 @@ protected function getHeaderActions(): array new \App\Rules\SupportedPolicyTypesRule, ]) ->columnSpanFull(), + Toggle::make('include_dependencies') + ->label('Include dependencies') + ->helperText('Include dependency extraction where supported.') + ->default(true) + ->dehydrated() + ->rules(['boolean']) + ->columnSpanFull(), Hidden::make('tenant_id') ->default(fn (): ?string => Tenant::current()?->getKey()) ->dehydrated(), @@ -127,6 +135,9 @@ protected function getHeaderActions(): array if (array_key_exists('policy_types', $data)) { $selectionPayload['policy_types'] = $data['policy_types']; } + if (array_key_exists('include_dependencies', $data)) { + $selectionPayload['include_dependencies'] = (bool) $data['include_dependencies']; + } $computed = $inventorySyncService->normalizeAndHashSelection($selectionPayload); $existing = InventorySyncRun::query() diff --git a/specs/046-inventory-sync-button/quickstart.md b/specs/046-inventory-sync-button/quickstart.md index a665c1d..42a2b04 100644 --- a/specs/046-inventory-sync-button/quickstart.md +++ b/specs/046-inventory-sync-button/quickstart.md @@ -25,6 +25,7 @@ ## Run locally 5. Click “Run Inventory Sync”: - Select which policy types to include (or click “Select all”). + - (Optional) Toggle “Include dependencies” if you want dependency extraction where supported. - You should see: - A database notification (started) - A bottom-right progress widget entry for `Sync inventory` diff --git a/specs/046-inventory-sync-button/tasks.md b/specs/046-inventory-sync-button/tasks.md index 556051d..686872c 100644 --- a/specs/046-inventory-sync-button/tasks.md +++ b/specs/046-inventory-sync-button/tasks.md @@ -125,6 +125,7 @@ ## Phase 6: Polish & Cross-Cutting Concerns - [X] T034 Run targeted tests: `./vendor/bin/sail artisan test --filter=InventorySync` (or specific test files) - [X] T035 Validate quickstart steps remain accurate in specs/046-inventory-sync-button/quickstart.md - [X] T036 Make BulkOperation progress reflect selected policy types (total_items = #types; per-type success/failure) in app/Filament/Pages/InventoryLanding.php and app/Jobs/RunInventorySyncJob.php +- [X] T037 Add `include_dependencies` toggle to the “Run Inventory Sync” modal in app/Filament/Pages/InventoryLanding.php and cover via tests/Feature/Inventory/InventorySyncButtonTest.php --- diff --git a/tests/Feature/Inventory/InventorySyncButtonTest.php b/tests/Feature/Inventory/InventorySyncButtonTest.php index 37accaf..3b32a5f 100644 --- a/tests/Feature/Inventory/InventorySyncButtonTest.php +++ b/tests/Feature/Inventory/InventorySyncButtonTest.php @@ -70,6 +70,31 @@ expect($run->selection_payload['policy_types'] ?? [])->toEqualCanonicalizing($selectedTypes); }); +it('persists include dependencies toggle into the run selection payload', function () { + Queue::fake(); + + [$user, $tenant] = createUserWithTenant(role: 'owner'); + $this->actingAs($user); + + $tenant->makeCurrent(); + Filament::setTenant($tenant, true); + + $sync = app(InventorySyncService::class); + $allTypes = $sync->defaultSelectionPayload()['policy_types']; + $selectedTypes = array_slice($allTypes, 0, min(2, count($allTypes))); + + Livewire::test(InventoryLanding::class) + ->callAction('run_inventory_sync', data: [ + 'policy_types' => $selectedTypes, + 'include_dependencies' => false, + ]) + ->assertHasNoActionErrors(); + + $run = InventorySyncRun::query()->where('tenant_id', $tenant->id)->latest('id')->first(); + expect($run)->not->toBeNull(); + expect((bool) ($run->selection_payload['include_dependencies'] ?? true))->toBeFalse(); +}); + it('rejects cross-tenant initiation attempts (403) with no side effects', function () { Queue::fake();