forget(['selected_plant', 'selected_line', 'selected_status', 'production_order']); $this->filtersForm->fill([ 'plant' => null, 'line' => null, 'selected_status' => null, 'production_order' => null, ]); } public function filtersForm(Form $form): Form { return $form ->statePath('filters') // Explicitly set where to store form data ->schema([ Select::make('plant') ->label('Select Plant') ->reactive() //->options(Plant::pluck('name', 'id')) ->options(function (callable $get) { $userHas = Filament::auth()->user()->plant_id; return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->afterStateUpdated(function ($state) { session(['selected_plant' => $state]); $this->triggerChartUpdate(); }), // Line Filter Select::make('line') ->options(function ($get) { $plantId = $get('plant'); return $plantId ? Plant::find($plantId)->getLineNames()->pluck('name', 'id') : []; }) ->label('Select Line') ->reactive() ->afterStateUpdated(function ($state) { session(['selected_line' => $state]); // Store in session $this->triggerChartUpdate(); }), Select::make('success_status') ->label('Select Status') ->options([ 'Ok' => 'Ok', 'Not Ok' => 'Not Ok', ]) ->reactive() ->afterStateUpdated(function ($state) { session(['selected_status' => $state]); // fixed typo //$this->dispatch('cumulativeChart'); // custom Livewire event }), // Production Order Text Input TextInput::make('production_order') ->label('Production Order') ->reactive() ->afterStateUpdated(function ($state) { session(['production_order' => $state]); $this->triggerChartUpdate(); }), ]) ->columns(4); } // public function triggerChartUpdate(): void // { // if (session()->has('selected_plant') && session()->has('selected_line') && session()->has('production_order')) { // $this->dispatch('productionOrderChart'); // } // } public function triggerChartUpdate(): void { $filters = $this->filtersForm->getState(); if (!empty($filters['plant']) && !empty($filters['line']) && !empty($filters['production_order']) && !empty($filters['success_status'])) { $this->dispatch('productionOrderChart', filters: $filters); } } public static function canAccess(): bool { return Auth::check() && Auth::user()->can('view production order count dashboard'); } }