Browse Source

fix(gui): allow insert after last column and insert before on first column

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4504/head
Pranav C 2 years ago
parent
commit
a4038a81fe
  1. 35
      packages/nc-gui/components/smartsheet/header/Menu.vue

35
packages/nc-gui/components/smartsheet/header/Menu.vue

@ -85,7 +85,11 @@ const setAsPrimaryValue = async () => {
const sortByColumn = async (direction: 'asc' | 'desc') => { const sortByColumn = async (direction: 'asc' | 'desc') => {
try { try {
$e('a:sort:add', { from: 'column-menu' }) $e('a:sort:add', { from: 'column-menu' })
await $api.dbTableSort.create(view.value?.id as string, { fk_column_id: column!.value.id, direction, push_to_top: true }) await $api.dbTableSort.create(view.value?.id as string, {
fk_column_id: column!.value.id,
direction,
push_to_top: true,
})
eventBus.emit(SmartsheetStoreEvents.SORT_RELOAD) eventBus.emit(SmartsheetStoreEvents.SORT_RELOAD)
reloadDataHook?.trigger() reloadDataHook?.trigger()
} catch (e: any) { } catch (e: any) {
@ -135,13 +139,13 @@ const duplicateColumn = async () => {
const gridViewColumnList = await $api.dbViewColumn.list(view.value?.id as string) const gridViewColumnList = await $api.dbViewColumn.list(view.value?.id as string)
const currentColumnIndex = gridViewColumnList.findIndex((f) => f.fk_column_id === column!.value.id) const currentColumnIndex = gridViewColumnList.findIndex((f) => f.fk_column_id === column!.value.id)
let newColumnOrder
if (currentColumnIndex === gridViewColumnList.length - 2) { if (currentColumnIndex === gridViewColumnList.length - 1) {
return newColumnOrder = gridViewColumnList[currentColumnIndex].order + 1
} else {
newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex + 1]?.order) / 2
} }
const newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex + 1]?.order) / 2
await $api.dbTableColumn.create(meta!.value!.id!, { await $api.dbTableColumn.create(meta!.value!.id!, {
...columnCreatePayload, ...columnCreatePayload,
column_order: { column_order: {
@ -162,22 +166,21 @@ const addColumn = async (before = false) => {
const currentColumnIndex = gridViewColumnList.findIndex((f) => f.fk_column_id === column!.value.id) const currentColumnIndex = gridViewColumnList.findIndex((f) => f.fk_column_id === column!.value.id)
// if (currentColumnIndex === gridViewColumnList.length - 2) {
// return
// }
let newColumnOrder let newColumnOrder
if (before) { if (before) {
if (currentColumnIndex === 0) {
newColumnOrder = gridViewColumnList[currentColumnIndex].order / 2
} else {
newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex - 1]?.order) / 2 newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex - 1]?.order) / 2
}
} else {
if (currentColumnIndex === gridViewColumnList.length - 1) {
newColumnOrder = gridViewColumnList[currentColumnIndex].order + 1
} else { } else {
newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex + 1]?.order) / 2 newColumnOrder = (gridViewColumnList[currentColumnIndex].order! + gridViewColumnList[currentColumnIndex + 1]?.order) / 2
} }
// eventBus.emit(SmartsheetStoreEvents.FIELD_ADD, { }
// columnOrder: {
// order: newColumnOrder,
// viewId: view.value?.id as string,
// },
// })
emit('addColumn', { emit('addColumn', {
column_order: { column_order: {
order: newColumnOrder, order: newColumnOrder,

Loading…
Cancel
Save