Browse Source

Merge pull request #4046 from nocodb/fix/3988-clear-cell

Feat: Grid view - allow clear cell on LTAR cell
pull/4057/head
Pranav C 2 years ago committed by GitHub
parent
commit
5cc9a84021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 3
      packages/nc-gui/components/smartsheet/Row.vue
  3. 3
      packages/nc-gui/components/smartsheet/column/FormulaOptions.vue
  4. 47
      packages/nc-gui/composables/useSmartsheetRowStore.ts
  5. 10
      packages/nocodb-sdk/src/lib/Api.ts
  6. 12
      scripts/sdk/swagger.json

14
packages/nc-gui/components/smartsheet/Grid.vue

@ -188,11 +188,14 @@ watch(contextMenu, () => {
}
})
const rowRefs = $ref<any[]>()
async function clearCell(ctx: { row: number; col: number }) {
const rowObj = data.value[ctx.row]
const columnObj = fields.value[ctx.col]
if (isVirtualCol(columnObj)) {
await rowRefs[ctx.row]!.clearLTARCell(columnObj)
return
}
@ -255,8 +258,7 @@ const onNavigate = (dir: NavigateDir) => {
if (selected.row < data.value.length - 1) {
selected.row++
} else {
addEmptyRow()
selected.row++
editEnabled = false
}
break
case NavigateDir.PREV:
@ -277,8 +279,6 @@ const showContextMenu = (e: MouseEvent, target?: { row: number; col: number }) =
}
}
const rowRefs = $ref<any[]>()
const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?: ViewType; data?: any } = {}) => {
let index = -1
for (const currentRow of args.data || data.value) {
@ -584,7 +584,11 @@ watch(
<!-- Clear cell -->
<a-menu-item
v-if="contextMenuTarget && !isVirtualCol(fields[contextMenuTarget.col])"
v-if="
contextMenuTarget &&
(fields[contextMenuTarget.col].uidt === UITypes.LinkToAnotherRecord ||
!isVirtualCol(fields[contextMenuTarget.col]))
"
@click="clearCell(contextMenuTarget)"
>
<div v-e="['a:row:clear']" class="nc-project-menu-item">{{ $t('activity.clearCell') }}</div>

3
packages/nc-gui/components/smartsheet/Row.vue

@ -20,7 +20,7 @@ const currentRow = toRef(props, 'row')
const { meta } = useSmartsheetStoreOrThrow()
const { isNew, state, syncLTARRefs } = useProvideSmartsheetRowStore(meta, currentRow)
const { isNew, state, syncLTARRefs, clearLTARCell } = useProvideSmartsheetRowStore(meta, currentRow)
// on changing isNew(new record insert) status sync LTAR cell values
watch(isNew, async (nextVal, prevVal) => {
@ -46,6 +46,7 @@ provide(ReloadRowDataHookInj, reloadHook)
defineExpose({
syncLTARRefs,
clearLTARCell,
})
</script>

3
packages/nc-gui/components/smartsheet/column/FormulaOptions.vue

@ -257,7 +257,8 @@ function validateAgainstMeta(parsedTree: any, errors = new Set(), typeErrors = n
const neighbours = [
...new Set(
(c.colOptions.formula.match(/cl_\w{14}/g) || []).filter(
(colId: string) => columns.value.filter((col: ColumnType) => col.id === colId && col.uidt === UITypes.Formula).length,
(colId: string) =>
columns.value.filter((col: ColumnType) => col.id === colId && col.uidt === UITypes.Formula).length,
),
),
]

47
packages/nc-gui/composables/useSmartsheetRowStore.ts

@ -1,5 +1,5 @@
import { UITypes } from 'nocodb-sdk'
import type { ColumnType, LinkToAnotherRecordType, RelationTypes, TableType } from 'nocodb-sdk'
import { RelationTypes, UITypes } from 'nocodb-sdk'
import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk'
import type { Ref } from 'vue'
import type { MaybeRef } from '@vueuse/core'
import {
@ -120,6 +120,48 @@ const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState(
}
}
// clear LTAR cell
const clearLTARCell = async (column: ColumnType) => {
try {
if (!column || column.uidt !== UITypes.LinkToAnotherRecord) return
const relatedTableMeta = metas.value?.[(<LinkToAnotherRecordType>column?.colOptions)?.fk_related_model_id as string]
if (isNew.value) {
state.value[column.title!] = null
} else if (currentRow.value) {
if ((<LinkToAnotherRecordType>column.colOptions)?.type === RelationTypes.BELONGS_TO) {
if (!currentRow.value.row[column.title!]) return
await $api.dbTableRow.nestedRemove(
NOCO,
project.value.title as string,
meta.value?.title as string,
extractPkFromRow(currentRow.value.row, meta.value?.columns as ColumnType[]),
'bt' as any,
column.title as string,
extractPkFromRow(currentRow.value.row[column.title!], relatedTableMeta?.columns as ColumnType[]),
)
currentRow.value.row[column.title!] = null
} else {
for (const link of (currentRow.value.row[column.title!] as Record<string, any>[]) || []) {
await $api.dbTableRow.nestedRemove(
NOCO,
project.value.title as string,
meta.value?.title as string,
extractPkFromRow(currentRow.value.row, meta.value?.columns as ColumnType[]),
(<LinkToAnotherRecordType>column?.colOptions).type as 'hm' | 'mm',
column.title as string,
extractPkFromRow(link, relatedTableMeta?.columns as ColumnType[]),
)
}
currentRow.value.row[column.title!] = []
}
}
} catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e))
}
}
const loadRow = async () => {
const record = await $api.dbTableRow.read(
NOCO,
@ -144,6 +186,7 @@ const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState(
syncLTARRefs,
loadRow,
currentRow,
clearLTARCell,
}
},
'smartsheet-row-store',

10
packages/nocodb-sdk/src/lib/Api.ts

@ -2694,7 +2694,7 @@ export class Api<
projectName: string,
tableName: string,
rowId: string,
relationType: 'mm' | 'hm',
relationType: 'mm' | 'hm' | 'bt',
columnName: string,
query?: {
limit?: string | number;
@ -2725,7 +2725,7 @@ export class Api<
projectName: string,
tableName: string,
rowId: string,
relationType: 'mm' | 'hm',
relationType: 'mm' | 'hm' | 'bt',
columnName: string,
refRowId: string,
query?: { limit?: string; offset?: string },
@ -2753,7 +2753,7 @@ export class Api<
projectName: string,
tableName: string,
rowId: string,
relationType: 'mm' | 'hm',
relationType: 'mm' | 'hm' | 'bt',
columnName: string,
refRowId: string,
params: RequestParams = {}
@ -2779,7 +2779,7 @@ export class Api<
projectName: string,
tableName: string,
rowId: string,
relationType: 'mm' | 'hm',
relationType: 'mm' | 'hm' | 'bt',
columnName: string,
query?: {
limit?: string | number;
@ -3154,7 +3154,7 @@ export class Api<
dataNestedList: (
sharedViewUuid: string,
rowId: string,
relationType: 'mm' | 'hm',
relationType: 'mm' | 'hm' | 'bt',
columnName: string,
query?: { limit?: string; offset?: string },
params: RequestParams = {}

12
scripts/sdk/swagger.json

@ -4106,7 +4106,8 @@
"type": "string",
"enum": [
"mm",
"hm"
"hm",
"bt"
]
},
"name": "relationType",
@ -4208,7 +4209,8 @@
"type": "string",
"enum": [
"mm",
"hm"
"hm",
"bt"
]
},
"name": "relationType",
@ -4323,7 +4325,8 @@
"type": "string",
"enum": [
"mm",
"hm"
"hm",
"bt"
]
},
"name": "relationType",
@ -4558,7 +4561,8 @@
"type": "string",
"enum": [
"mm",
"hm"
"hm",
"bt"
]
},
"name": "relationType",

Loading…
Cancel
Save