Skip to content

Commit

Permalink
Merge branch '3.x' into column-selection-hide-on-init
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to authored Jan 26, 2025
2 parents 275c6d7 + 97e5c23 commit 8c5116c
Show file tree
Hide file tree
Showing 46 changed files with 485 additions and 197 deletions.
32 changes: 32 additions & 0 deletions .meta-storm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
<stopCompletion />
</classMethod>

<classMethod
class="\MoonShine\UI\Components\Icon"
method="make"
argument="0"
>
<files extension="blade.php" xpath="$project/vendor/moonshine/moonshine/src/UI/resources/views/icons"/>
<stopCompletion />
</classMethod>

<classMethod
class="\MoonShine\UI\Components\ActionButton"
method="method"
Expand Down Expand Up @@ -63,6 +72,22 @@
<collection name="justify-align" argument="0" />
<stopCompletion />
</classMethod>
<classMethod
class="\MoonShine\UI\Components\ProgressBar"
method="make"
argument="1"
>
<collection name="size" argument="1" />
<stopCompletion />
</classMethod>
<classMethod
class="\MoonShine\UI\Components\Spinner"
method="make"
argument="0"
>
<collection name="size" argument="0" />
<stopCompletion />
</classMethod>
</definitions>
<collections>
<strings name="items-align">
Expand All @@ -80,5 +105,12 @@
<value>around</value>
<value>evenly</value>
</strings>
<strings name="size">
<value>xs</value>
<value>sm</value>
<value>md</value>
<value>lg</value>
<value>xl</value>
</strings>
</collections>
</meta-storm>
3 changes: 2 additions & 1 deletion src/Contracts/src/UI/FieldContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ interface FieldContract extends
SortableFieldContract,
HasLinkContract,
HasBadgeContract,
HasHintContract
HasHintContract,
HasReactivityContract
{
public function defaultMode(): static;

Expand Down
6 changes: 6 additions & 0 deletions src/Contracts/src/UI/HasReactivityContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ interface HasReactivityContract
{
public function isReactive(): bool;

public function isReactivitySupported(): bool;

public function prepareReactivityValue(mixed $value, mixed &$casted, array &$except): mixed;

public function getReactiveValue(): mixed;

/**
* @param TFields $fields
*
Expand Down
25 changes: 17 additions & 8 deletions src/Laravel/src/Fields/Relationships/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Closure;
use Illuminate\Database\Eloquent\Model;
use MoonShine\Contracts\UI\HasReactivityContract;
use MoonShine\Core\Exceptions\PageException;
use MoonShine\Laravel\Collections\Fields;
use MoonShine\Laravel\Contracts\Fields\HasAsyncSearchContract;
use MoonShine\Laravel\Contracts\Fields\HasRelatedValuesContact;
use MoonShine\Laravel\Enums\Action;
Expand All @@ -18,7 +16,6 @@
use MoonShine\UI\Contracts\DefaultValueTypes\CanBeObject;
use MoonShine\UI\Contracts\HasDefaultValueContract;
use MoonShine\UI\Traits\Fields\HasPlaceholder;
use MoonShine\UI\Traits\Fields\Reactivity;
use MoonShine\UI\Traits\Fields\Searchable;
use MoonShine\UI\Traits\Fields\WithDefaultValue;
use Throwable;
Expand All @@ -27,22 +24,18 @@
* @template-covariant R of \Illuminate\Database\Eloquent\Relations\BelongsTo
*
* @extends ModelRelationField<R>
*
* @implements HasReactivityContract<Fields>
*/
class BelongsTo extends ModelRelationField implements
HasAsyncSearchContract,
HasRelatedValuesContact,
HasDefaultValueContract,
CanBeObject,
HasReactivityContract
CanBeObject
{
use WithRelatedValues;
use WithAsyncSearch;
use Searchable;
use WithDefaultValue;
use HasPlaceholder;
use Reactivity;
use BelongsToOrManyCreatable;

protected string $view = 'moonshine::fields.relationships.belongs-to';
Expand Down Expand Up @@ -124,6 +117,22 @@ protected function resolveOnApply(): ?Closure
};
}

public function prepareReactivityValue(mixed $value, mixed &$casted, array &$except): mixed
{
$value = data_get($value, 'value', $value);

$casted = $this->getRelatedModel();
$related = $this->getRelation()?->getRelated();

$target = $related?->forceFill([
$related->getKeyName() => $value,
]);

$casted?->setRelation($this->getRelationName(), $target);

return $value;
}

/**
* @throws Throwable
*/
Expand Down
Loading

0 comments on commit 8c5116c

Please sign in to comment.