major ui updates
This commit is contained in:
@@ -12,7 +12,6 @@ use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Livewire\WithFileUploads;
|
||||
use Modules\Helpdesk\Models\Comment;
|
||||
use Modules\Helpdesk\Models\Priority;
|
||||
use Modules\Helpdesk\Models\Status;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
@@ -145,36 +144,39 @@ final class TicketShow extends Component
|
||||
'team',
|
||||
'attachments.user',
|
||||
'gitCommits.repository',
|
||||
'comments.attachments',
|
||||
'comments.replies.attachments',
|
||||
'comments.replies.replies.attachments',
|
||||
]) ?? $ticket;
|
||||
|
||||
$comments = Comment::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->with(['user', 'attachments'])
|
||||
->oldest()
|
||||
->get();
|
||||
$comments = $ticket->comments
|
||||
->merge($ticket->comments->flatMap->replies)
|
||||
->merge($ticket->comments->flatMap->replies->flatMap->replies);
|
||||
|
||||
$grouped = $comments->groupBy('parent_id');
|
||||
$users = User::query()
|
||||
->whereIn('id', $comments->pluck('user_id')->filter()->unique())
|
||||
->get()
|
||||
->keyBy('id');
|
||||
|
||||
$comments->each(function ($comment) use ($grouped): void {
|
||||
$comment->setRelation('replies', $grouped->get($comment->id, collect()));
|
||||
});
|
||||
|
||||
$ticket->setRelation('comments', $this->buildCommentTree($grouped));
|
||||
$this->attachCommentUsers($ticket->comments, $users);
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
private function buildCommentTree($grouped, ?int $parentId = null)
|
||||
|
||||
/**
|
||||
* Attach loaded users to comment hierarchy without triggering lazy loading.
|
||||
*
|
||||
* @param Collection<int, mixed> $comments
|
||||
* @param Collection<int, User> $users
|
||||
*/
|
||||
private function attachCommentUsers(Collection $comments, Collection $users): void
|
||||
{
|
||||
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, $comment->id));
|
||||
|
||||
return $comment;
|
||||
|
||||
});
|
||||
|
||||
if ($comment->relationLoaded('replies')) {
|
||||
$this->attachCommentUsers($comment->replies, $users);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user