11<script setup lang="ts">
2- import { ref , watch } from ' vue'
2+ import { computed , onMounted , ref , watch } from ' vue'
33import { useI18n } from ' vue-i18n'
4- import { useRouter } from ' vue-router'
4+ import { useRoute , useRouter } from ' vue-router'
55import { api , apiFetch , ensureOk , unwrap , type Schemas } from ' @/api/client'
66import PageHeader from ' @/components/common/PageHeader.vue'
77import { useApiAction , useErrorText } from ' @/composables/useApiAction'
@@ -11,9 +11,10 @@ import { formatDateTime } from '@/utils/format'
1111
1212type Summary = Schemas [' StageSummary' ] | Schemas [' PipelineSummary' ]
1313
14- /** Lista de Etapas ou Trilhas (spec 008): busca, filtro por status, versão publicada, uso; Autor cria e importa. */
14+ /** Lista de Etapas ou Trilhas (spec 008): busca, filtro por status (e por trilha, nas Etapas) , versão publicada, uso; Autor cria e importa. */
1515const props = defineProps <{ kind: ' stages' | ' pipelines' }>()
1616const { t } = useI18n ()
17+ const route = useRoute ()
1718const router = useRouter ()
1819const session = useSession ()
1920const notify = useNotify ()
@@ -31,6 +32,13 @@ const createError = ref<string | null>(null)
3132const draft = ref ({ key: ' ' , name: ' ' , description: ' ' })
3233const importing = ref (false )
3334
35+ // Filtro "Trilha" das Etapas (D-164, D-165): só as Etapas da última versão publicada da trilha, na ordem dos passos.
36+ // Fica na URL (`?trilha=`) para o link poder ser compartilhado.
37+ const queryPipeline = () => (props .kind === ' stages' && typeof route .query .trilha === ' string' && route .query .trilha ) || null
38+ const pipelineKey = ref <string | null >(queryPipeline ())
39+ const pipelines = ref <Schemas [' PipelineSummary' ][]>([])
40+ const selectedPipeline = computed (() => pipelines .value .find ((p ) => p .key === pipelineKey .value ) ?? null )
41+
3442const headers = [
3543 { title: t (' catalog.key' ), key: ' key' , sortable: false },
3644 { title: t (' catalog.name' ), key: ' name' , sortable: false },
@@ -49,7 +57,7 @@ async function load() {
4957 }
5058 const result = await run (() =>
5159 props .kind === ' stages'
52- ? unwrap (api .GET (' /stages' , { params: { query } }))
60+ ? unwrap (api .GET (' /stages' , { params: { query: { ... query , pipelineKey: pipelineKey . value ?? undefined } } }))
5361 : unwrap (api .GET (' /pipelines' , { params: { query } })),
5462 )
5563 if (result ) {
@@ -70,6 +78,41 @@ watch(search, () => {
7078 }, 300 )
7179})
7280watch ([status , page , pageSize ], () => void load (), { immediate: true })
81+ watch (pipelineKey , (key ) => {
82+ void router .replace ({ query: { ... route .query , trilha: key ?? undefined } })
83+ if (page .value === 1 ) {
84+ void load ()
85+ } else {
86+ page .value = 1
87+ }
88+ })
89+ watch (
90+ () => route .query .trilha ,
91+ () => {
92+ if (queryPipeline () !== pipelineKey .value ) {
93+ pipelineKey .value = queryPipeline ()
94+ }
95+ },
96+ )
97+
98+ async function loadPipelines() {
99+ const all: Schemas [' PipelineSummary' ][] = []
100+ for (let number = 1 ; ; number ++ ) {
101+ const result = await unwrap (api .GET (' /pipelines' , { params: { query: { page: number , pageSize: 100 } } }))
102+ all .push (... result .items )
103+ if (result .items .length === 0 || all .length >= result .total ) {
104+ break
105+ }
106+ }
107+
108+ pipelines .value = all
109+ }
110+
111+ onMounted (() => {
112+ if (props .kind === ' stages' ) {
113+ void run (loadPipelines )
114+ }
115+ })
73116
74117const detailRoute = (key : string ) => ({ name: props .kind === ' stages' ? ' stage' : ' pipeline' , params: { key } })
75118
@@ -156,7 +199,27 @@ function usedBy(item: Summary) {
156199 hide-details
157200 style =" max-width : 220px "
158201 />
202+ <v-autocomplete
203+ v-if =" kind === 'stages'"
204+ v-model =" pipelineKey"
205+ :items =" pipelines.map((p) => ({ value: p.key, title: p.name }))"
206+ :label =" t('catalog.pipeline')"
207+ clearable
208+ hide-details
209+ style =" max-width : 320px "
210+ data-testid =" pipeline-filter"
211+ />
159212 </v-card-text >
213+ <v-alert
214+ v-if =" selectedPipeline && !selectedPipeline.latestPublishedVersion"
215+ type =" info"
216+ variant =" tonal"
217+ density =" compact"
218+ class =" mx-4 mb-2"
219+ data-testid =" pipeline-unpublished"
220+ >
221+ {{ t('catalog.pipelineUnpublished') }}
222+ </v-alert >
160223 <v-data-table-server
161224 v-model:page =" page"
162225 v-model:items-per-page =" pageSize"
0 commit comments