Skip to content

Commit b1405bb

Browse files
feat(datasets): add Atom feed link to search page (#828)
Add a link to the datasets Atom feed on the search page. The link includes current search filters, allowing users to subscribe to filtered search results via their RSS reader. Requires opendatateam/udata#3578 for filter support on the Atom endpoint. --------- Co-authored-by: Nicolas KEMPF <[email protected]>
1 parent 9f61364 commit b1405bb

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

components/Datasets/SearchPage.vue

Lines changed: 43 additions & 27 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">
@@ -284,7 +294,7 @@
284294
import { BrandedButton, getLink, getOrganizationTypes, LoadingBlock, Pagination, OTHER, USER, toast } from '@datagouv/components-next'
285295
import type { DatasetV2, License, Organization, OrganizationTypes, RegisteredSchema, TranslatedBadge, OrganizationOrSuggest } from '@datagouv/components-next'
286296
import { ref, computed, type Component } from 'vue'
287-
import { RiCloseCircleLine, RiDownloadLine } from '@remixicon/vue'
297+
import { RiCloseCircleLine, RiDownloadLine, RiRssLine } from '@remixicon/vue'
288298
import { computedAsync, debouncedRef, useUrlSearchParams } from '@vueuse/core'
289299
import SearchInput from '~/components/Search/SearchInput.vue'
290300
import type { PaginatedArray, SpatialGranularity, SpatialZone, Tag } from '~/types/types'
@@ -317,10 +327,16 @@ const params = useUrlSearchParams<DatasetSearchParams>('history', {
317327
removeFalsyValues: true,
318328
})
319329
320-
const nonFalsyParams = computed(() => {
330+
const nonFalsyParams = computed<DatasetSearchParams>(() => {
321331
const filteredParams = Object.entries(toValue(params)).filter(([_k, v]) => v)
322332
const propsParams = props.organization ? { organization: props.organization.id } : {}
323-
return { ...propsParams, ...Object.fromEntries(filteredParams), page_size: pageSize }
333+
return { ...propsParams, ...Object.fromEntries(filteredParams) as DatasetSearchParams, page_size: pageSize.toFixed(0) }
334+
})
335+
336+
const atomFeedUrl = computed(() => {
337+
const { page, page_size, ...feedParams } = nonFalsyParams.value
338+
const query = new URLSearchParams(feedParams).toString()
339+
return `${config.public.apiBase}/api/1/datasets/recent.atom${query ? `?${query}` : ''}`
324340
})
325341
326342
const { data: searchResults, status: searchResultsStatus, refresh } = await useAPI<PaginatedArray<DatasetV2>>('/api/2/datasets/search/', {

0 commit comments

Comments
 (0)