-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor notification summary handling to use Summary value object #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,22 @@ | ||
| @component('mail::message') | ||
| # {{ __($summary['message'] ?? 'You have new notifications', $summary['properties'] ?? []) }} | ||
| @if ($summary->title) | ||
| # {{ __($summary->title, $summary->data) }} | ||
| @endif | ||
|
|
||
| {{ __($summary->message, $summary->data) }} | ||
|
|
||
| @component('mail::table') | ||
| | # | Notification | | ||
| | # | @lang('Notification') | | ||
| | - | ----------- | | ||
| @foreach ($items as $index => $item) | ||
| | {{ $index + 1 }} | [{{ __($item['message'] ?? '', $item['properties'] ?? []) }}]({{ $item['url'] ?? '#' }}) | | ||
| | {{ $index + 1 }} | [{{ __($item['message'] ?? '', $item['data'] ?? []) }}]({{ $item['url'] ?? '#' }}) | | ||
| @endforeach | ||
| @endcomponent | ||
|
|
||
| @component('mail::button', ['url' => $summary['url'] ?? '/']) | ||
| View | ||
| @if ($summary->actionText) | ||
| @component('mail::button', ['url' => $summary->actionUrl]) | ||
| @lang($summary->actionText) | ||
|
Comment on lines
+16
to
+18
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mimicking Laravel :) |
||
| @endcomponent | ||
| @endif | ||
|
|
||
| @endcomponent | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <?php | ||
|
|
||
| namespace TestMonitor\Floodgate\Notifications; | ||
|
|
||
| use Illuminate\Contracts\Support\Arrayable; | ||
| use Illuminate\Support\Traits\Conditionable; | ||
|
|
||
| class Summary implements Arrayable | ||
| { | ||
| use Conditionable; | ||
|
|
||
| /** | ||
| * The title displayed above the summary message. | ||
| */ | ||
| public ?string $title = null; | ||
|
|
||
| /** | ||
| * The summary message, using the same :placeholder syntax as toArray(). | ||
| */ | ||
| public string $message = ''; | ||
|
|
||
| /** | ||
| * The replacement values for the message's :placeholders. | ||
| */ | ||
| public array $data = []; | ||
|
|
||
| /** | ||
| * The mail subject. | ||
| */ | ||
| public ?string $subject = null; | ||
|
|
||
| /** | ||
| * The text for the summary mail's call-to-action button. | ||
| */ | ||
| public ?string $actionText = null; | ||
|
|
||
| /** | ||
| * The URL for the summary mail's call-to-action button. | ||
| */ | ||
| public ?string $actionUrl = null; | ||
|
|
||
| /* | ||
| * Set the title displayed above the summary message. | ||
| */ | ||
| public function title(string $title): static | ||
| { | ||
| $this->title = $title; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /* | ||
| * Set the summary message, using the same :placeholder syntax as toArray(). | ||
| */ | ||
| public function message(string $message): static | ||
| { | ||
| $this->message = $message; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /* | ||
| * Merge additional replacement values for the message's :placeholders. | ||
| */ | ||
| public function with(array|string $key, mixed $value = null): static | ||
| { | ||
| if (is_array($key)) { | ||
| $this->data = array_merge($this->data, $key); | ||
| } else { | ||
| $this->data[$key] = $value; | ||
| } | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /* | ||
| * Set the mail subject. | ||
| */ | ||
| public function subject(string $subject): static | ||
| { | ||
| $this->subject = $subject; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /* | ||
| * Set the call-to-action button's text and URL. | ||
| */ | ||
| public function action(string $text, string $url): static | ||
| { | ||
| $this->actionText = $text; | ||
| $this->actionUrl = $url; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /* | ||
| * Return the summary as an array, suitable for the database channel. | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| return array_filter([ | ||
| 'title' => $this->title, | ||
| 'message' => $this->message, | ||
| 'data' => $this->data, | ||
| 'url' => $this->actionUrl, | ||
| ], fn ($value) => ! is_null($value)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ehm... no...