// Filter presets — added to USAutoMonitoring.php public ?int $activePresetId = null; // ID of currently active preset public string $newPresetName = ''; // Bound to save-preset modal input public bool $showSavePresetModal = false; // Controls save modal visibility public bool $newPresetIsDefault = false; // Bound to "Set as default" checkbox
The existing mount() method now calls loadDefaultPreset() at the end of initialization. This means if a user has set a default preset, their saved filters are automatically applied the moment they open the Monitoring Dashboard — no manual selection needed.
Called automatically from mount(). Queries user_filter_presets for the current user's default preset on the monitoring page. If found, applies all filter values and sets $activePresetId.
$preset = UserFilterPreset::forUser(Auth::id()) ->forPage('monitoring') ->where('is_default', true) ->first(); if ($preset) { $this->applyPresetFilters($preset->filters); $this->activePresetId = $preset->id; }
Triggered when user clicks "Save" in the Save Preset modal. Validates name is not empty. If "Set as default" is checked, clears is_default on all other presets for this user first. Creates the new preset with a snapshot of all current filter values. Shows a success notification and closes the modal.
Triggered when user clicks a preset name in the presets dropdown. Fetches the preset and verifies it belongs to the current user (ownership check — prevents loading another user's preset by guessing IDs). Applies all stored filter values to the page's Livewire properties.
Deletes a preset after verifying ownership. If the deleted preset was the currently active one, clears $activePresetId so the indicator disappears from the UI.
Deactivates the preset indicator without changing any filters. Used when the user clicks the ✕ on the active preset pill. Filters stay as-is — the user's current view is unchanged, they're just no longer "in" a named preset.
Livewire computed property accessible in the blade view as $this->userPresets. Returns all presets for the current user on the monitoring page, ordered with the default preset first, then alphabetically by name.
Builds and returns the current filter snapshot as an array for storage in the filters JSON column. Captures all 11 filter properties currently on the page.
return [ 'activeTab' => $this->activeTab, 'filterDateFrom' => $this->filterDateFrom, 'filterDateTo' => $this->filterDateTo, 'filterStatus' => $this->filterStatus, 'filterCarrierStatus' => $this->filterCarrierStatus, 'filterSupplierCategory' => $this->filterSupplierCategory, 'filterSearch' => $this->filterSearch, 'filterMyAssignments' => $this->filterMyAssignments, 'issueTypeFilter' => $this->issueTypeFilter, 'issueDateFrom' => $this->issueDateFrom, 'issueDateTo' => $this->issueDateTo, ];
Applies a stored filters array back to the page's Livewire properties. Uses isset() checks on each key so loading an older preset (missing newer filter keys) doesn't cause errors — forward-compatible as new filters are added in future tasks.
| Criterion | Result | How Verified |
|---|---|---|
| Presets save and reload filters correctly | ✓ PASS | Tinker test: saved preset with filterStatus=flagged, reloaded and confirmed value |
| Default preset auto-loads on page open | ✓ PASS | loadDefaultPreset() called in mount() — confirmed query returns correct record |
| Deleting a preset removes it from DB | ✓ PASS | Tinker test: deleted preset, confirmed count returned to 0 |
| No preset can be loaded by a different user | ✓ PASS | Ownership check with user_id=999 returned null |
| PHP syntax clean | ✓ PASS | php -l USAutoMonitoring.php — no syntax errors |