Skip to content

Commit 8ea0dbb

Browse files
committed
refactor(actions): improve state fusion action formatting and logic
- Reformatted method calls with proper line breaks for readability - Updated hidden logic to use canTransitionTo method instead of transitionableStates - Added null safety with optional chaining operators - Added record refresh in after callback
1 parent f5849e0 commit 8ea0dbb

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

src/Actions/StateFusionAction.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,49 @@ protected function setUp(): void
2020
{
2121
parent::setUp();
2222

23-
$this->label(fn (Model $record) => $this->resolveLabel($record->{$this->getAttribute()}));
24-
$this->color(fn (Model $record) => $this->resolveColor($record->{$this->getAttribute()}));
25-
$this->icon(fn (Model $record) => $this->resolveIcon($record->{$this->getAttribute()}));
26-
$this->tooltip(fn (Model $record) => $this->resolveDescription($record->{$this->getAttribute()}));
27-
$this->setActionAttributes();
28-
29-
$this->hidden(
30-
fn ($record) => ! in_array(
31-
$this->getToState()::getMorphClass(),
32-
$record->{$this->getAttribute()}->transitionableStates(),
23+
$this->label(
24+
fn (Model $record) => $this->resolveLabel(
25+
$record->{$this->getAttribute()},
26+
),
27+
);
28+
$this->color(
29+
fn (Model $record) => $this->resolveColor(
30+
$record->{$this->getAttribute()},
31+
),
32+
);
33+
$this->icon(
34+
fn (Model $record) => $this->resolveIcon(
35+
$record->{$this->getAttribute()},
3336
),
3437
);
38+
$this->tooltip(
39+
fn (Model $record) => $this->resolveDescription(
40+
$record->{$this->getAttribute()},
41+
),
42+
);
43+
$this->setActionAttributes();
44+
45+
$this->hidden(function (Model $record) {
46+
return ! $record?->{$this->getAttribute()}?->canTransitionTo(
47+
$this->getToStateClass(),
48+
);
49+
});
3550

3651
$this->action(function ($record, array $data): void {
3752
if (empty($data)) {
38-
$record->{$this->getAttribute()}->transitionTo($this->getToStateClass());
53+
$record->{$this->getAttribute()}->transitionTo(
54+
$this->getToStateClass(),
55+
);
3956
} else {
40-
$record->{$this->getAttribute()}->transitionTo($this->getToStateClass(), $data);
57+
$record->{$this->getAttribute()}->transitionTo(
58+
$this->getToStateClass(),
59+
$data,
60+
);
4161
}
4262

4363
$this->success();
4464
});
65+
$this->after(fn ($record) => $record->refresh());
4566
// $this->badge();
4667
// $this->button();
4768
}

0 commit comments

Comments
 (0)