Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Data/NotificationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ final class NotificationData extends Data
{
public function __construct(
public string $title,
public NotificationLevel $level,
public ?NotificationLevel $level,
public ?string $message,
public bool $autoHide,
) {}

public static function from(array $notification): self
{
return new self(
title: $notification['title'],
level: NotificationLevel::tryFrom($notification['level']),
message: $notification['message'] ?? null,
autoHide: $notification['autoHide'] ?? true,
);
}
}
12 changes: 7 additions & 5 deletions src/EntityList/Commands/Wizards/IsWizardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ trait IsWizardCommand
protected function getWizardContext(): WizardCommandContext
{
if (! $this->wizardCommandContext) {
$this->wizardCommandContext = session()->get(sprintf('CWC.%s.%s', get_class($this), $this->getKey()));
if (! $this->wizardCommandContext) {
$this->wizardCommandContext = new WizardCommandContext();
}
$context = session()->get(sprintf('CWC.%s.%s', get_class($this), $this->getKey()));
$this->wizardCommandContext = match (true) {
$context instanceof WizardCommandContext => $context,
is_array($context) => WizardCommandContext::fromArray($context),
default => new WizardCommandContext(),
};
}

return $this->wizardCommandContext;
Expand All @@ -29,7 +31,7 @@ protected function getWizardContext(): WizardCommandContext
protected function toStep(string $step): array
{
if ($this->wizardCommandContext) {
session()->put(sprintf('CWC.%s.%s', get_class($this), $this->getKey()), $this->wizardCommandContext);
session()->put(sprintf('CWC.%s.%s', get_class($this), $this->getKey()), $this->wizardCommandContext->toArray());
}

return [
Expand Down
21 changes: 19 additions & 2 deletions src/EntityList/Commands/Wizards/WizardCommandContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Code16\Sharp\EntityList\Commands\Wizards;

use Code16\Sharp\Exceptions\Commands\SharpInvalidStepException;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Validation\Factory as Validator;

class WizardCommandContext
class WizardCommandContext implements Arrayable
{
protected array $attributes = [];
public function __construct(
protected array $attributes = [],
) {}

public function setCurrentStep(string $step): self
{
Expand Down Expand Up @@ -42,4 +45,18 @@ class_basename(get_class($this)),
);
}
}

public static function fromArray(array $data): static
{
return new static(
attributes: $data['attributes'] ?? [],
);
}

public function toArray(): array
{
return [
'attributes' => $this->attributes,
];
}
}
10 changes: 5 additions & 5 deletions src/Utils/SharpNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(string $title)

$notifications[$this->id] = [
'title' => $title,
'level' => NotificationLevel::Info,
'level' => NotificationLevel::Info->value,
'message' => null,
'autoHide' => true,
];
Expand All @@ -33,28 +33,28 @@ public function setDetail(string $detail): self
public function setLevelSuccess(): self
{
return $this->update([
'level' => NotificationLevel::Success,
'level' => NotificationLevel::Success->value,
]);
}

public function setLevelInfo(): self
{
return $this->update([
'level' => NotificationLevel::Info,
'level' => NotificationLevel::Info->value,
]);
}

public function setLevelWarning(): self
{
return $this->update([
'level' => NotificationLevel::Warning,
'level' => NotificationLevel::Warning->value,
]);
}

public function setLevelDanger(): self
{
return $this->update([
'level' => NotificationLevel::Danger,
'level' => NotificationLevel::Danger->value,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Http/UpdateAssetsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
$notifications = session('sharp_notifications');
$notification = collect($notifications)->first();
expect($notification['title'])->toBe('Assets updated successfully')
->and($notification['level']->value)->toBe('success');
->and($notification['level'])->toBe('success');
});
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function defineEnvironment($app): void
$app['config']->set('view.cache', false);
$app['config']->set('inertia.testing.page_paths', [__DIR__.'/../resources/js/Pages']);
$app['config']->set('database.default', 'testing');
$app['config']->set('session.serialization', 'json');

$app['view']->addNamespace('fixtures', __DIR__.'/Fixtures/resources/views');

Expand Down
Loading