Skip to content

Commit 2c4d7be

Browse files
committed
feat(datasets): add Atom feed button to search results
Move Atom feed link from page to SearchPage component as requested. Uses BrandedButton with RiRssLine icon, positioned next to sort control. URL built from nonFalsyParams for reactive filter support. Requires opendatateam/udata#3578 for filter support on the Atom endpoint.
1 parent 4b741a8 commit 2c4d7be

File tree

2 files changed

+53
-69
lines changed

2 files changed

+53
-69
lines changed

components/Datasets/SearchPage.vue

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -185,33 +185,43 @@
185185
>
186186
{{ t("{count} résultats | {count} résultat | {count} résultats", searchResults.total) }}
187187
</p>
188-
<div class="fr-col-auto fr-grid-row fr-grid-row--middle">
189-
<label
190-
for="sort-search"
191-
class="fr-col-auto text-sm m-0 mr-2"
192-
>
193-
{{ t('Trier par :') }}
194-
</label>
195-
<div class="fr-col">
196-
<select
197-
id="sort-search"
198-
v-model="searchSort"
199-
class="fr-select !shadow-input-blue"
200-
name="sort"
201-
@change="currentPage = 1"
188+
<div class="fr-col-auto fr-grid-row fr-grid-row--middle gap-4">
189+
<div class="fr-grid-row fr-grid-row--middle">
190+
<label
191+
for="sort-search"
192+
class="fr-col-auto text-sm m-0 mr-2"
202193
>
203-
<option value="">
204-
{{ t('Pertinence') }}
205-
</option>
206-
<option
207-
v-for="{ value, label } in sortOptions"
208-
:key="label"
209-
:value="value"
194+
{{ t('Trier par :') }}
195+
</label>
196+
<div class="fr-col">
197+
<select
198+
id="sort-search"
199+
v-model="searchSort"
200+
class="fr-select !shadow-input-blue"
201+
name="sort"
202+
@change="currentPage = 1"
210203
>
211-
{{ label }}
212-
</option>
213-
</select>
204+
<option value="">
205+
{{ t('Pertinence') }}
206+
</option>
207+
<option
208+
v-for="{ value, label } in sortOptions"
209+
:key="label"
210+
:value="value"
211+
>
212+
{{ label }}
213+
</option>
214+
</select>
215+
</div>
214216
</div>
217+
<BrandedButton
218+
:href="atomFeedUrl"
219+
:icon="RiRssLine"
220+
:title="t('Flux Atom de cette recherche')"
221+
color="secondary"
222+
size="sm"
223+
external
224+
/>
215225
</div>
216226
</div>
217227
<transition mode="out-in">
@@ -280,7 +290,7 @@
280290
import { BrandedButton, getLink, getOrganizationTypes, LoadingBlock, Pagination, OTHER, USER } from '@datagouv/components-next'
281291
import type { DatasetV2, License, Organization, OrganizationTypes, RegisteredSchema, TranslatedBadge, OrganizationOrSuggest } from '@datagouv/components-next'
282292
import { ref, computed, type Component } from 'vue'
283-
import { RiCloseCircleLine, RiDownloadLine } from '@remixicon/vue'
293+
import { RiCloseCircleLine, RiDownloadLine, RiRssLine } from '@remixicon/vue'
284294
import { computedAsync, debouncedRef, useUrlSearchParams } from '@vueuse/core'
285295
import SearchInput from '~/components/Search/SearchInput.vue'
286296
import type { PaginatedArray, SpatialGranularity, SpatialZone, Tag } from '~/types/types'
@@ -320,6 +330,12 @@ const nonFalsyParams = computed(() => {
320330
return { ...propsParams, ...Object.fromEntries(filteredParams), page_size: pageSize }
321331
})
322332
333+
const atomFeedUrl = computed(() => {
334+
const { page, page_size, ...feedParams } = nonFalsyParams.value
335+
const query = new URLSearchParams(feedParams).toString()
336+
return `${config.public.apiBase}/api/1/datasets/recent.atom${query ? `?${query}` : ''}`
337+
})
338+
323339
const { data: searchResults, status: searchResultsStatus, refresh } = await useAPI<PaginatedArray<DatasetV2>>('/api/2/datasets/search/', {
324340
params: nonFalsyParams,
325341
lazy: true,

pages/datasets/search.vue

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,18 @@
1111
</BreadcrumbItem>
1212
</Breadcrumb>
1313

14-
<div class="flex justify-between items-start">
15-
<div>
16-
<h1 class="text-gray-title font-extrabold text-2xl mb-2">
17-
{{ $t('Jeux de données') }}
18-
</h1>
19-
<p
20-
v-if="site"
21-
class="block mb-3"
22-
>
23-
{{ $t('Rechercher parmi les {count} jeux de données sur {site}', {
24-
count: site.metrics.datasets,
25-
site: config.public.title,
26-
}) }}
27-
</p>
28-
</div>
29-
<a
30-
:href="`${config.public.apiBase}/api/1/datasets/recent.atom`"
31-
class="flex items-center gap-1 text-sm text-blue-500 hover:text-blue-700"
32-
:title="$t('Flux Atom de cette recherche')"
33-
@click.prevent="openRss"
34-
>
35-
<svg
36-
xmlns="http://www.w3.org/2000/svg"
37-
class="h-4 w-4"
38-
viewBox="0 0 24 24"
39-
fill="currentColor"
40-
>
41-
<circle
42-
cx="6.18"
43-
cy="17.82"
44-
r="2.18"
45-
/>
46-
<path d="M4 4.44v2.83c7.03 0 12.73 5.7 12.73 12.73h2.83c0-8.59-6.97-15.56-15.56-15.56zm0 5.66v2.83c3.9 0 7.07 3.17 7.07 7.07h2.83c0-5.47-4.43-9.9-9.9-9.9z" />
47-
</svg>
48-
RSS
49-
</a>
50-
</div>
14+
<h1 class="text-gray-title font-extrabold text-2xl mb-2">
15+
{{ $t('Jeux de données') }}
16+
</h1>
17+
<p
18+
v-if="site"
19+
class="block mb-3"
20+
>
21+
{{ $t('Rechercher parmi les {count} jeux de données sur {site}', {
22+
count: site.metrics.datasets,
23+
site: config.public.title,
24+
}) }}
25+
</p>
5126

5227
<DatasetsSearchPage />
5328
</div>
@@ -64,12 +39,5 @@ useSeoMeta({
6439
6540
const config = useRuntimeConfig()
6641
67-
function openRss() {
68-
const searchParams = window.location.search
69-
const baseUrl = `${config.public.apiBase}/api/1/datasets/recent.atom`
70-
const url = searchParams ? `${baseUrl}${searchParams}` : baseUrl
71-
window.open(url, '_blank')
72-
}
73-
7442
const { data: site } = await useAPI<Site>('/api/1/site/')
7543
</script>

0 commit comments

Comments
 (0)