From cc572ae2386a8d967986b2ddeb620df13a02e153 Mon Sep 17 00:00:00 2001 From: Samuel Hepworth Date: Tue, 2 Aug 2022 12:37:09 +0100 Subject: [PATCH 1/4] fix(FlightInformationRegionsRelationManager): make FIR searchable by its identifier --- .../FlightInformationRegionsRelationManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php index 00b90ea1..2cbd8c25 100644 --- a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php +++ b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php @@ -12,7 +12,7 @@ class FlightInformationRegionsRelationManager extends RelationManager { protected static string $relationship = 'flightInformationRegions'; - protected static ?string $recordTitleAttribute = 'name'; + protected static ?string $recordTitleAttribute = 'identifier'; public static function form(Form $form): Form { From 5d92a36d6da8ea4a4bca6d463abc81361d169218 Mon Sep 17 00:00:00 2001 From: Samuel Hepworth Date: Tue, 2 Aug 2022 21:10:32 +0100 Subject: [PATCH 2/4] fix(FlightInformationRegionsRelationManager): search by identifier and name --- ...lightInformationRegionsRelationManager.php | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php index 2cbd8c25..2c1367e9 100644 --- a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php +++ b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php @@ -2,18 +2,25 @@ namespace App\Filament\Resources\UserResource\RelationManagers; +use App\Models\FlightInformationRegion; use Filament\Forms; use Filament\Resources\Form; use Filament\Resources\RelationManagers\RelationManager; use Filament\Resources\Table; use Filament\Tables; +use Illuminate\Support\Collection; class FlightInformationRegionsRelationManager extends RelationManager { protected static string $relationship = 'flightInformationRegions'; - protected static ?string $recordTitleAttribute = 'identifier'; + protected static ?string $recordTitleAttribute = 'name'; + private static function setFirOptions(Collection $firs) + { + return $firs->mapWithKeys(fn (FlightInformationRegion $fir) => [$fir->id => $fir->identifierName]); + } + public static function form(Form $form): Form { return $form @@ -45,7 +52,18 @@ public static function table(Table $table): Table ]) ->headerActions([ Tables\Actions\CreateAction::make(), - Tables\Actions\AttachAction::make(), + Tables\Actions\AttachAction::make() + ->label("Add User to FIR") + ->form(fn (Form $form): array => [ + Forms\Components\Select::make('flight_information_region_id') + ->label("Flight Information Region") + ->searchable() + ->options( + self::setFirOptions( + FlightInformationRegion::all() + ) + ) + ]) ]) ->actions([ Tables\Actions\EditAction::make(), From 750506e1d523a2a6be00e14f9fc0d0e0f7754e38 Mon Sep 17 00:00:00 2001 From: Samuel Hepworth Date: Tue, 2 Aug 2022 21:59:43 +0100 Subject: [PATCH 3/4] fix(FlightInformationRegionsRelationManager.php): remove unnecessary AttachAction button label --- .../RelationManagers/FlightInformationRegionsRelationManager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php index 2c1367e9..d7ac38cd 100644 --- a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php +++ b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php @@ -53,7 +53,6 @@ public static function table(Table $table): Table ->headerActions([ Tables\Actions\CreateAction::make(), Tables\Actions\AttachAction::make() - ->label("Add User to FIR") ->form(fn (Form $form): array => [ Forms\Components\Select::make('flight_information_region_id') ->label("Flight Information Region") From d6514b8374fc0976a31cba474d4f38b54b4e9b47 Mon Sep 17 00:00:00 2001 From: Samuel Hepworth Date: Tue, 2 Aug 2022 22:27:57 +0100 Subject: [PATCH 4/4] chores: run linter --- app/Console/Kernel.php | 1 - .../FlowMeasure/Content/FlowMeasureRecipientsFactory.php | 8 ++++---- .../FlightInformationRegionsRelationManager.php | 2 +- app/Http/Controllers/EventController.php | 2 +- app/Imports/EventParticipantsImport.php | 4 ++-- database/factories/EventFactory.php | 6 +++--- tests/Api/EventTest.php | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 84b2e04f..25d8ead9 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,7 +2,6 @@ namespace App\Console; -use App\Console\Commands\DeleteOldData; use App\Console\Commands\OptimiseTables; use App\Console\Commands\SendDiscordNotifications; use Illuminate\Console\Scheduling\Schedule; diff --git a/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php b/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php index 53926796..7ae1ed4d 100644 --- a/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php +++ b/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php @@ -28,10 +28,10 @@ private function hasRecentlyBeenNotified(PendingMessageInterface $pendingMessage { $measure = $pendingMessage->flowMeasure(); return $pendingMessage->type( - ) === DiscordNotificationType::FLOW_MEASURE_ACTIVATED && $measure->notifiedDiscordNotifications->firstWhere( - fn (DiscordNotification $notification) => $notification->created_at > Carbon::now()->subHour() && - $notification->pivot->notified_as === $measure->identifier - ) !== null; + ) === DiscordNotificationType::FLOW_MEASURE_ACTIVATED && $measure->notifiedDiscordNotifications->firstWhere( + fn (DiscordNotification $notification) => $notification->created_at > Carbon::now()->subHour() && + $notification->pivot->notified_as === $measure->identifier + ) !== null; } private function ecfmpRecipients(PendingMessageInterface $pendingMessage): FlowMeasureRecipientsInterface diff --git a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php index d7ac38cd..ad6c2a22 100644 --- a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php +++ b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php @@ -20,7 +20,7 @@ private static function setFirOptions(Collection $firs) { return $firs->mapWithKeys(fn (FlightInformationRegion $fir) => [$fir->id => $fir->identifierName]); } - + public static function form(Form $form): Form { return $form diff --git a/app/Http/Controllers/EventController.php b/app/Http/Controllers/EventController.php index a03c14ca..0275ee79 100644 --- a/app/Http/Controllers/EventController.php +++ b/app/Http/Controllers/EventController.php @@ -25,7 +25,7 @@ public function getFilteredEvents(Request $request): JsonResource } else { if ($this->onlyActive($request)) { $flowMeasures = $this->repository->getActiveEvents($this->includeTrashed($request)); - } else if ($this->onlyFinished($request)) { + } elseif ($this->onlyFinished($request)) { $flowMeasures = $this->repository->getFinishedEvents($this->includeTrashed($request)); } else { if ($this->onlyUpcoming($request)) { diff --git a/app/Imports/EventParticipantsImport.php b/app/Imports/EventParticipantsImport.php index 751329e2..a0b8c5ea 100644 --- a/app/Imports/EventParticipantsImport.php +++ b/app/Imports/EventParticipantsImport.php @@ -40,8 +40,8 @@ public function collection(Collection $rows) $this->event->participants()->delete(); $this->event->participants()->createMany( $rows - ->filter(fn($row) => $this->rowValid($row)) - ->map(fn(Collection $row): array => [ + ->filter(fn ($row) => $this->rowValid($row)) + ->map(fn (Collection $row): array => [ 'cid' => $row[0], 'origin' => !isset($row[1]) || empty($row[1]) ? null : Str::upper($row[1]), 'destination' => !isset($row[2]) || empty($row[2]) ? null : Str::upper($row[2]), diff --git a/database/factories/EventFactory.php b/database/factories/EventFactory.php index ca04a0d9..0d0ba048 100644 --- a/database/factories/EventFactory.php +++ b/database/factories/EventFactory.php @@ -30,7 +30,7 @@ public function finished(): static public function notStarted(): static { - return $this->state(fn(array $attributes) => [ + return $this->state(fn (array $attributes) => [ 'date_start' => $this->faker->dateTimeBetween('now + 1 minute', 'now + 1 hour'), 'date_end' => $this->faker->dateTimeBetween('now + 2 hour', 'now + 3 hour'), ]); @@ -38,7 +38,7 @@ public function notStarted(): static public function withTimes(Carbon $startTime, Carbon $endTime): static { - return $this->state(fn(array $attributes) => [ + return $this->state(fn (array $attributes) => [ 'date_start' => $startTime, 'date_end' => $endTime, ]); @@ -46,7 +46,7 @@ public function withTimes(Carbon $startTime, Carbon $endTime): static public function withVatcanCode(): static { - return $this->state(fn(array $attributes) => [ + return $this->state(fn (array $attributes) => [ 'vatcan_code' => $this->faker->word(), ]); } diff --git a/tests/Api/EventTest.php b/tests/Api/EventTest.php index d96ba78c..e494eb8a 100644 --- a/tests/Api/EventTest.php +++ b/tests/Api/EventTest.php @@ -77,7 +77,7 @@ public function testItReturnsAnEventWithParticipants() 'date_end' => ApiDateTimeFormatter::formatDateTime($event->date_end), 'flight_information_region_id' => $event->flight_information_region_id, 'vatcan_code' => $event->vatcan_code, - 'participants' => $event->participants->map(fn(EventParticipant $eventParticipant) => [ + 'participants' => $event->participants->map(fn (EventParticipant $eventParticipant) => [ 'cid' => $eventParticipant->cid, 'destination' => $eventParticipant->destination, 'origin' => $eventParticipant->origin,