Skip to content

Commit 039859a

Browse files
authored
fix(ui): draw the search and inherited-node labels with the shared badge (#1328)
The newer-version, snapshot and repository labels of a search result and the "overridden" marker of an inherited node were hand-built spans with their own height, radius and colours. They now use the shared badge, so they match every other status label. Signed-off-by: TheMeinerLP <github@themeinerlp.dev>
1 parent a1cc36a commit 039859a

4 files changed

Lines changed: 53 additions & 15 deletions

File tree

‎reposilite-frontend/src/components/access/nodes/NodeEditor.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
// @vitest-environment jsdom
1818

19+
import MdBadge from '../../md/MdBadge.vue'
1920
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
2021
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
2122
import NodeEditor from './NodeEditor.vue'
@@ -771,6 +772,13 @@ describe('NodeEditor', () => {
771772
expect(rows[1].find('[data-test="inherited-overridden"]').exists(), 'held directly').toBe(true)
772773
})
773774

775+
it('draws the overridden marker as a shared badge', () => {
776+
mountEditor({ inherited: INHERITED() })
777+
778+
const badges = wrapper.findAllComponents(MdBadge).filter(badge => badge.attributes('data-test') === 'inherited-overridden')
779+
expect(badges.length, 'the marker is an md-badge').toBe(1)
780+
})
781+
774782
it('is open to start with', () => {
775783
mountEditor({ inherited: INHERITED() })
776784

‎reposilite-frontend/src/components/access/nodes/NodeInheritedSection.vue‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<script setup lang="ts">
1818
import { ref, useId, type PropType } from 'vue'
19+
import MdBadge from '../../md/MdBadge.vue'
1920
import MdList from '../../md/MdList.vue'
2021
import MdListItem from '../../md/MdListItem.vue'
2122
import type { InheritedEntry } from './inheritedNodes'
@@ -115,11 +116,13 @@ const regionId = `inherited-${useId()}`
115116
>
116117
{{ inheritedSourceLabel(entry) }}
117118
</p>
118-
<span
119+
<MdBadge
119120
v-if="isOverridden(entry, direct)"
120-
class="mt-1 inline-block rounded-corner-small bg-surface-container-highest px-2 py-1 md-label-small text-on-surface-variant"
121+
class="mt-1"
121122
data-test="inherited-overridden"
122-
>Overridden by a direct node</span>
123+
>
124+
Overridden by a direct node
125+
</MdBadge>
123126
<template #trailing>
124127
<span
125128
class="md-label-large"

‎reposilite-frontend/src/components/search/SearchResultRow.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { describe, it, expect } from 'vitest'
1818
import { mount } from '@vue/test-utils'
1919
import { createMemoryHistory, createRouter } from 'vue-router'
2020
import SearchResultRow from './SearchResultRow.vue'
21+
import MdBadge from '../md/MdBadge.vue'
2122
import type { SearchItem } from './searchResult'
2223

2324
const shell = { render: () => null }
@@ -47,4 +48,27 @@ describe('SearchResultRow', () => {
4748
expect(button.attributes('href'), 'it stays a link').toBe('/releases/org/example/tool/1.0.0')
4849
wrapper.unmount()
4950
})
51+
52+
it('draws the newer version, the snapshot flag and the repositories as shared badges', () => {
53+
const wrapper = mount(SearchResultRow, {
54+
props: {
55+
item: {
56+
...item(),
57+
latestVersion: '2.0.0',
58+
snapshot: true,
59+
repositories: [
60+
{ name: 'releases', origin: 'LOCAL' },
61+
{ name: 'central', origin: 'MIRROR' }
62+
]
63+
} as SearchItem
64+
},
65+
global: { stubs: { RouterLink: true } }
66+
})
67+
68+
const badges = wrapper.findAllComponents(MdBadge)
69+
70+
expect(badges.map(badge => badge.attributes('data-tone')), 'one badge per label, tinted by its meaning')
71+
.toEqual(['hosted', 'neutral', 'neutral', 'accent'])
72+
wrapper.unmount()
73+
})
5074
})

‎reposilite-frontend/src/components/search/SearchResultRow.vue‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<script setup lang="ts">
1818
import { computed, useId } from 'vue'
1919
import { RouterLink } from 'vue-router'
20+
import MdBadge from '../md/MdBadge.vue'
2021
import MdButton from '../md/MdButton.vue'
2122
import MdIconButton from '../md/MdIconButton.vue'
2223
import { formatDay, formatSize, repositoryLabel } from './searchResult'
@@ -114,26 +115,28 @@ const sourceOf = (file: SearchFile) => (file.origin === 'MIRROR'
114115
</button>
115116

116117
<div class="flex flex-wrap items-center gap-2 pl-10 md-body-medium text-on-surface-variant">
117-
<span
118+
<MdBadge
118119
v-if="hasNewer"
120+
tone="hosted"
119121
data-test="newer"
120-
class="inline-flex h-6 items-center rounded-corner-small bg-tertiary-container px-2 md-label-medium text-on-tertiary-container"
121-
>Newer: {{ item.latestVersion }}</span>
122-
<span
122+
>
123+
Newer: {{ item.latestVersion }}
124+
</MdBadge>
125+
<MdBadge
123126
v-if="item.snapshot"
124127
data-test="snapshot"
125-
class="inline-flex h-6 items-center rounded-corner-small border border-outline px-2 md-label-medium text-on-surface"
126-
>Snapshot</span>
127-
<span
128+
>
129+
Snapshot
130+
</MdBadge>
131+
<MdBadge
128132
v-for="repository in item.repositories"
129133
:key="`${repository.name}:${repository.origin}`"
134+
:tone="repository.origin === 'MIRROR' ? 'accent' : 'neutral'"
130135
data-test="repository"
131136
:data-origin="repository.origin"
132-
class="inline-flex h-6 items-center rounded-corner-small px-2 md-label-medium"
133-
:class="repository.origin === 'MIRROR'
134-
? 'bg-secondary-container text-on-secondary-container'
135-
: 'border border-outline text-on-surface'"
136-
>{{ repositoryLabel(repository) }}</span>
137+
>
138+
{{ repositoryLabel(repository) }}
139+
</MdBadge>
137140
<span data-test="file-count">{{ fileCount }}</span>
138141
<span
139142
v-if="item.lastModified"

0 commit comments

Comments
 (0)