diff --git a/app/Filament/Pages/Dashboard.php b/app/Filament/Pages/Dashboard.php index 1de959c..c8e5471 100644 --- a/app/Filament/Pages/Dashboard.php +++ b/app/Filament/Pages/Dashboard.php @@ -24,12 +24,11 @@ class Dashboard extends \Filament\Pages\Dashboard ->label('Select Plant') ->reactive() ->afterStateUpdated(function ($state, callable $set) use ($selectedPlant) { - // Update only in memory and not in the URL - session(['selected_plant' => $state]); // Store in session - session()->forget('selected_line'); // Reset line filter + session(['selected_plant' => $state]); + session()->forget('selected_line'); $set('Plant', $state); $set('Line', null); - $this->dispatch('filtersUpdated'); // Notify chart to refresh + $this->triggerChartUpdate(); }), // Line Filter @@ -42,9 +41,16 @@ class Dashboard extends \Filament\Pages\Dashboard ->reactive() ->afterStateUpdated(function ($state) { session(['selected_line' => $state]); // Store in session - $this->dispatch('filtersUpdated'); // Notify chart to refresh + $this->triggerChartUpdate(); // Notify chart to refresh }), ]); } + // Helper to check if both filters are set + public function triggerChartUpdate(): void + { + if (session()->has('selected_plant') && session()->has('selected_line')) { + $this->dispatch('filtersUpdated'); + } + } }