Browse Source

fix(gui-v2): clear cell

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2947/head
Pranav C 2 years ago
parent
commit
94bde3fb8a
  1. 31
      packages/nc-gui-v2/components/smartsheet/Grid.vue
  2. 4
      packages/nc-gui-v2/composables/useViewData.ts

31
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -1,6 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { isVirtualCol } from 'nocodb-sdk' import { ColumnType, isVirtualCol } from 'nocodb-sdk'
import { import {
Row,
inject, inject,
onKeyStroke, onKeyStroke,
onMounted, onMounted,
@ -118,6 +119,19 @@ watch(contextMenu, () => {
} }
}) })
const clearCell = async (ctx: { row: number; col: number }) => {
const rowObj = data.value[ctx.row]
const columnObj = fields.value[ctx.col]
if (isVirtualCol(columnObj)) {
return
}
rowObj.row[columnObj.title] = null
// update/save cell value
await updateOrSaveRow(rowObj, columnObj.title)
}
/** handle keypress events */ /** handle keypress events */
onKeyStroke(['Tab', 'Shift', 'Enter', 'Delete', 'ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'], async (e: KeyboardEvent) => { onKeyStroke(['Tab', 'Shift', 'Enter', 'Delete', 'ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'], async (e: KeyboardEvent) => {
if (selected.row !== null && selected.col !== null) { if (selected.row !== null && selected.col !== null) {
@ -148,19 +162,8 @@ onKeyStroke(['Tab', 'Shift', 'Enter', 'Delete', 'ArrowDown', 'ArrowUp', 'ArrowLe
break break
/** on delete key press clear cell */ /** on delete key press clear cell */
case 'Delete': case 'Delete':
{
e.preventDefault() e.preventDefault()
const rowObj = data.value[selected.row] await clearCell(selected as { row: number; col: number })
const columnObj = fields.value[selected.col]
if (isVirtualCol(columnObj)) {
return
}
rowObj.row[columnObj.title] = null
// update/save cell value
await updateOrSaveRow(rowObj, columnObj.title)
}
break break
/** on arrow key press navigate through cells */ /** on arrow key press navigate through cells */
case 'ArrowRight': case 'ArrowRight':
@ -294,7 +297,7 @@ onKeyStroke(['Tab', 'Shift', 'Enter', 'Delete', 'ArrowDown', 'ArrowUp', 'ArrowLe
<div class="bg-white shadow" @click="contextMenu = false"> <div class="bg-white shadow" @click="contextMenu = false">
<div v-if="contextMenuTarget" class="nc-menu-item" @click="deleteRow(contextMenuTarget.row)">Delete row</div> <div v-if="contextMenuTarget" class="nc-menu-item" @click="deleteRow(contextMenuTarget.row)">Delete row</div>
<div class="nc-menu-item" @click="deleteSelectedRows">Delete all selected rows</div> <div class="nc-menu-item" @click="deleteSelectedRows">Delete all selected rows</div>
<div v-if="contextMenuTarget" class="nc-menu-item" >Clear cell</div> <div v-if="contextMenuTarget" class="nc-menu-item" @click="clearCell(contextMenuTarget)">Clear cell</div>
<div v-if="contextMenuTarget" class="nc-menu-item" @click="addEmptyRow(contextMenuTarget.row + 1)">Insert new row</div> <div v-if="contextMenuTarget" class="nc-menu-item" @click="addEmptyRow(contextMenuTarget.row + 1)">Insert new row</div>
</div> </div>
</template> </template>

4
packages/nc-gui-v2/composables/useViewData.ts

@ -13,7 +13,7 @@ const formatData = (list: Record<string, any>[]) =>
rowMeta: {}, rowMeta: {},
})) }))
interface Row { export interface Row {
row: Record<string, any> row: Record<string, any>
oldRow: Record<string, any> oldRow: Record<string, any>
rowMeta?: any rowMeta?: any
@ -136,7 +136,7 @@ export function useViewData(
} }
const addEmptyRow = (addAfter = formattedData.value.length) => { const addEmptyRow = (addAfter = formattedData.value.length) => {
formattedData.value.splice(addAfter,0, { formattedData.value.splice(addAfter, 0, {
row: {}, row: {},
oldRow: {}, oldRow: {},
rowMeta: { new: true }, rowMeta: { new: true },

Loading…
Cancel
Save