Aded documentation module

This commit is contained in:
Mark Gregory
2026-06-12 15:32:09 +01:00
parent a2c68bc4dc
commit 1c9ed1a537
18 changed files with 418 additions and 85 deletions
+17 -23
View File
@@ -73,6 +73,7 @@ final class TicketShow extends Component
$this->reset(['commentBody', 'internal', 'attachments']);
$this->ticket = $this->freshTicket($this->ticket);
$this->dispatch('helpdesk-editor-reset', model: 'commentBody');
$this->dispatch('helpdesk-comment-added');
}
@@ -87,8 +88,9 @@ final class TicketShow extends Component
$tickets->comment($this->ticket, Auth::user(), $this->replyBody, $this->internal, [], $this->reply_parent_id);
$this->cancelReply();
$this->reset(['reply_parent_id', 'replyBody']);
$this->ticket = $this->freshTicket($this->ticket);
$this->dispatch('helpdesk-editor-reset', model: 'replyBody');
$this->dispatch('helpdesk-reply-added');
}
@@ -144,39 +146,31 @@ final class TicketShow extends Component
'team',
'attachments.user',
'gitCommits.repository',
'comments.attachments',
'comments.replies.attachments',
'comments.replies.replies.attachments',
]) ?? $ticket;
$comments = $ticket->comments
->merge($ticket->comments->flatMap->replies)
->merge($ticket->comments->flatMap->replies->flatMap->replies);
$comments = \Modules\Helpdesk\Models\Comment::query()
->where('ticket_id', $ticket->id)
->with(['user', 'attachments.user'])
->oldest()
->get();
$users = User::query()
->whereIn('id', $comments->pluck('user_id')->filter()->unique())
->get()
->keyBy('id');
$this->attachCommentUsers($ticket->comments, $users);
$ticket->setRelation('comments', $this->buildCommentTree($comments->groupBy('parent_id')));
return $ticket;
}
/**
* Attach loaded users to comment hierarchy without triggering lazy loading.
* Build an unlimited nested comment tree from a flat eager-loaded collection.
*
* @param Collection<int, mixed> $comments
* @param Collection<int, User> $users
* @param Collection<int|string, Collection<int, mixed>> $grouped
* @return Collection<int, mixed>
*/
private function attachCommentUsers(Collection $comments, Collection $users): void
private function buildCommentTree(Collection $grouped, ?int $parentId = null): Collection
{
foreach ($comments as $comment) {
$comment->setRelation('user', $users->get($comment->user_id));
return $grouped->get($parentId, collect())->map(function ($comment) use ($grouped) {
$comment->setRelation('replies', $this->buildCommentTree($grouped, (int) $comment->id));
if ($comment->relationLoaded('replies')) {
$this->attachCommentUsers($comment->replies, $users);
}
}
return $comment;
})->values();
}
}