Skip to content

Commit

Permalink
Merge pull request #204 from Lakshan-Madushanka/master
Browse files Browse the repository at this point in the history
Display the related count next to the issue's label
  • Loading branch information
ash-jc-allen authored Aug 21, 2024
2 parents 905e488 + 85cad88 commit 55ead90
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
46 changes: 45 additions & 1 deletion app/Livewire/ListIssues.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Livewire;

use App\DataTransferObjects\Issue;
use App\DataTransferObjects\Label;
use App\DataTransferObjects\Repository;
use App\Exceptions\GitHubRateLimitException;
use App\Services\IssueService;
Expand Down Expand Up @@ -88,7 +89,6 @@ public function mount(): void
{
$this->setSortOrderOnPageLoad();

$this->labels = config('repos.labels');
$this->repos = app(RepoService::class)->reposToCrawl()->sort();

try {
Expand All @@ -102,11 +102,17 @@ public function mount(): void

public function render(): View
{
$this->initialiseLabels();

$issues = $this->originalIssues
->filter(fn (Issue $issue): bool => $this->showIgnoredIssues === in_array($issue->url, $this->ignoredUrls, true))
->when($this->searchTerm, $this->applySearch())
->when($this->sort, $this->applySort());

foreach ($issues as $issue) {
$this->incrementLabelCounts($issue);
}

return view('livewire.list-issues', [
'issues' => $issues,
'sorts' => self::SORTS,
Expand Down Expand Up @@ -169,4 +175,42 @@ private function setSortOrderOnPageLoad(): void
->first();
}
}

/**
* Initialise each of the labels with counts of 0.
*
* @return void
*/
private function initialiseLabels(): void
{
foreach (config('repos.labels') as $label) {
$this->labels[$label] = 0;
}
}

/**
* Loop through each of the labels on the issue and increment the count
* for each label that we're tracking in Find A PR.
*
* @param Issue $issue
* @return void
*/
private function incrementLabelCounts(Issue $issue): void
{
foreach ($issue->labels as $label) {
if (!$this->isValidLabel($label)) {
continue;
}

$this->labels[$label->name]++;
}
}

/**
* Assert whether the label is one that we're tracking in Find A PR.
*/
private function isValidLabel(Label $label): bool
{
return array_key_exists($label->name, $this->labels);
}
}
7 changes: 4 additions & 3 deletions resources/views/components/side-bar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ class="w-full rounded-md border border-gray-300 shadow-sm px-2 py-2 bg-white tex
<p class="text-gray-400 text-sm">({{ count($labels) }})</p>
</div>

@foreach($labels as $label)
@foreach($labels as $name => $count)
<div>
<p class="inline-block items-center px-3 py-1 my-0.5 rounded text-xs font-bold border bg-gray-400 dark:bg-gray-600 text-white">
{{ $label }}
<p class="inline-block items-center px-3 py-1 my-0.5 space-x-1 rounded text-xs font-bold border bg-gray-400 dark:bg-gray-600 text-white">
<span>{{ $name }}</span>
<span>({{$count}})</span>
</p>
</div>
@endforeach
Expand Down

0 comments on commit 55ead90

Please sign in to comment.