Skip to main content

AI & workflows

Ai Repo List code

Copy the implementation or inspect every file that belongs to this component unit.

resources/views/components/ui/ai-repo-list.blade.php

@props([
    'repositories' => [],
    'selectedSlug' => null,
    'title' => 'Repositories',
    'navigate' => false,
    'embedded' => false,
])

@php
    /*
    | Dashboard list of git repositories connected to agent workflows.
    |
    | Usage:
    |   <x-ui.ai-repo-list navigate :repositories="[
    |       ['slug' => 'components', 'name' => 'components', 'owner' => 'laravel', 'defaultBranch' => 'main', 'updatedAt' => '2h ago'],
    |   ]" />
    */
    $itemClass = fn (bool $isSelected): string => \Illuminate\Support\Arr::toCssClasses([
        'flex flex-col gap-2 px-4 py-3 transition sm:flex-row sm:items-center sm:justify-between sm:px-5',
        'bg-brand-50/70 dark:bg-brand-950/20' => $isSelected,
        'hover:bg-gray-50 dark:hover:bg-gray-950/60' => $navigate && ! $isSelected,
    ]);

    $visibilityVariants = [
        'public' => 'green',
        'private' => 'gray',
    ];

    $normalizedRepositories = collect($repositories)
        ->map(function ($repository) {
            return [
                'slug' => $repository['slug'] ?? '',
                'name' => $repository['name'] ?? 'repository',
                'owner' => $repository['owner'] ?? 'org',
                'description' => $repository['description'] ?? null,
                'visibility' => $repository['visibility'] ?? 'private',
                'defaultBranch' => $repository['defaultBranch'] ?? 'main',
                'language' => $repository['language'] ?? null,
                'branchCount' => (int) ($repository['branchCount'] ?? 0),
                'updatedAt' => $repository['updatedAt'] ?? null,
                'href' => $repository['href'] ?? null,
            ];
        })
        ->filter(fn (array $repository) => $repository['slug'] !== '')
        ->values()
        ->all();
@endphp

<div {{ $attributes->merge(['class' => $embedded ? 'min-w-0' : 'min-w-0 overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm dark:border-gray-800 dark:bg-gray-900']) }}>
    @unless ($embedded)
        <div class="border-b border-gray-200 px-4 py-4 dark:border-gray-800 sm:px-5">
            <p class="text-sm font-semibold text-gray-900 dark:text-white">{{ $title }}</p>
            <p class="text-xs text-gray-500 dark:text-gray-400">{{ count($normalizedRepositories) }} repositories</p>
        </div>
    @endunless

    <ul @class(['divide-y divide-gray-200 dark:divide-gray-800', 'border-t border-gray-200 dark:border-gray-800' => $embedded]) role="list">
        @forelse ($normalizedRepositories as $repository)
            @php
                $isSelected = $selectedSlug === $repository['slug'];
            @endphp
            <li>
                @if ($navigate && $repository['href'])
                    <a href="{{ $repository['href'] }}" @class([$itemClass($isSelected), 'block'])>
                        <div class="min-w-0 flex-1">
                            <p class="truncate text-sm font-medium text-gray-900 dark:text-white">{{ $repository['owner'] }}/{{ $repository['name'] }}</p>
                            @if ($repository['description'])
                                <p class="mt-0.5 line-clamp-2 text-xs text-gray-500 dark:text-gray-400">{{ $repository['description'] }}</p>
                            @endif
                            <div class="mt-1 flex flex-wrap items-center gap-2 text-xs text-gray-500 dark:text-gray-400">
                                @if ($repository['language'])
                                    <span>{{ $repository['language'] }}</span>
                                @endif
                                <span class="hidden text-gray-300 sm:inline dark:text-gray-600">·</span>
                                <span>{{ $repository['branchCount'] }} branches</span>
                                @if ($repository['updatedAt'])
                                    <span class="hidden text-gray-300 sm:inline dark:text-gray-600">·</span>
                                    <span>{{ $repository['updatedAt'] }}</span>
                                @endif
                            </div>
                        </div>

                        <div class="flex shrink-0 flex-wrap items-center gap-2">
                            <x-ui.badge :variant="$visibilityVariants[$repository['visibility']] ?? 'gray'" size="sm">
                                {{ ucfirst($repository['visibility']) }}
                            </x-ui.badge>
                            <x-ui.badge variant="outline" size="sm">{{ $repository['defaultBranch'] }}</x-ui.badge>
                        </div>
                    </a>
                @else
                    <div @class($itemClass($isSelected))>
                        <div class="min-w-0 flex-1">
                            <p class="truncate text-sm font-medium text-gray-900 dark:text-white">{{ $repository['owner'] }}/{{ $repository['name'] }}</p>
                            @if ($repository['description'])
                                <p class="mt-0.5 line-clamp-2 text-xs text-gray-500 dark:text-gray-400">{{ $repository['description'] }}</p>
                            @endif
                        </div>

                        <x-ui.badge :variant="$visibilityVariants[$repository['visibility']] ?? 'gray'" size="sm">
                            {{ ucfirst($repository['visibility']) }}
                        </x-ui.badge>
                    </div>
                @endif
            </li>
        @empty
            <li class="px-4 py-6 text-sm text-gray-500 dark:text-gray-400 sm:px-5">No repositories connected.</li>
        @endforelse
    </ul>
</div>