22 <div class =" position-relative project-group-picker" ref =" pickerRef" @focusout =" onFocusOut" >
33 <input
44 v-model =" searchText"
5+ :id =" props.id"
56 type =" text"
67 class =" form-select"
78 :disabled =" props.disabled"
2223 Showing first {{ projectGroups.length }} of {{ totalCount }} project groups
2324 <span v-if =" hasMore && !loading" class =" pg-scroll-hint" >· ; Scroll to continue loading</span >
2425 </template >
25- <template v-else-if =" ! hasMore " >Showing all {{ projectGroups.length }} project group{{ projectGroups.length !== 1 ? 's' : '' }}</template >
26+ <template v-else-if =" ! showScrollHint " >Showing all {{ projectGroups.length }} project group{{ projectGroups.length !== 1 ? 's' : '' }}</template >
2627 <template v-else >
2728 Showing first {{ projectGroups.length }} results
2829 <span v-if =" !loading" class =" pg-scroll-hint" >· ; Scroll to continue loading</span >
3233 </div >
3334 <div
3435 class =" pg-list-wrap"
35- :class =" { 'pg-has-more': hasMore && !loading }"
36+ :class =" { 'pg-has-more': showScrollHint && !loading }"
3637 ref =" listRef"
3738 @scroll =" onScroll"
3839 >
@@ -88,8 +89,9 @@ import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
8889import { tdeiUserClient } from ' ~/services/index'
8990import type { TdeiProjectGroupItem } from ' ~/types/tdei'
9091
91- const props = withDefaults (defineProps <{ disabled? : boolean ; options? : TdeiProjectGroupItem [] }>(), {
92+ const props = withDefaults (defineProps <{ id ? : string ; disabled? : boolean ; options? : TdeiProjectGroupItem []; rememberSelection ? : boolean }>(), {
9293 disabled: false ,
94+ rememberSelection: false ,
9395})
9496
9597const model = defineModel ({ required: true })
@@ -104,6 +106,7 @@ const listRef = ref<HTMLElement | null>(null)
104106const activeIndex = ref (- 1 )
105107
106108const projectGroups = computed (() => props .options ?? fetchedGroups .value )
109+ const showScrollHint = computed (() => ! props .options && hasMore .value )
107110
108111let pageNo = 1
109112const hasMore = ref (true )
@@ -143,7 +146,9 @@ const loadGroups = async (reset = false) => {
143146 if (total !== undefined ) totalCount .value = total
144147 fetchedGroups .value .push (... newGroups )
145148 const selected = newGroups .find (g => g .tdei_project_group_id === model .value )
146- if (selected ) persistCachedName (selected .tdei_project_group_id , selected .name )
149+ if (selected && props .rememberSelection ) {
150+ persistCachedName (selected .tdei_project_group_id , selected .name )
151+ }
147152
148153 if (newGroups .length < pageSize ) {
149154 hasMore .value = false
@@ -204,7 +209,9 @@ const selectGroup = (id: string) => {
204209 if (pg ) {
205210 searchText .value = pg .name
206211 selectedGroupName .value = pg .name
207- persistCachedName (pg .tdei_project_group_id , pg .name )
212+ if (props .rememberSelection ) {
213+ persistCachedName (pg .tdei_project_group_id , pg .name )
214+ }
208215 }
209216}
210217
@@ -295,7 +302,7 @@ watch(
295302 (groups ) => {
296303 if (groups .length > 0 ) {
297304 const pgId = model .value as string | undefined
298- if (! pgId || ! groups .some (pg => pg .tdei_project_group_id === pgId )) {
305+ if (! pgId || ( props . options && ! groups .some (pg => pg .tdei_project_group_id === pgId ) )) {
299306 model .value = groups [0 ]?.tdei_project_group_id
300307 }
301308 const selected = groups .find (pg => pg .tdei_project_group_id === model .value )
@@ -310,7 +317,7 @@ watch(
310317
311318onMounted (async () => {
312319 // Show cached name immediately before the API call completes
313- if (model .value && loadCachedName (model .value as string )) {
320+ if (props . rememberSelection && model .value && loadCachedName (model .value as string )) {
314321 applyCachedName ()
315322 }
316323
@@ -322,7 +329,7 @@ onMounted(async () => {
322329 if (selected ) {
323330 searchText .value = selected .name
324331 selectedGroupName .value = selected .name
325- } else if (model .value && loadCachedName (model .value as string )) {
332+ } else if (props . rememberSelection && model .value && loadCachedName (model .value as string )) {
326333 // Group is beyond page 1 — use the cached name for display
327334 applyCachedName ()
328335 } else if (model .value ) {
0 commit comments