Skip to content

Commit

Permalink
Merge pull request #47 from noxoua/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
noxoua authored Nov 21, 2023
2 parents a7be7d2 + 6dd3878 commit d1c6535
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 80 deletions.
13 changes: 13 additions & 0 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ $logger->fields([
->keyValue(differenceOnly: true)
->label('Attributes'),
])
```

#### Key-Value with fields
```php
$logger->fields([
Field::make('recipient')
->hasOne('recipient')
->keyValue([
Field::make('recipient.full_name'),
Field::make('recipient.phone'),
Field::make('recipient.shipping_provider'),
]),
])
```

![Screenshot](./assets/images/key-value-screenshot.png)
Expand Down
2 changes: 1 addition & 1 deletion resources/dist/filament-activity-log.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions resources/views/components/badge.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasLabel;
use Filament\Support\Contracts\HasIcon;
$isHtmlAllowed = $field->isHtmlAllowed();
@endphp

<div class="flex flex-wrap gap-2">
Expand All @@ -10,8 +12,13 @@
<x-filament::badge
:color="$field->badgeColor"
class="w-fit"
:tooltip="$label"
>
{{ $label }}
@if ($isHtmlAllowed)
{!! $label !!}
@else
{{ $label }}
@endif
</x-filament::badge>
@endforeach
@elseif($field->is('enum'))
Expand All @@ -25,16 +32,25 @@ class="w-fit"
:color="$color"
:icon="$icon"
class="w-fit"
:tooltip="$label"
>
{{ $label }}
@if ($isHtmlAllowed)
{!! $label !!}
@else
{{ $label }}
@endif
</x-filament::badge>
@else
<x-filament::badge
:color="$field->badgeColor"
class="w-fit"
:tooltip="$value"
>
{{ $value }}
@if ($isHtmlAllowed)
{!! $value !!}
@else
{{ $value }}
@endif
</x-filament::badge>
@endif

</div>
18 changes: 16 additions & 2 deletions resources/views/components/default.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
@php
$isHtmlAllowed = $field->isHtmlAllowed();
@endphp

@if (is_array($value))
<pre class="text-xs text-gray-500">{{ json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) }}</pre>
<pre class="text-xs text-gray-500">
@if ($isHtmlAllowed)
{!! json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) !!}
@else
{{ $value }}
{{ json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) }}
@endif
</pre>
@else
@if ($isHtmlAllowed)
{!! $value !!}
@else
{{ $value }}
@endif
@endif
75 changes: 59 additions & 16 deletions resources/views/components/key-value.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
<div class="rounded-lg shadow-sm bg-gray-50 dark:bg-transparent ring-1 ring-gray-950/10 dark:ring-white/20">
<table class="w-full table-auto">
<tbody class="divide-y divide-gray-200 dark:divide-white/20">
@foreach ((array) $value as $key => $_value)
<tr class="divide-x divide-gray-200 dark:divide-white/20 rtl:divide-x-reverse">
<td class="font-mono text-xs p-2">
{{ $key }}
</td>
@if (!empty($value))
@php
$hasFields = $field->keyValue instanceof \Noxo\FilamentActivityLog\ResourceLogger\Types\KeyValueField;
if ($hasFields) {
$fields = $field->keyValue->getFields();
}
$isHtmlAllowed = $field->isHtmlAllowed();
@endphp

<td class="font-mono text-xs p-2">
{{ $_value }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>

<div class="rounded-lg shadow-sm bg-gray-50 dark:bg-transparent ring-1 ring-gray-950/10 dark:ring-white/20">
<table class="w-full table-auto truncate">
@if ($hasFields)
<tbody class="divide-y divide-gray-200 dark:divide-white/20">
@foreach ($fields as $key => $keyValueField)
@php
if (!array_key_exists($keyValueField->name, $value)) {
continue;
}
$rawValue = $value[$keyValueField->name];
$dispayValue = $keyValueField->display($rawValue);
@endphp

<tr class="divide-x divide-gray-200 dark:divide-white/20 rtl:divide-x-reverse">
<td class="font-mono text-xs p-2 w-[1%] whitespace-nowrap">
{{ $keyValueField->getLabel() }}
</td>

<td class="font-mono text-xs p-2 truncate max-w-0">
@if ($isHtmlAllowed)
{!! $dispayValue !!}
@else
{{ $dispayValue }}
@endif
</td>
</tr>
@endforeach
</tbody>
@else
<tbody class="divide-y divide-gray-200 dark:divide-white/20">
@foreach ((array) $value as $key => $_value)
<tr class="divide-x divide-gray-200 dark:divide-white/20 rtl:divide-x-reverse">
<td class="font-mono text-xs p-2 w-[1%] whitespace-nowrap">
{{ $key }}
</td>

<td class="font-mono text-xs p-2 truncate max-w-0">
@if ($isHtmlAllowed)
{!! $_value !!}
@else
{{ $_value }}
@endif
</td>
</tr>
@endforeach
</tbody>
@endif
</table>
</div>
@endif
54 changes: 36 additions & 18 deletions resources/views/components/table.blade.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
@if (!empty($value))
<x-filament-tables::table class="w-full overflow-hidden text-sm">
<x-slot:header>
@foreach (array_keys($value[0]) as $key)
<x-filament-tables::header-cell class="!py-2">
{{ $key }}
</x-filament-tables::header-cell>
@endforeach
</x-slot:header>
@php
$fields = $field->table->getFields();
$isHtmlAllowed = $field->isHtmlAllowed();
@endphp

<div class="w-full overflow-x-scroll border border-gray-200 dark:border-white/5 rounded-lg">
<x-filament-tables::table>
<x-slot:header>
<x-filament-tables::row>
@foreach ($fields as $field)
<x-filament-tables::header-cell class="!p-2">
{{ $field->getLabel() }}
</x-filament-tables::header-cell>
@endforeach
</x-filament-tables::row>
</x-slot:header>


@foreach ($value as $item)
<x-filament-tables::row @class(['bg-gray-100/30 dark:bg-gray-900' => $loop->even])>
@foreach ($item as $_value)
<x-filament-tables::cell class="px-4 py-2 align-top sm:first-of-type:ps-6 sm:last-of-type:pe-6">
{{ $_value }}
</x-filament-tables::cell>
@endforeach
</x-filament-tables::row>
@endforeach
</x-filament-tables::table>
@foreach ($value as $item)
<x-filament-tables::row @class(['bg-gray-100/30 dark:bg-gray-900/20' => $loop->even])>
@foreach ($fields as $field)
<x-filament-tables::cell class="p-2 align-top">
@php
$rawValue = $item[$field->name] ?? data_get($item, $field->name);
$dispayValue = $field->display($rawValue);
@endphp

@if ($isHtmlAllowed)
{!! $dispayValue !!}
@else
{{ $dispayValue }}
@endif
</x-filament-tables::cell>
@endforeach
</x-filament-tables::row>
@endforeach
</x-filament-tables::table>
</div>
@endif
32 changes: 16 additions & 16 deletions resources/views/list/tables/default.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<x-filament-tables::table class="w-full overflow-hidden text-sm">
<x-filament-tables::table class="w-full overflow-hidden text-sm !table-fixed">
<x-slot:header>
<x-filament-tables::header-cell class="!py-2">
<x-filament-tables::header-cell
width="20%"
class="!py-2"
>
@lang('filament-activity-log::activities.table.field')
</x-filament-tables::header-cell>
<x-filament-tables::header-cell class="!py-2">
<x-filament-tables::header-cell
width="40%"
class="!py-2"
>
@lang('filament-activity-log::activities.table.old')
</x-filament-tables::header-cell>
<x-filament-tables::header-cell class="!py-2">
<x-filament-tables::header-cell
width="40%"
class="!py-2"
>
@lang('filament-activity-log::activities.table.new')
</x-filament-tables::header-cell>
</x-slot:header>
Expand All @@ -22,10 +31,7 @@
@endphp

<x-filament-tables::row @class(['bg-gray-100/30 dark:bg-gray-900' => $loop->even])>
<x-filament-tables::cell
width="20%"
class="px-4 py-2 align-top sm:first-of-type:ps-6 sm:last-of-type:pe-6"
>
<x-filament-tables::cell class="px-4 py-2 align-top sm:first-of-type:ps-6 sm:last-of-type:pe-6">
{{ $field->getLabel() }}
</x-filament-tables::cell>

Expand All @@ -41,17 +47,11 @@ class="px-4 py-2 align-top break-all !whitespace-normal"
]) }}
</x-filament-tables::cell>
@else
<x-filament-tables::cell
width="40%"
class="px-4 py-2 align-top break-all !whitespace-normal"
>
<x-filament-tables::cell class="px-4 py-2 align-top overflow-x-scroll">
{{ $field->display($oldValue) }}
</x-filament-tables::cell>

<x-filament-tables::cell
width="40%"
class="px-4 py-2 align-top break-all !whitespace-normal"
>
<x-filament-tables::cell class="px-4 py-2 align-top overflow-x-scroll">
{{ $field->display($newValue) }}
</x-filament-tables::cell>
@endif
Expand Down
22 changes: 11 additions & 11 deletions resources/views/list/tables/simple.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<x-filament-tables::table class="w-full overflow-hidden text-sm">
<x-filament-tables::table class="w-full overflow-hidden text-sm !table-fixed">
<x-slot:header>
<x-filament-tables::header-cell class="!py-2">
<x-filament-tables::header-cell
width="20%"
class="!py-2"
>
@lang('filament-activity-log::activities.table.field')
</x-filament-tables::header-cell>
<x-filament-tables::header-cell class="!py-2">
<x-filament-tables::header-cell
width="80%"
class="!py-2"
>
@lang('filament-activity-log::activities.table.value')
</x-filament-tables::header-cell>
</x-slot:header>
Expand All @@ -17,17 +23,11 @@
@endphp

<x-filament-tables::row @class(['bg-gray-100/30 dark:bg-gray-900' => $loop->even])>
<x-filament-tables::cell
width="20%"
class="px-4 py-2 align-top sm:first-of-type:ps-6 sm:last-of-type:pe-6"
>
<x-filament-tables::cell class="px-4 py-2 align-top sm:first-of-type:ps-6 sm:last-of-type:pe-6">
{{ $field->getLabel() }}
</x-filament-tables::cell>

<x-filament-tables::cell
width="40%"
class="px-4 py-2 align-top break-all !whitespace-normal"
>
<x-filament-tables::cell class="px-4 py-2 align-top overflow-x-scroll">
{{ $field->display($value) }}
</x-filament-tables::cell>
</x-filament-tables::row>
Expand Down
5 changes: 3 additions & 2 deletions src/Loggers/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public function __construct(Model $newModel = null, Model $oldModel = null)
*/
public function through(Closure $callback): static
{
$callback(clone $this->oldModel);
$callback(clone $this->newModel);

$this->newModel = $this->oldModel->fresh();
$this->oldModel = clone $this->newModel;
$this->newModel->refresh();

return $this;
}
Expand Down
Loading

0 comments on commit d1c6535

Please sign in to comment.