99 "limit" : 10 ,
1010 "created_after" : " " ,
1111 "created_before" : " " ,
12- "triage" : " "
12+ "triage" : " " ,
13+ "survey" : " "
1314 }
1415 }
1516}
1920import { computed , watch } from " vue"
2021import { useApiFetch } from " ../utils/data-fetching.ts"
2122import type { ResponseDisplay } from " @shared-types/response"
23+ import type { SurveyDisplay } from " @shared-types/api"
2224import { useRouter , useRoute } from " vue-router"
2325import ProgressSpinner from " ../components/ProgressSpinner.vue"
2426import PaginationSizeSelect from " ../components/ResponseListPage/PaginationSizeSelect.vue"
@@ -36,12 +38,14 @@ const createdBefore = computed(
3638 () => (route .query .created_before as string ) ?? " "
3739)
3840const ordering = computed (() => route .query .triage as string )
41+ const surveyFilter = computed (() => (route .query .survey as string ) ?? " " )
3942
4043const filterParams = computed (() => {
4144 const params = new URLSearchParams ()
4245 if (createdAfter .value ) params .set (" created_after" , createdAfter .value )
4346 if (createdBefore .value ) params .set (" created_before" , createdBefore .value )
4447 if (ordering .value ) params .set (" ordering" , String (ordering .value ))
48+ if (surveyFilter .value ) params .set (" survey" , surveyFilter .value )
4549 return params
4650})
4751
@@ -62,7 +66,11 @@ const exportCsvUrl = computed(() => {
6266 return ` ${base }/responses/export/csv/${q ? ` ?${q } ` : " " } `
6367})
6468
65- type PaginatedResponse = { count: number ; results: ResponseDisplay [] }
69+ type PaginatedResponse = {
70+ count: number
71+ results: ResponseDisplay []
72+ surveys: SurveyDisplay []
73+ }
6674
6775const { data, execute, isFetching } = useApiFetch (url )
6876 .get ()
@@ -122,6 +130,7 @@ const updateCreatedAfter = (value: string) =>
122130const updateCreatedBefore = (value : string ) =>
123131 updateQuery ({ created_before: value , page: 1 })
124132const updateOrdering = (value : string ) => updateQuery ({ triage: value })
133+ const updateSurvey = (value : string ) => updateQuery ({ survey: value , page: 1 })
125134
126135const exportJson = () => {
127136 window .location .href = exportJsonUrl .value
@@ -130,7 +139,10 @@ const exportCsv = () => {
130139 window .location .href = exportCsvUrl .value
131140}
132141
133- watch ([page , limit , createdAfter , createdBefore , ordering ], fetchSearchResults )
142+ watch (
143+ [page , limit , createdAfter , createdBefore , ordering , surveyFilter ],
144+ fetchSearchResults
145+ )
134146 </script >
135147
136148<template >
@@ -139,12 +151,30 @@ watch([page, limit, createdAfter, createdBefore, ordering], fetchSearchResults)
139151 :links =" [{ to: '/dashboard', text: 'Dashboard' }, { text: 'Réponses' }]"
140152 />
141153 <div class =" filters border mb-2 rounded border-gray-300 p-4 flex gap-8" >
142- <DateRangeFilter
143- :created-after =" createdAfter"
144- :created-before =" createdBefore"
145- @update:created-after =" updateCreatedAfter"
146- @update:created-before =" updateCreatedBefore"
147- />
154+ <div >
155+ <DateRangeFilter
156+ class =" mb-3"
157+ :created-after =" createdAfter"
158+ :created-before =" createdBefore"
159+ @update:created-after =" updateCreatedAfter"
160+ @update:created-before =" updateCreatedBefore"
161+ />
162+ <DsfrInputGroup >
163+ <DsfrSelect
164+ label =" Enquête"
165+ :model-value =" surveyFilter"
166+ :options =" [
167+ { value: '', text: 'Toutes les enquêtes' },
168+ ...(data?.surveys ?? []).map((s) => ({
169+ value: String(s.id),
170+ text: s.title,
171+ })),
172+ ]"
173+ class =" text-sm!"
174+ @update:modelValue =" updateSurvey"
175+ />
176+ </DsfrInputGroup >
177+ </div >
148178 <div class =" flex flex-col gap-4" >
149179 <PaginationSizeSelect
150180 :modelValue =" limit"
0 commit comments