-
Notifications
You must be signed in to change notification settings - Fork 1
Bug-3566: Add searchable project group picker and TDEI fixes #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,256 @@ | ||
| <template> | ||
| <select | ||
| v-model="model" | ||
| class="project-group-picker form-select" | ||
| aria-label="Project Group Selection" | ||
| > | ||
| <option | ||
| v-for="pg in projectGroups" | ||
| :key="pg.id" | ||
| :value="pg.id" | ||
| <div class="position-relative project-group-picker" ref="pickerRef"> | ||
| <input | ||
| v-model="searchText" | ||
| type="text" | ||
| class="form-select" | ||
| :disabled="props.disabled" | ||
| placeholder="Search project groups..." | ||
| @focus="onFocus" | ||
| @keydown="onKeydown" | ||
| /> | ||
| <ul | ||
| v-if="isOpen" | ||
| ref="listRef" | ||
| class="list-group position-absolute w-100 mt-1 shadow bg-white" | ||
| style="z-index: 1000; max-height: 250px; overflow-y: auto;" | ||
| @scroll="onScroll" | ||
| @mousedown.prevent | ||
| > | ||
| {{ pg.name }} | ||
| </option> | ||
| </select> | ||
| <li | ||
| v-if="projectGroups.length === 0 && !loading" | ||
| class="list-group-item text-muted" | ||
| > | ||
| No project groups found. | ||
| </li> | ||
| <li | ||
| v-for="(pg, index) in projectGroups" | ||
| :key="pg.id" | ||
| :id="'pg-item-' + index" | ||
| class="list-group-item list-group-item-action cursor-pointer" | ||
| :class="{ highlighted: activeIndex === index, 'fw-bold': model === pg.id }" | ||
| @click="selectGroup(pg.id)" | ||
| @mouseenter="activeIndex = index" | ||
| > | ||
| {{ pg.name }} | ||
| </li> | ||
| <li v-if="loading" class="list-group-item text-center"> | ||
| <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue' | ||
| import { tdeiUserClient } from '~/services/index' | ||
|
|
||
| const props = withDefaults(defineProps<{ disabled?: boolean }>(), { | ||
| disabled: false, | ||
| }) | ||
|
|
||
| const model = defineModel({ required: true }) | ||
| const projectGroups = (await tdeiUserClient.getMyProjectGroups()) | ||
| .sort((a, b) => a.name.localeCompare(b.name)) | ||
| const searchText = ref('') | ||
| const isOpen = ref(false) | ||
| const projectGroups = ref<{ id: string; name: string }[]>([]) | ||
| const selectedGroupName = ref('') | ||
| const loading = ref(false) | ||
| const pickerRef = ref<HTMLElement | null>(null) | ||
| const listRef = ref<HTMLElement | null>(null) | ||
| const activeIndex = ref(-1) | ||
|
|
||
| let pageNo = 1 | ||
| let hasMore = true | ||
| let pendingReset = false | ||
| const pageSize = 10 | ||
|
|
||
| const loadGroups = async (reset = false) => { | ||
| if (loading.value) { | ||
| pendingReset = pendingReset || reset | ||
| return | ||
| } | ||
|
|
||
| if (reset) { | ||
| pageNo = 1 | ||
| hasMore = true | ||
| projectGroups.value = [] | ||
| activeIndex.value = -1 | ||
| } | ||
| if (!hasMore) return | ||
|
|
||
|
shweta2101 marked this conversation as resolved.
|
||
| loading.value = true | ||
| try { | ||
| let query = searchText.value | ||
| // If the text is exactly the selected group's name, fetch all options instead of filtering | ||
| if (query === selectedGroupName.value) { | ||
| query = '' | ||
| } | ||
|
|
||
| const newGroups = await tdeiUserClient.getMyProjectGroups(pageNo, query, pageSize) | ||
| projectGroups.value.push(...newGroups) | ||
|
|
||
| if (projectGroups.length > 0) { | ||
| if (!model.value || !projectGroups.some(pg => pg.id === model.value)) { | ||
| model.value = projectGroups[0].id | ||
| if (newGroups.length < pageSize) { | ||
| hasMore = false | ||
| } else { | ||
| pageNo++ | ||
| } | ||
| } catch (e) { | ||
| console.error(e) | ||
| } finally { | ||
| loading.value = false | ||
|
|
||
| if (pendingReset) { | ||
| const resetNext = pendingReset | ||
| pendingReset = false | ||
| await loadGroups(resetNext) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let timeoutId: ReturnType<typeof setTimeout> | ||
| watch(searchText, (newVal, oldVal) => { | ||
| if (!isOpen.value) return | ||
|
|
||
| clearTimeout(timeoutId) | ||
| timeoutId = setTimeout(() => { | ||
| loadGroups(true) | ||
| }, 300) | ||
| }) | ||
|
|
||
| watch(model, (newId) => { | ||
| const pg = projectGroups.value.find(p => p.id === newId) | ||
| if (pg && !isOpen.value) { | ||
| searchText.value = pg.name | ||
| selectedGroupName.value = pg.name | ||
| } | ||
| }) | ||
|
|
||
| const onScroll = (e: Event) => { | ||
| const target = e.target as HTMLElement | ||
| if (target.scrollTop + target.clientHeight >= target.scrollHeight - 10) { | ||
| loadGroups() | ||
| } | ||
| } | ||
|
|
||
| const selectGroup = (id: string) => { | ||
| model.value = id | ||
| isOpen.value = false | ||
| const pg = projectGroups.value.find(p => p.id === id) | ||
| if (pg) { | ||
| searchText.value = pg.name | ||
| selectedGroupName.value = pg.name | ||
| } | ||
| } | ||
|
|
||
| const onFocus = (e: Event) => { | ||
| isOpen.value = true | ||
| loadGroups(true) | ||
| const target = e.target as HTMLInputElement | ||
| if (target) { | ||
| target.select() | ||
| } | ||
| } | ||
|
|
||
| const scrollToActive = () => { | ||
| nextTick(() => { | ||
| if (!listRef.value || activeIndex.value < 0) return | ||
| const activeEl = listRef.value.querySelector(`#pg-item-${activeIndex.value}`) as HTMLElement | ||
| if (activeEl) { | ||
| const list = listRef.value | ||
| const top = activeEl.offsetTop | ||
| const bottom = top + activeEl.offsetHeight | ||
|
|
||
| if (top < list.scrollTop) { | ||
| list.scrollTop = top | ||
| } else if (bottom > list.scrollTop + list.clientHeight) { | ||
| list.scrollTop = bottom - list.clientHeight | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| const onKeydown = (e: KeyboardEvent) => { | ||
| if (!isOpen.value) { | ||
| if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { | ||
| onFocus(e) | ||
| e.preventDefault() | ||
| } | ||
| return | ||
| } | ||
|
|
||
| if (e.key === 'ArrowDown') { | ||
| e.preventDefault() | ||
| if (activeIndex.value < projectGroups.value.length - 1) { | ||
| activeIndex.value++ | ||
| scrollToActive() | ||
| } | ||
| } else if (e.key === 'ArrowUp') { | ||
| e.preventDefault() | ||
| if (activeIndex.value > 0) { | ||
| activeIndex.value-- | ||
| scrollToActive() | ||
| } | ||
| } else if (e.key === 'Enter') { | ||
| e.preventDefault() | ||
| if (activeIndex.value >= 0 && activeIndex.value < projectGroups.value.length) { | ||
| const pg = projectGroups.value[activeIndex.value] | ||
| if (pg) selectGroup(pg.id) | ||
| } | ||
| } else if (e.key === 'Escape') { | ||
| e.preventDefault() | ||
| isOpen.value = false | ||
| const pg = projectGroups.value.find(p => p.id === model.value) | ||
| if (pg) { | ||
| searchText.value = pg.name | ||
| selectedGroupName.value = pg.name | ||
| } else { | ||
| searchText.value = '' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const handleClickOutside = (event: MouseEvent) => { | ||
| if (pickerRef.value && !pickerRef.value.contains(event.target as Node)) { | ||
| if (isOpen.value) { | ||
| isOpen.value = false | ||
| const pg = projectGroups.value.find(p => p.id === model.value) | ||
| if (pg) { | ||
| searchText.value = pg.name | ||
| selectedGroupName.value = pg.name | ||
| } else { | ||
| searchText.value = '' | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| onMounted(async () => { | ||
| document.addEventListener('mousedown', handleClickOutside) | ||
| await loadGroups(true) | ||
|
|
||
| if (projectGroups.value.length > 0) { | ||
| if (!model.value) { | ||
| model.value = projectGroups.value[0]?.id | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const selected = projectGroups.value.find(pg => pg.id === model.value) | ||
| if (selected) { | ||
| searchText.value = selected.name | ||
| selectedGroupName.value = selected.name | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| onUnmounted(() => { | ||
| document.removeEventListener('mousedown', handleClickOutside) | ||
| }) | ||
| </script> | ||
|
|
||
| <style scoped> | ||
| .cursor-pointer { | ||
| cursor: pointer; | ||
| } | ||
| .list-group-item.highlighted { | ||
| background-color: rgba(13, 110, 253, 0.25); | ||
| color: inherit; | ||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.