Skip to content

Commit

Permalink
Merge pull request #233 from ECFMP/167-mandatory-route-deleting-boxes
Browse files Browse the repository at this point in the history
fix(FlowMeasureResource): fix mandatory_route being broken
  • Loading branch information
AndyTWF authored Aug 13, 2022
2 parents 4e0947c + 831442c commit f471bd4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Filament/Resources/FlowMeasureResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static function form(Form $form): Form
->required()
->visible(fn (Closure $get) => $get('type') == FlowMeasureType::MANDATORY_ROUTE->value)
->schema([
Forms\Components\Textarea::make('')->required()
Forms\Components\Textarea::make('mandatory_route')->required()
]),
]),
self::filters($events),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected function mutateFormDataBeforeCreate(array $data): array
switch ($data['type']) {
case FlowMeasureType::MANDATORY_ROUTE->value:
Arr::pull($data, 'value');
$data['mandatory_route'] = Arr::flatten($data['mandatory_route']);
break;
case FlowMeasureType::MINIMUM_DEPARTURE_INTERVAL->value:
case FlowMeasureType::AVERAGE_DEPARTURE_INTERVAL->value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ protected function mutateFormDataBeforeFill(array $data): array

$data['filters'] = $newFilters->toArray();

if (Arr::has($data, 'mandatory_route')) {
Arr::set($data, 'mandatory_route', collect($data['mandatory_route'])
->map(function (string $value) {
return ['mandatory_route' => $value];
})
->toArray());
}

return $data;
}

Expand All @@ -96,6 +104,7 @@ protected function mutateFormDataBeforeSave(array $data): array
switch ($data['type']) {
case FlowMeasureType::MANDATORY_ROUTE->value:
Arr::pull($data, 'value');
$data['mandatory_route'] = Arr::flatten($data['mandatory_route']);
break;
case FlowMeasureType::MINIMUM_DEPARTURE_INTERVAL->value:
case FlowMeasureType::AVERAGE_DEPARTURE_INTERVAL->value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ protected function mutateFormDataBeforeFill(array $data): array

$data['filters'] = $newFilters->toArray();

if (Arr::has($data, 'mandatory_route')) {
Arr::set($data, 'mandatory_route', collect($data['mandatory_route'])
->map(function (string $value) {
return ['mandatory_route' => $value];
})
->toArray());
}

return $data;
}

Expand Down

0 comments on commit f471bd4

Please sign in to comment.