Skip to content

Commit

Permalink
Fix order activity timeline blank entries (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
wychoong authored Jan 12, 2024
1 parent f7919a4 commit faeb6db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 23 additions & 2 deletions packages/core/src/Base/Traits/LogsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Lunar\Base\Traits;

use Illuminate\Support\Arr;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity as SpatieLogsActivity;

trait LogsActivity
{
use SpatieLogsActivity;

public static array $logExcept = [];

/**
* Get the log options for the activity log.
*/
Expand All @@ -17,7 +20,25 @@ public function getActivitylogOptions(): LogOptions
return LogOptions::defaults()
->useLogName('lunar')
->logAll()
->dontSubmitEmptyLogs()
->logExcept(['updated_at']);
->logExcept(array_merge(['updated_at'], static::getActivitylogExcept()))
->logOnlyDirty()
->dontSubmitEmptyLogs();
}

public static function addActivitylogExcept(array|string $fields)
{
$fields = Arr::wrap($fields);

static::$logExcept = array_merge(static::$logExcept, $fields);
}

public static function getDefaultLogExcept(): array
{
return [];
}

public static function getActivitylogExcept(): array
{
return array_merge(static::getDefaultLogExcept(), static::$logExcept);
}
}
7 changes: 7 additions & 0 deletions packages/core/src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,11 @@ public function isPlaced(): bool
{
return ! blank($this->placed_at);
}

public static function getDefaultLogExcept(): array
{
return [
'status',
];
}
}

1 comment on commit faeb6db

@vercel
Copy link

@vercel vercel bot commented on faeb6db Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.