Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions frontend/app/components/shared/layout/search/search-result.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ SPDX-License-Identifier: MIT

<!-- Repositories -->
<div
v-if="tab === 'all' && props.repositories.length > 0"
v-if="tab === 'all' && repositories.length > 0"
class="pt-3 px-3 text-xs font-semibold leading-5 text-neutral-400"
>
Repositories
</div>
<section
v-if="tab === 'all' || (tab === 'repositories' && props.repositories.length > 0)"
v-if="tab === 'all' || (tab === 'repositories' && repositories.length > 0)"
class="flex flex-col gap-1"
>
<nuxt-link
v-for="repository of props.repositories"
v-for="repository of repositories"
:key="repository.slug"
:to="{
name: LfxRoutes.REPOSITORY,
Expand All @@ -102,7 +102,7 @@ SPDX-License-Identifier: MIT
</nuxt-link>
</section>
<section
v-if="tab === 'repositories' && props.repositories.length === 0"
v-if="tab === 'repositories' && repositories.length === 0"
class="px-3 py-12 flex flex-col items-center"
>
<lfx-icon
Expand Down Expand Up @@ -180,6 +180,7 @@ import LfxAvatar from '~/components/uikit/avatar/avatar.vue';
import LfxIcon from '~/components/uikit/icon/icon.vue';
import { LfxRoutes } from '~/components/shared/types/routes';
import LfxArchivedTag from '~/components/shared/components/archived-tag.vue';
import { normalizeRepoName } from '~/components/shared/utils/helper';

const props = defineProps<{
projects: SearchProject[];
Expand All @@ -193,6 +194,18 @@ const tab = ref('all');

const noResult = computed(() => !props.projects.length && !props.repositories.length && !props.collections.length);

const repositories = computed(() =>
Comment thread
joanagmaia marked this conversation as resolved.
props.repositories.map((repository) => ({
...repository,
name: normalizeRepoName({
...repository,
url: repository.name,
score: 0,
rank: 0,
Comment thread
joanagmaia marked this conversation as resolved.
}),
})),
);

const tabs = [
{
value: 'all',
Expand Down
16 changes: 10 additions & 6 deletions frontend/app/components/shared/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ export const isElementVisible = (element: HTMLElement) => {
export const normalizeRepoName = (repo: ProjectRepository): string => {
try {
const url = new URL(repo.url);
const { hostname } = url;
const pathParts = url.pathname.split('/').filter(Boolean);

// return last 2 segments (owner/repo)
if (pathParts.length > 2) {
return pathParts.slice(-2).join('/');
if (!pathParts.length) {
return repo.name;
}

// Fallback: return repo name or last path segment
return pathParts[pathParts.length - 1] || repo.name;
// GitHub, GitLab and Git repos: always show owner/repo (last 2 path segments)
if (hostname === 'github.com' || hostname === 'gitlab' || hostname === 'git.') {
return pathParts.length >= 2 ? pathParts.slice(-2).join('/') : pathParts[0] || '';
}

// For all other platforms (Gerrit): show full path after domain
return pathParts.join('/');
} catch {
// If URL parsing fails, return the repo name as fallback
return repo.name;
}
};