Browse Source

refactor(gui-v2): show type based direction option

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2860/head
Pranav C 2 years ago
parent
commit
d4c4d512a1
  1. 24
      packages/nc-gui-v2/components/smartsheet-toolbar/SortListMenu.vue
  2. 35
      packages/nc-gui-v2/utils/sortUtils.ts

24
packages/nc-gui-v2/components/smartsheet-toolbar/SortListMenu.vue

@ -1,5 +1,7 @@
<script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk'
import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue'
import { getSortDirectionOptions } from '~/utils/sortUtils'
import { computed, inject, useViewSorts } from '#imports'
import { ActiveViewInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/context'
import MdiMenuDownIcon from '~icons/mdi/menu-down'
@ -15,6 +17,12 @@ const reloadDataHook = inject(ReloadViewDataHookInj)
const { sorts, saveOrUpdate, loadSorts, addSort, deleteSort } = useViewSorts(view, () => reloadDataHook?.trigger())
const columns = computed(() => meta?.value?.columns || [])
const columnByID = computed<Record<string, ColumnType>>(() =>
columns?.value?.reduce((obj: any, col: any) => {
obj[col.id] = col
return obj
}, {}),
)
watch(
() => (view?.value as any)?.id,
@ -57,15 +65,19 @@ watch(
<a-select
v-model:value="sort.direction"
size="small"
class="flex-shrink-1 flex-grow-0 caption nc-sort-dir-select"
:options="[
{ text: 'asc', value: 'asc' },
{ text: 'desc', value: 'desc' },
]"
class="flex-shrink-1 flex-grow-0 caption nc-sort-dir-select !text-xs"
:label="$t('labels.operation')"
@click.stop
@update:model-value="saveOrUpdate(sort, i)"
/>
>
<a-select-option
v-for="(option, j) in getSortDirectionOptions(columnByID[sort.fk_column_id]?.uidt)"
:key="j"
:value="option.value"
>
<span class="text-xs">{{ option.text }}</span>
</a-select-option>
</a-select>
<!-- <template #item="{ item }"> -->
<!-- <span class="caption font-weight-regular">{{ item.text }}</span> -->
<!-- </template> -->

35
packages/nc-gui-v2/utils/sortUtils.ts

@ -0,0 +1,35 @@
import { UITypes } from 'nocodb-sdk'
export const getSortDirectionOptions = (uidt: UITypes) => {
switch (uidt) {
case UITypes.Year:
case UITypes.Number:
case UITypes.Decimal:
case UITypes.Rating:
case UITypes.Count:
case UITypes.AutoNumber:
case UITypes.Time:
case UITypes.Currency:
case UITypes.Percent:
case UITypes.Duration:
case UITypes.PhoneNumber:
case UITypes.Date:
case UITypes.DateTime:
case UITypes.CreateTime:
case UITypes.LastModifiedTime:
return [
{ text: '1 → 9', value: 'asc' },
{ text: '9 → 1', value: 'desc' },
]
case UITypes.Checkbox:
return [
{ text: '▢ → ✓', value: 'asc' },
{ text: '✓ → ▢', value: 'desc' },
]
default:
return [
{ text: 'A → Z', value: 'asc' },
{ text: 'Z → A', value: 'desc' },
]
}
}
Loading…
Cancel
Save