Skip to content

Commit

Permalink
Replace autocomplete with select as node filter option input (#659)
Browse files Browse the repository at this point in the history
* Replace autocomplete with select as node filter option input

* i18n
  • Loading branch information
huchenlei committed Aug 28, 2024
1 parent 968f417 commit 5c2cb00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/components/searchbox/NodeSearchFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,50 @@
optionLabel="name"
@change="updateSelectedFilterValue"
/>
<AutoComplete
v-model="selectedFilterValue"
:suggestions="filterValues"
:min-length="0"
@complete="(event) => updateFilterValues(event.query)"
completeOnFocus
forceSelection
dropdown
></AutoComplete>
<Select v-model="selectedFilterValue" :options="filterValues" filter />
</div>
<div class="_footer">
<Button type="button" label="Add" @click="submit"></Button>
<Button type="button" :label="$t('add')" @click="submit"></Button>
</div>
</template>

<script setup lang="ts">
import { NodeFilter, type FilterAndValue } from '@/services/nodeSearchService'
import Button from 'primevue/button'
import SelectButton from 'primevue/selectbutton'
import AutoComplete from 'primevue/autocomplete'
import { ref, onMounted } from 'vue'
import Select from 'primevue/select'
import { ref, onMounted, computed } from 'vue'
import { useNodeDefStore } from '@/stores/nodeDefStore'
const filters = ref<NodeFilter[]>([])
const filters = computed(() => nodeDefStore.nodeSearchService.nodeFilters)
const selectedFilter = ref<NodeFilter>()
const filterValues = ref<string[]>([])
const filterValues = computed(() => selectedFilter.value?.fuseSearch.data ?? [])
const selectedFilterValue = ref<string>('')
const nodeDefStore = useNodeDefStore()
onMounted(() => {
const nodeSearchService = useNodeDefStore().nodeSearchService
filters.value = nodeSearchService.nodeFilters
selectedFilter.value = nodeSearchService.nodeFilters[0]
selectedFilter.value = nodeDefStore.nodeSearchService.nodeFilters[0]
updateSelectedFilterValue()
})
const emit = defineEmits(['addFilter'])
const emit = defineEmits<{
(event: 'addFilter', filterAndValue: FilterAndValue): void
}>()
const updateSelectedFilterValue = () => {
updateFilterValues('')
if (filterValues.value.includes(selectedFilterValue.value)) {
return
}
selectedFilterValue.value = filterValues.value[0]
}
const updateFilterValues = (query: string) => {
filterValues.value = selectedFilter.value.fuseSearch.search(query)
}
const submit = () => {
emit('addFilter', [
selectedFilter.value,
selectedFilterValue.value
] as FilterAndValue)
}
onMounted(updateSelectedFilterValue)
</script>

<style scoped>
Expand Down
3 changes: 3 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { createI18n } from 'vue-i18n'

const messages = {
en: {
add: 'Add',
confirm: 'Confirm',
reset: 'Reset',
customizeFolder: 'Customize Folder',
icon: 'Icon',
color: 'Color',
Expand Down

0 comments on commit 5c2cb00

Please sign in to comment.