Added trigger function for refresh chart against plant and line

This commit is contained in:
dhanabalan
2025-04-19 12:53:18 +05:30
parent f1f9a2c5da
commit 8980429b52

View File

@@ -24,12 +24,11 @@ class Dashboard extends \Filament\Pages\Dashboard
->label('Select Plant') ->label('Select Plant')
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set) use ($selectedPlant) { ->afterStateUpdated(function ($state, callable $set) use ($selectedPlant) {
// Update only in memory and not in the URL session(['selected_plant' => $state]);
session(['selected_plant' => $state]); // Store in session session()->forget('selected_line');
session()->forget('selected_line'); // Reset line filter
$set('Plant', $state); $set('Plant', $state);
$set('Line', null); $set('Line', null);
$this->dispatch('filtersUpdated'); // Notify chart to refresh $this->triggerChartUpdate();
}), }),
// Line Filter // Line Filter
@@ -42,9 +41,16 @@ class Dashboard extends \Filament\Pages\Dashboard
->reactive() ->reactive()
->afterStateUpdated(function ($state) { ->afterStateUpdated(function ($state) {
session(['selected_line' => $state]); // Store in session 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');
}
}
} }