Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor endpoints initialization for Browser component #2722

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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
Loading