Skip to content

Commit 250cd70

Browse files
committed
5.2.4
1 parent e34b3aa commit 250cd70

File tree

14 files changed

+98
-39
lines changed

14 files changed

+98
-39
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,5 @@
162162
},
163163
"minimum-stability": "dev",
164164
"prefer-stable": true,
165-
"version": "5.2.3"
165+
"version": "5.2.4"
166166
}

public/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/app.js": "/app.js?id=daaffa78cdcf42b078c1a3167c9a19d1",
2+
"/app.js": "/app.js?id=b857d5654171bf2bc52af06dc8eb5772",
33
"/ui.js": "/ui.js?id=592866a715b1c20b43fff6ca7980b279",
44
"/manifest.js": "/manifest.js?id=3267e5c99fd7b729e2f38ec55b50397d",
55
"/app.css": "/app.css?id=e6e32c23966698900f862c22cfc1651d",

resources/js/fields/Form/SlugField.vue

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@
1212
ref="theInput"
1313
:value="value"
1414
@blur="handleChangesOnBlurEvent"
15+
@keyup.enter="handleChangeOnPressingEnterEvent"
16+
@keydown.enter="handleChangeOnPressingEnterEvent"
1517
:id="field.uniqueKey"
16-
:disabled="isReadonly"
18+
:disabled="isImmutable"
19+
:readonly="isImmutable"
1720
class="w-full form-control form-input form-control-bordered"
1821
:dusk="field.attribute"
1922
autocomplete="off"
2023
spellcheck="false"
2124
/>
2225

