Browse Source

fix(nc-gui): field list order issue

pull/8917/head
Ramesh Mane 5 months ago
parent
commit
6be0c340f6
  1. 7
      packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue
  2. 33
      packages/nc-gui/components/smartsheet/toolbar/FieldListWithSearch.vue

7
packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue

@ -69,6 +69,7 @@ const options = computed<SelectProps['options']>(() =>
?.sort((field1, field2) => { ?.sort((field1, field2) => {
let orderVal1 = 0 let orderVal1 = 0
let orderVal2 = 0 let orderVal2 = 0
let sortByOrder = 0
if (isSystemColumn(field1)) { if (isSystemColumn(field1)) {
orderVal1 = 1 orderVal1 = 1
@ -77,7 +78,11 @@ const options = computed<SelectProps['options']>(() =>
orderVal2 = 1 orderVal2 = 1
} }
return orderVal1 - orderVal2 if (field1?.order !== undefined && field2?.order !== undefined) {
sortByOrder = field1.order - field2.order
}
return orderVal1 - orderVal2 || sortByOrder
}) })
?.map((c: ColumnType) => ({ ?.map((c: ColumnType) => ({
value: c.id, value: c.id,

33
packages/nc-gui/components/smartsheet/toolbar/FieldListWithSearch.vue

@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { ColumnType } from 'nocodb-sdk' import { isSystemColumn, type ColumnType } from 'nocodb-sdk'
const props = defineProps<{ const props = defineProps<{
// As we need to focus search box when the parent is opened // As we need to focus search box when the parent is opened
@ -13,10 +13,39 @@ const props = defineProps<{
const emits = defineEmits<{ selected: [ColumnType] }>() const emits = defineEmits<{ selected: [ColumnType] }>()
const { isParentOpen, toolbarMenu, searchInputPlaceholder, selectedOptionId, options, showSelectedOption } = toRefs(props) const {
isParentOpen,
toolbarMenu,
searchInputPlaceholder,
selectedOptionId,
options: _options,
showSelectedOption,
} = toRefs(props)
const searchQuery = ref('') const searchQuery = ref('')
const options = computed(() =>
(_options.value || []).sort((field1, field2) => {
// sort and keep system columns at the end
let orderVal1 = 0
let orderVal2 = 0
let sortByOrder = 0
if (isSystemColumn(field1)) {
orderVal1 = 1
}
if (isSystemColumn(field2)) {
orderVal2 = 1
}
if (field1?.order !== undefined && field2?.order !== undefined) {
sortByOrder = field1.order - field2.order
}
return orderVal1 - orderVal2 || sortByOrder
}),
)
const filteredOptions = computed( const filteredOptions = computed(
() => options.value?.filter((c: ColumnType) => c.title?.toLowerCase().includes(searchQuery.value.toLowerCase())) ?? [], () => options.value?.filter((c: ColumnType) => c.title?.toLowerCase().includes(searchQuery.value.toLowerCase())) ?? [],
) )

Loading…
Cancel
Save