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

Lightweight layout on asynchronous loading #2120

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
38 changes: 24 additions & 14 deletions src/Screen/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function currentAsync(): self
return $this;
}

/**
/**
* @param Repository $repository
*
* @return mixed
Expand All @@ -101,28 +101,38 @@ protected function buildAsDeep(Repository $repository)
{
$this->query = $repository;

if (! $this->isSee()) {
if (!$this->isSee()) {
return;
}

$build = collect($this->layouts)
->map(function ($layouts) {
return Arr::wrap($layouts);
})
->map(function (iterable $layouts, string $key) use ($repository) {
return $this->buildChild($layouts, $key, $repository);
})
->collapse()
->all();

$variables = array_merge($this->variables, [
'manyForms' => $build,
'manyForms' => $this->reparation(),
'templateSlug' => $this->getSlug(),
'asyncEnable' => empty($this->asyncMethod) ? 0 : 1,
'asyncRoute' => $this->asyncRoute(),
]);

return view($this->async ? 'platform::layouts.blank' : $this->template, $variables);
return view($this->async ? 'layouts.blank' : $this->template, $variables);
}

/**
* @return array
*/
protected function reparation(): array
{
if ($this->asyncMethod && !$this->async) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During testing, I found that if we use asynchronous form loading and subsequently receive an error related to validation in it, it will not be displayed to us, since our asynchronous layout will not initially be loaded when the screen loads.

This error will be eliminated by adding an additional check.

if ($this->asyncMethod && !$this->async && !Session::get('errors')) {...

But in this case, again the null related error I mentioned earlier may occur.

For example, if you use something like:

$this->query->get('user')->exists

in our layout, since in case of receiving a validation error, we return to the past logic of behavior

return [];
}

return collect($this->layouts)
->map(function ($layouts) {
return Arr::wrap($layouts);
})
->map(function (array $layouts, string $key) {
return $this->buildChild($layouts, $key, $this->query);
})
->collapse()
->all();
}

/**
Expand Down