2326
<button
24-
class="rounded inline-flex text-sm ml-3 link-default"
2527
v-if="field.showCustomizeButton"
2628
type="button"
2729
@click="toggleCustomizeClick"
30+
:dusk="`${field.attribute}-slug-field-edit-button`"
31+
class="rounded inline-flex text-sm ml-3 link-default"
2832
>
2933
{{ __('Customize') }}
3034
</button>
@@ -40,13 +44,15 @@ import {
4044
HandlesValidationErrors,
4145
} from '@/mixins'
4246
import debounce from 'lodash/debounce'
47+
import get from 'lodash/get'
4348
import isNil from 'lodash/isNil'
4449
4550
export default {
4651
mixins: [FormField, HandlesFieldPreviews, HandlesValidationErrors],
4752
4853
data: () => ({
4954
isListeningToChanges: false,
55+
isCustomisingValue: false,
5056
debouncedHandleChange: null,
5157
}),
5258
@@ -74,10 +80,24 @@ export default {
7480
}
7581
},
7682
77-
async handleChangesOnBlurEvent(event) {
78-
let value = event?.target?.value ?? event
83+
handleChangeOnPressingEnterEvent(event) {
84+
event.preventDefault()
85+
event.stopPropagation()
86+
87+
this.listenToValueChanges(event?.target?.value ?? event)
88+
},
89+
90+
handleChangesOnBlurEvent(event) {
91+
this.listenToValueChanges(event?.target?.value ?? event)
92+
},
7993
80-
if (this.isReadonly) {
94+
listenToValueChanges(value) {
95+
if (this.isImmutable === true) {
96+
return
97+
}
98+
99+
if (this.isCustomisingValue === true) {
100+
this.value = value
81101
return
82102
}
83103
@@ -91,18 +111,20 @@ export default {
91111
},
92112
93113
toggleCustomizeClick() {
94-
if (this.field.readonly) {
114+
if (this.field.extraAttributes.readonly === true) {
115+
this.isCustomisingValue = true
95116
this.removeChangeListener()
96117
this.isListeningToChanges = false
97-
this.field.readonly = false
118+
this.field.writable = true
98119
this.field.extraAttributes.readonly = false
99120
this.field.showCustomizeButton = false
100121
this.$refs.theInput.focus()
101122
return
102123
}
103124
125+
this.isCustomisingValue = false
104126
this.registerChangeListener()
105-
this.field.readonly = true
127+
this.field.writable = false
106128
this.field.extraAttributes.readonly = true
107129
},
108130
},
@@ -112,6 +134,14 @@ export default {
112134
return this.field.shouldListenToFromChanges
113135
},
114136
137+
isImmutable() {
138+
return Boolean(
139+
this.field.readonly === false &&
140+
this.field.writable === true &&
141+
get(this.field, 'extraAttributes.readonly') === true
142+
)
143+
},
144+
115145
eventName() {
116146
return this.getFieldAttributeChangeEventName(this.field.from)
117147
},

src/Fields/Repeater.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\Nova\Fields;
44

5+
use Illuminate\Support\Arr;
56
use Laravel\Nova\Exceptions\NovaException;
67
use Laravel\Nova\Fields\Repeater\Presets\HasMany;
78
use Laravel\Nova\Fields\Repeater\Presets\JSON;
@@ -288,8 +289,8 @@ protected function replaceRulesPlaceholder(array $rules, string $replaceWith = '
288289
return $rules;
289290
}
290291

291-
return collect($rules)->map(static function ($rules) use ($replacements) {
292-
return collect($rules)->map(static function ($rule) use ($replacements) {
292+
return collect($rules)->map(static function ($fieldRules) use ($replacements) {
293+
return collect(Arr::wrap($fieldRules))->map(static function ($rule) use ($replacements) {
293294
return is_string($rule)
294295
? str_replace(array_keys($replacements), array_values($replacements), $rule)
295296
: $rule;

src/Fields/Slug.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function jsonSerialize(): array
101101
};
102102

103103
if (! is_null($from) && $request->isUpdateOrUpdateAttachedRequest()) {
104-
$this->readonly();
104+
$this->immutable();
105105
$this->showCustomizeButton = true;
106106
}
107107

src/Http/Requests/NovaRequest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Foundation\Http\FormRequest;
66
use Illuminate\Http\Request;
77
use Illuminate\Routing\Route;
8+
use Laravel\Nova\TrashedStatus;
89
use Mockery as m;
910
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
1011

@@ -150,6 +151,18 @@ public function isPresentationRequest(): bool
150151
|| $this->isLensRequest();
151152
}
152153

154+
/**
155+
* Get the trashed status of the request.
156+
*/
157+
public function trashed(): TrashedStatus
158+
{
159+
if (is_null($trashed = $this->trashed)) {
160+
return TrashedStatus::DEFAULT;
161+
}
162+
163+
return TrashedStatus::tryFrom((string) $trashed) ?? TrashedStatus::DEFAULT;
164+
}
165+
153166
/**
154167
* Create an Illuminate request from a Symfony instance.
155168
*/

src/Http/Requests/QueriesResources.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,5 @@ public function orderings(): array
7373
/**
7474
* Get the trashed status of the request.
7575
*/
76-
protected function trashed(): TrashedStatus
77-
{
78-
return TrashedStatus::tryFrom((string) $this->trashed) ?? TrashedStatus::DEFAULT;
79-
}
76+
abstract public function trashed(): TrashedStatus;
8077
}

src/Http/Requests/RestoreLensResourceRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function restorableModels(Collection $models): Collection
3434
/**
3535
* Get the trashed status of the request.
3636
*/
37-
protected function trashed(): TrashedStatus
37+
public function trashed(): TrashedStatus
3838
{
3939
return TrashedStatus::WITH;
4040
}

src/Http/Requests/RestoreResourceRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function restorableModels(Collection $models): Collection
3434
/**
3535
* Get the trashed status of the request.
3636
*/
37-
protected function trashed(): TrashedStatus
37+
public function trashed(): TrashedStatus
3838
{
3939
return TrashedStatus::WITH;
4040
}

src/Http/Resources/LensViewResource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Contracts\Database\Eloquent\Builder;
66
use Laravel\Nova\Http\Requests\LensRequest;
77
use Laravel\Nova\Lenses\Lens;
8-
use Laravel\Nova\TrashedStatus;
98

109
class LensViewResource extends Resource
1110
{
@@ -22,7 +21,7 @@ public function toArray($request)
2221
$query = $request->newSearchQuery();
2322

2423
if ($request->resourceSoftDeletes()) {
25-
(TrashedStatus::tryFrom($request->trashed) ?? TrashedStatus::DEFAULT)->applySoftDeleteConstraint($query);
24+
$request->trashed()->applySoftDeleteConstraint($query);
2625
}
2726

2827
$paginator = $lens->query($request, $query);

src/Notifications/NovaChannel.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\Nova\Notifications;
44

5+
use Illuminate\Contracts\Support\Arrayable;
56
use Illuminate\Notifications\Notification as LaravelNotification;
67
use Illuminate\Support\Facades\Gate;
78
use Illuminate\Support\Str;
@@ -16,17 +17,26 @@ class NovaChannel
1617
*/
1718
public function send($notifiable, LaravelNotification $notification)
1819
{
19-
if (
20-
app()->environment('local') ||
21-
Gate::forUser($notifiable)->check('viewNova')
22-
) {
20+
if ($this->canRun($notifiable) && method_exists($notification, 'toNova')) {
21+
$payload = $notification->toNova($notifiable);
22+
2323
Notification::create([
2424
'id' => Str::orderedUuid(),
2525
'type' => get_class($notification),
2626
'notifiable_id' => $notifiable->getKey(),
2727
'notifiable_type' => $notifiable->getMorphClass(),
28-
'data' => $notification->toNova($notifiable), /** @phpstan-ignore method.notFound */
28+
'data' => $payload instanceof Arrayable ? $payload->toArray() : $payload,
2929
]);
3030
}
3131
}
32+
33+
/**
34+
* Determine if notification should be send to $notifiable.
35+
*
36+
* @param mixed $notifiable
37+
*/
38+
protected function canRun($notifiable): bool
39+
{
40+
return app()->environment('local') || Gate::forUser($notifiable)->check('viewNova');
41+
}
3242
}

src/Notifications/NovaNotification.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace Laravel\Nova\Notifications;
44

5+
use Illuminate\Contracts\Support\Arrayable;
6+
use Illuminate\Notifications\Notification as LaravelNotification;
57
use Laravel\Nova\Exceptions\HelperNotSupported;
68
use Laravel\Nova\Makeable;
79
use Laravel\Nova\Nova;
810
use Laravel\Nova\URL;
911
use Laravel\Nova\WithComponent;
1012
use Stringable;
1113

12-
class NovaNotification extends \Illuminate\Notifications\Notification
14+
class NovaNotification extends LaravelNotification implements Arrayable
1315
{
1416
use Makeable;
1517
use WithComponent;
@@ -167,16 +169,7 @@ public function type(string $type = 'success')
167169
*/
168170
public function toNova()
169171
{
170-
return [
171-
'component' => $this->component(),
172-
'icon' => $this->icon,
173-
'message' => $this->message,
174-
'actionText' => Nova::__($this->actionText),
175-
'actionUrl' => $this->actionUrl,
176-
'openInNewTab' => $this->openInNewTab,
177-
'type' => $this->type,
178-
'iconClass' => static::$types[$this->type],
179-
];
172+
return $this->toArray();
180173
}
181174

182175
/**
@@ -189,4 +182,19 @@ public function via($notifiable)
189182
{
190183
return [NovaChannel::class];
191184
}
185+
186+
/** {@inheritDoc} */
187+
public function toArray()
188+
{
189+
return [
190+
'component' => $this->component(),
191+
'icon' => $this->icon,
192+
'message' => $this->message,
193+
'actionText' => Nova::__($this->actionText),
194+
'actionUrl' => $this->actionUrl,
195+
'openInNewTab' => $this->openInNewTab,
196+
'type' => $this->type,
197+
'iconClass' => static::$types[$this->type],
198+
];
199+
}
192200
}

src/ResolvesFields.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ protected function shouldAddActionsField(NovaRequest $request): Closure
257257
protected function actionEventsField(): MorphMany
258258
{
259259
return MorphMany::make(Nova::__('Action Events'), 'actions', Nova::actionResource())
260-
->canSee(static fn ($request) => Nova::actionResource()::authorizedToViewAny($request));
260+
->canSee(static fn ($request) => Nova::actionResource()::authorizedToViewAny($request))
261+
->collapsable();
261262
}
262263

263264
/**

0 commit comments

Comments
 (0)