Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/old-values' into old-values
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Laravel/src/Fields/Relationships/HasMany.php
  • Loading branch information
lee-to committed Feb 5, 2025
2 parents b71430f + 798fbb8 commit 52f491e
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Laravel/src/Fields/Relationships/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function resolvePreview(): string

protected function resolveValue(): mixed
{
if($this->isOldValue()) {
if ($this->isOldValue()) {
return $this->toValue();
}

Expand Down
11 changes: 5 additions & 6 deletions src/Laravel/src/Fields/Relationships/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use MoonShine\Laravel\Traits\Fields\WithAsyncSearch;
use MoonShine\Laravel\Traits\Fields\WithRelatedLink;
use MoonShine\Laravel\Traits\Fields\WithRelatedValues;
use MoonShine\Support\DTOs\Select\Options;
use MoonShine\Support\Enums\Color;
use MoonShine\UI\Collections\ActionButtons;
use MoonShine\UI\Components\ActionButton;
Expand Down Expand Up @@ -264,7 +263,7 @@ public function setValues(array $values): void

public function getAvailableValues(): mixed
{
if(!\is_null($this->memoizeValues)) {
if (! \is_null($this->memoizeValues)) {
return $this->memoizeValues;
}

Expand Down Expand Up @@ -306,7 +305,7 @@ public function getAvailableValues(): mixed

public function getComponent(): ComponentContract
{
if(!\is_null($this->resolvedComponent)) {
if (! \is_null($this->resolvedComponent)) {
return $this->resolvedComponent;

Check failure on line 309 in src/Laravel/src/Fields/Relationships/BelongsToMany.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\BelongsToMany::getComponent() should return MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\TableBuilderContract.

Check failure on line 309 in src/Laravel/src/Fields/Relationships/BelongsToMany.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\BelongsToMany::getComponent() should return MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\TableBuilderContract.
}

Expand Down Expand Up @@ -381,14 +380,14 @@ protected function getColumnOrFormattedValue(Model $item, string|int $default):
protected function resolveOldValue(mixed $old): mixed
{
// otherwise you will have to make a db query to receive records by keys
if($this->isAsyncSearch()) {
if ($this->isAsyncSearch()) {
return $this->toValue();
}

$oldPivot = $this->getCore()->getRequest()->getOld($this->getPivotName());

return collect($old)
->map(fn ($key) => clone $this->makeRelatedModel($key, relations: $oldPivot[$key] ?? []))
->map(fn ($key): ?Model => clone $this->makeRelatedModel($key, relations: $oldPivot[$key] ?? []))
->values();
}

Expand Down Expand Up @@ -581,7 +580,7 @@ public function prepareReactivityValue(mixed $value, mixed &$casted, array &$exc
{
$casted = $this->getRelatedModel();
$value = collect($value)
->map(fn ($key) => clone $this->makeRelatedModel($key))
->map(fn ($key): ?Model => clone $this->makeRelatedModel($key))
->values();

$casted?->setRelation($this->getRelationName(), $value);
Expand Down
3 changes: 1 addition & 2 deletions src/Laravel/src/Fields/Relationships/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use MoonShine\Contracts\UI\ComponentContract;
use MoonShine\Contracts\UI\FieldContract;
use MoonShine\Contracts\UI\FieldWithComponentContract;
use MoonShine\Contracts\UI\FormBuilderContract;
use MoonShine\Contracts\UI\HasFieldsContract;
use MoonShine\Contracts\UI\TableBuilderContract;
use MoonShine\Laravel\Buttons\HasManyButton;
Expand Down Expand Up @@ -566,7 +565,7 @@ protected function resolveValue(): mixed
*/
public function getComponent(): ComponentContract
{
if(!\is_null($this->resolvedComponent)) {
if (! \is_null($this->resolvedComponent)) {
return $this->resolvedComponent;

Check failure on line 569 in src/Laravel/src/Fields/Relationships/HasMany.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\HasMany::getComponent() should return MoonShine\UI\Components\ActionButton|MoonShine\UI\Components\FormBuilder|MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\ComponentContract.

Check failure on line 569 in src/Laravel/src/Fields/Relationships/HasMany.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\HasMany::getComponent() should return MoonShine\UI\Components\ActionButton|MoonShine\UI\Components\FormBuilder|MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\ComponentContract.
}

Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Fields/Relationships/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function modifyTable(Closure $callback): static
*/
public function getComponent(): ComponentContract
{
if(!\is_null($this->resolvedComponent)) {
if (! \is_null($this->resolvedComponent)) {
return $this->resolvedComponent;

Check failure on line 216 in src/Laravel/src/Fields/Relationships/HasOne.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\HasOne::getComponent() should return MoonShine\UI\Components\FormBuilder but returns MoonShine\Contracts\UI\ComponentContract.

Check failure on line 216 in src/Laravel/src/Fields/Relationships/HasOne.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\HasOne::getComponent() should return MoonShine\UI\Components\FormBuilder but returns MoonShine\Contracts\UI\ComponentContract.
}

Expand Down
4 changes: 2 additions & 2 deletions src/Laravel/src/Fields/Relationships/ModelRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ public function makeRelatedModel(int|string $key, array $attributes = [], array
{
$related = $this->getRelatedModel();

if(\is_null($related)) {
if (\is_null($related)) {
return null;
}

return $related->forceFill([
$related->getKeyName() => $key,
...$attributes
...$attributes,
])->setRelations($relations);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Fields/Relationships/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function getTypeValue(): string

protected function resolveValue(): string
{
if($this->isOldValue()) {
if ($this->isOldValue()) {
return $this->toValue();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Laravel/src/Fields/Relationships/RelationRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function resolveValue(): mixed
protected function resolveOldValue(mixed $old): mixed
{
foreach ($this->getFields() as $field) {
if($field instanceof Json) {
if ($field instanceof Json) {
foreach ($old as $index => $value) {
$column = $field->getColumn();
$old[$index][$column] = $field->prepareOnApplyRecursive(
Expand All @@ -248,7 +248,7 @@ protected function resolveOldValue(mixed $old): mixed
*/
public function getComponent(): ComponentContract
{
if(!\is_null($this->resolvedComponent)) {
if (! \is_null($this->resolvedComponent)) {
return $this->resolvedComponent;

Check failure on line 252 in src/Laravel/src/Fields/Relationships/RelationRepeater.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\RelationRepeater::getComponent() should return MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\ComponentContract.

Check failure on line 252 in src/Laravel/src/Fields/Relationships/RelationRepeater.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\Laravel\Fields\Relationships\RelationRepeater::getComponent() should return MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\ComponentContract.
}

Expand Down
6 changes: 3 additions & 3 deletions src/UI/src/Fields/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function prepareOnApplyRecursive(iterable $collection): array
$collection = $this->prepareOnApply($collection);

foreach ($this->getFields() as $field) {
if($field instanceof self) {
if ($field instanceof self) {
foreach ($collection as $index => $value) {
$column = $field->getColumn();
$collection[$index][$column] = $field->prepareOnApplyRecursive(
Expand All @@ -371,7 +371,7 @@ protected function resolveOldValue(mixed $old): mixed

public function getComponent(): ComponentContract
{
if(!\is_null($this->resolvedComponent)) {
if (! \is_null($this->resolvedComponent)) {
return $this->resolvedComponent;

Check failure on line 375 in src/UI/src/Fields/Json.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\UI\Fields\Json::getComponent() should return MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\ComponentContract.

Check failure on line 375 in src/UI/src/Fields/Json.php

View workflow job for this annotation

GitHub Actions / moonshine-analyse

Method MoonShine\UI\Fields\Json::getComponent() should return MoonShine\UI\Components\Table\TableBuilder but returns MoonShine\Contracts\UI\ComponentContract.
}

Expand Down Expand Up @@ -451,7 +451,7 @@ public function getComponent(): ComponentContract
fn (TableBuilder $tableBuilder) => value($this->modifyTable, $tableBuilder, $this->isPreviewMode()),
);

if(!$this->isObjectMode() && !$this->isPreviewMode()) {
if (! $this->isPreviewMode()) {
$component = $component
->editable()
->reindex(prepared: true)
Expand Down

0 comments on commit 52f491e

Please sign in to comment.