Optimierung 2.1: Admin-PM-Editoren nutzen Tags-Trait

Admin create/edit nutzen jetzt InteractsWithPressReleaseTags (wie die
Customer-Editoren) statt die byte-gleiche addTag/removeTag/tagsArray-Logik
lokal zu duplizieren. ~48 Zeilen je Datei entfernt.

Tests: 259 PressRelease-Tests gruen.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-19 08:32:41 +00:00
parent 554a731a24
commit 0344ac26af
2 changed files with 4 additions and 100 deletions

View file

@ -19,6 +19,8 @@ use Livewire\Attributes\Title;
use Livewire\Volt\Component;
new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class extends Component {
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
public string $portal = 'presseecho';
public string $language = 'de';
@ -110,39 +112,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
$this->resetErrorBag('title');
}
public function addTag(string $tag): void
{
$tag = trim($tag);
if ($tag === '') {
return;
}
$existing = $this->tagsArray();
if (count($existing) >= 5) {
return;
}
if (in_array($tag, $existing, true)) {
return;
}
$existing[] = $tag;
$this->keywords = implode(', ', $existing);
unset($this->tags, $this->presubmitChecks);
}
public function removeTag(string $tag): void
{
$existing = array_values(array_filter($this->tagsArray(), fn(string $existingTag): bool => $existingTag !== $tag));
$this->keywords = implode(', ', $existing);
unset($this->tags, $this->presubmitChecks);
}
/**
* Single Source of Truth für die Validierungsregeln. Ermöglicht
* Live-Re-Validation via updated()-Hook ohne Duplikation.
@ -424,23 +393,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
];
}
/**
* @return list<string>
*/
private function tagsArray(): array
{
if (trim($this->keywords) === '') {
return [];
}
return collect(explode(',', $this->keywords))
->map(fn(string $tag): string => trim($tag))
->filter()
->unique()
->values()
->all();
}
private function defaultContactIdFor(int $companyId): ?int
{
if ($companyId <= 0) {

View file

@ -24,6 +24,8 @@ use Livewire\Attributes\Title;
use Livewire\Volt\Component;
new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] class extends Component {
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
#[Locked]
public int $id;
@ -159,39 +161,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
unset($this->presubmitChecks);
}
public function addTag(string $tag): void
{
$tag = trim($tag);
if ($tag === '') {
return;
}
$existing = $this->tagsArray();
if (count($existing) >= 5) {
return;
}
if (in_array($tag, $existing, true)) {
return;
}
$existing[] = $tag;
$this->keywords = implode(', ', $existing);
unset($this->tags, $this->presubmitChecks);
}
public function removeTag(string $tag): void
{
$existing = array_values(array_filter($this->tagsArray(), fn(string $existingTag): bool => $existingTag !== $tag));
$this->keywords = implode(', ', $existing);
unset($this->tags, $this->presubmitChecks);
}
/**
* @return array<string, array<int, mixed>>
*/
@ -611,23 +580,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
];
}
/**
* @return list<string>
*/
private function tagsArray(): array
{
if (trim($this->keywords) === '') {
return [];
}
return collect(explode(',', $this->keywords))
->map(fn(string $tag): string => trim($tag))
->filter()
->unique()
->values()
->all();
}
private function defaultContactIdFor(int $companyId): ?int
{
if ($companyId <= 0) {