Skip to content

Commit

Permalink
Refactor endpoint initialization and remove redundant checks
Browse files Browse the repository at this point in the history
  • Loading branch information
zeezo887 committed Feb 4, 2025
1 parent 53f59c3 commit e4d74ce
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/View/Components/Fields/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function __construct(
default: $default
);

if (!$this->endpoints) {
$endpointsFromModules = isset($this->modules) ? collect($this->modules)->map(function ($module) {
if (!$this->endpoints && isset($this->modules)) {
$this->endpoints = collect($this->modules)->map(function ($module) {
return [
'label' => $module['label'] ?? ucfirst($module['name']),
'value' => moduleRoute(
Expand All @@ -62,16 +62,14 @@ public function __construct(
false
),
];
})->toArray() : null;
})->toArray();
}

$this->endpoints = $this->endpoints === [] ? $endpointsFromModules ?? [] : [];

if (empty($this->endpoints)) {
$routeEndpoint = $this->moduleName;
if ($this->routePrefix) {
$routeEndpoint = Str::replaceFirst($this->routePrefix . '.', '', $this->moduleName);
}
$routeEndpoint = $this->routePrefix
? Str::replaceFirst($this->routePrefix . '.', '', $this->moduleName)

Check warning on line 70 in src/View/Components/Fields/Browser.php

View check run for this annotation

Codecov / codecov/patch

src/View/Components/Fields/Browser.php#L70

Added line #L70 was not covered by tests
: $this->moduleName;

$this->endpoint = $this->endpoint ?? (empty($endpoints) ? moduleRoute(
// Remove the route prefix from the moduleName.
$routeEndpoint,
Expand Down

0 comments on commit e4d74ce

Please sign in to comment.