Skip to content

Commit b1da212

Browse files
committed
add jsonentry
1 parent f8f7ed5 commit b1da212

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry" :id="$getId()">
2+
<div {{ \Filament\Support\prepare_inherited_attributes($getExtraAttributeBag())
3+
->class(['code-editor-textarea relative overflow-hidden'])
4+
}}
5+
>
6+
<div class="code-editor-textarea-wrapper-ctn overflow-auto"
7+
@theme-changed.window="(e) => toggleTheme(
8+
e.detail === 'system' ? window.matchMedia('(prefers-color-scheme: dark)').matches : e.detail === 'dark'
9+
)"
10+
x-data="codeEditorFormComponent({
11+
state: @js($getState()),
12+
isReadOnly: true,
13+
isDarkMode: (Alpine.store('theme') || 'light') === 'system' ? window.matchMedia('(prefers-color-scheme: dark)').matches : (Alpine.store('theme') || 'light') === 'dark',
14+
})"
15+
x-load
16+
x-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-code-editor', 'solution-forest/inspirecms') }}"
17+
x-load-css="[@js(\Filament\Support\Facades\FilamentAsset::getStyleHref('filament-code-editor', package: 'solution-forest/inspirecms'))]"
18+
>
19+
<div wire:ignore
20+
x-ref="codeEditor"
21+
@class([
22+
'code-editor-textarea-wrapper',
23+
'w-full overflow-hidden',
24+
])
25+
>
26+
</div>
27+
</div>
28+
</div>
29+
</x-dynamic-component>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace SolutionForest\InspireCms\Filament\Infolists\Components;
4+
5+
use Filament\Infolists\Components\Entry;
6+
7+
class JsonEntry extends Entry
8+
{
9+
protected string $view = 'inspirecms::filament.infolists.components.json-entry';
10+
11+
public function getState(): mixed
12+
{
13+
$state = parent::getState();
14+
15+
if (is_array($state) || is_object($state)) {
16+
return json_encode($state, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
17+
}
18+
19+
return $state;
20+
}
21+
}

src/Filament/Resources/ExportResource.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -118,43 +118,19 @@ public static function infolist(Infolist $infolist): Infolist
118118
->label(__('inspirecms::resources/export.exporter.label'))
119119
->inlineLabel(),
120120

121-
Infolists\Components\TextEntry::make('process_message')
121+
\SolutionForest\InspireCms\Filament\Infolists\Components\JsonEntry::make('message')
122122
->label(__('inspirecms::resources/export.message.label'))
123-
->columnSpanFull()
124-
->size('xs')->color('gray')
125-
->extraAttributes([
126-
'class' => 'bg-gray-100 dark:bg-gray-800 rounded-md p-2 overflow-x-auto',
127-
])
128123
->getStateUsing(function ($record) {
129124
$payload = $record->payload;
130125
if (! is_array($payload)) {
131126
return '';
132127
}
133-
$arr = Arr::except($payload, ['result']);
134128

135-
return str(json_encode($arr, JSON_PRETTY_PRINT))->wrap('<code>', '</code>')->wrap('<pre>', '</pre>')->toHtmlString();
129+
return Arr::except($payload, ['result']);
136130
}),
137131

138-
Infolists\Components\TextEntry::make('result')
139-
->label(__('inspirecms::resources/export.result.label'))
140-
->columnSpanFull()
141-
->size('xs')->color('gray')
142-
->extraAttributes([
143-
'class' => 'bg-gray-100 dark:bg-gray-800 rounded-md p-2 overflow-x-auto',
144-
])
145-
->html()
146-
->getStateUsing(function ($record) {
147-
$payload = $record->payload;
148-
if (! is_array($payload)) {
149-
return '';
150-
}
151-
$arr = $payload['result'] ?? [];
152-
if (! is_array($arr)) {
153-
$arr = [$arr];
154-
}
155-
156-
return str(json_encode($arr, JSON_PRETTY_PRINT))->wrap('<code>', '</code>')->wrap('<pre>', '</pre>')->toHtmlString();
157-
}),
132+
\SolutionForest\InspireCms\Filament\Infolists\Components\JsonEntry::make('payload.result')
133+
->label(__('inspirecms::resources/export.result.label')),
158134
]),
159135
]);
160136
}

src/Filament/Resources/ImportResource.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,9 @@ public static function infolist(Infolist $infolist): Infolist
116116
))
117117
->copyable()->copyableState(fn ($record) => $record->author?->email),
118118

119-
Infolists\Components\TextEntry::make('payload')
120-
->label(__('inspirecms::resources/import.payload.label'))
119+
\SolutionForest\InspireCms\Filament\Infolists\Components\JsonEntry::make('payload')
121120
->columnSpanFull()
122-
->size('xs')->color('gray')
123-
->extraAttributes([
124-
'class' => 'bg-gray-100 dark:bg-gray-800 rounded-md p-2 overflow-x-auto',
125-
])
126-
->getStateUsing(function ($record) {
127-
$payload = $record->payload;
128-
if (! is_array($payload)) {
129-
return '';
130-
}
131-
132-
return str(json_encode($payload, JSON_PRETTY_PRINT))->wrap('<code>', '</code>')->wrap('<pre>', '</pre>')->toHtmlString();
133-
}),
121+
->label(__('inspirecms::resources/import.payload.label')),
134122
]);
135123
}
136124

0 commit comments

Comments
 (0)