From 71158bc6d740f3038404e80c06ad38763f8b9bdf Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Mon, 19 Feb 2024 03:41:23 +0000 Subject: [PATCH] fix: show warning on paste or clear on not supported col --- packages/nc-gui/components/smartsheet/Row.vue | 7 +++-- .../components/smartsheet/grid/Table.vue | 27 ++++++++++++++----- packages/nc-gui/composables/useLTARStore.ts | 9 +++---- .../composables/useMultiSelect/index.ts | 12 +++++++++ .../composables/useSmartsheetRowStore.ts | 2 -- packages/nc-gui/composables/useViewSorts.ts | 2 +- packages/nc-gui/lang/en.json | 5 +++- packages/nc-gui/utils/dataUtils.ts | 2 +- packages/nocodb/src/db/BaseModelSqlv2.ts | 1 + 9 files changed, 47 insertions(+), 20 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Row.vue b/packages/nc-gui/components/smartsheet/Row.vue index 80a806bdfb..4b5567e90e 100644 --- a/packages/nc-gui/components/smartsheet/Row.vue +++ b/packages/nc-gui/components/smartsheet/Row.vue @@ -21,7 +21,10 @@ const currentRow = toRef(props, 'row') const { meta } = useSmartsheetStoreOrThrow() -const { isNew, state, syncLTARRefs, clearLTARCell, addLTARRef, cleaMMCell } = useProvideSmartsheetRowStore(meta as Ref, currentRow) +const { isNew, state, syncLTARRefs, clearLTARCell, addLTARRef, cleaMMCell } = useProvideSmartsheetRowStore( + meta as Ref, + currentRow, +) const reloadViewDataTrigger = inject(ReloadViewDataHookInj)! @@ -41,7 +44,7 @@ defineExpose({ syncLTARRefs, clearLTARCell, addLTARRef, - cleaMMCell + cleaMMCell, }) diff --git a/packages/nc-gui/components/smartsheet/grid/Table.vue b/packages/nc-gui/components/smartsheet/grid/Table.vue index 63378c34d4..b3a8bb8301 100644 --- a/packages/nc-gui/components/smartsheet/grid/Table.vue +++ b/packages/nc-gui/components/smartsheet/grid/Table.vue @@ -29,15 +29,18 @@ import { getEnumColorByIndex, iconMap, inject, + isBt, isColumnRequiredAndNull, isDrawerOrModalExist, isEeUI, isMac, + isMm, message, onClickOutside, onMounted, provide, ref, + useApi, useEventListener, useI18n, useMultiSelect, @@ -50,7 +53,6 @@ import { useViewColumnsOrThrow, useViewsStore, watch, - useApi } from '#imports' import type { CellRange, Row } from '#imports' @@ -291,7 +293,6 @@ async function clearCell(ctx: { row: number; col: number } | null, skipUpdate = rowId === extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]) && columnObj.id === col.id ) { - if (rowRefs.value) { if (isBt(columnObj)) { rowObj.row[columnObj.title] = row.row[columnObj.title] @@ -299,7 +300,12 @@ async function clearCell(ctx: { row: number; col: number } | null, skipUpdate = await rowRefs.value[ctx.row]!.addLTARRef(rowObj.row[columnObj.title], columnObj) await rowRefs.value[ctx.row]!.syncLTARRefs(rowObj.row) } else if (isMm(columnObj)) { - await api.dbDataTableRow.nestedLink(meta.value?.id as string, columnObj.id as string, encodeURIComponent(rowId as string), mmClearResult) + await api.dbDataTableRow.nestedLink( + meta.value?.id as string, + columnObj.id as string, + encodeURIComponent(rowId as string), + mmClearResult, + ) rowObj.row[columnObj.title] = mmClearResult?.length ? mmClearResult?.length : null } } @@ -319,7 +325,7 @@ async function clearCell(ctx: { row: number; col: number } | null, skipUpdate = args: [clone(ctx), clone(columnObj), clone(rowObj), clone(paginationDataRef.value), mmClearResult], }, redo: { - fn: async (ctx: { row: number; col: number }, col: ColumnType, row: Row, pg: PaginatedType, mmClearResult:any[]) => { + fn: async (ctx: { row: number; col: number }, col: ColumnType, row: Row, pg: PaginatedType) => { if (paginationDataRef.value?.pageSize === pg.pageSize) { if (paginationDataRef.value?.page !== pg.page) { await changePage?.(pg.page!) @@ -331,7 +337,7 @@ async function clearCell(ctx: { row: number; col: number } | null, skipUpdate = if (rowRefs.value) { if (isBt(columnObj)) { await rowRefs.value[ctx.row]!.clearLTARCell(columnObj) - } else if (isMm(columnObj)){ + } else if (isMm(columnObj)) { await rowRefs.value[ctx.row]!.cleaMMCell(columnObj) } } @@ -347,7 +353,7 @@ async function clearCell(ctx: { row: number; col: number } | null, skipUpdate = throw new Error(t('msg.pageSizeChanged')) } }, - args: [clone(ctx), clone(columnObj), clone(rowObj), clone(paginationDataRef.value), mmClearResult], + args: [clone(ctx), clone(columnObj), clone(rowObj), clone(paginationDataRef.value)], }, scope: defineViewScope({ view: view.value }), }) @@ -912,13 +918,20 @@ async function clearSelectedRangeOfCells() { const cols = fields.value.slice(startCol, endCol + 1) const rows = dataRef.value.slice(startRow, endRow + 1) const props = [] + let isInfoShown = false for (const row of rows) { for (const col of cols) { if (!row || !col || !col.title) continue // TODO handle LinkToAnotherRecord - if (isVirtualCol(col)) continue + if (isVirtualCol(col)) { + if ((isBt(col) || isMm(col)) && !isInfoShown) { + message.info(t('msg.info.groupClearIsNotSupportedOnLinksColumn')) + isInfoShown = true + } + continue + } row.row[col.title] = null props.push(col.title) diff --git a/packages/nc-gui/composables/useLTARStore.ts b/packages/nc-gui/composables/useLTARStore.ts index 51882e0673..14b43b745c 100644 --- a/packages/nc-gui/composables/useLTARStore.ts +++ b/packages/nc-gui/composables/useLTARStore.ts @@ -1,14 +1,11 @@ -import { +import { UITypes, dateFormats, parseStringDateTime, timeFormats } from 'nocodb-sdk' +import type { type ColumnType, type LinkToAnotherRecordType, type PaginatedType, + RelationTypes, type RequestParams, type TableType, - UITypes, - dateFormats, - parseStringDateTime, - timeFormats, - RelationTypes, } from 'nocodb-sdk' import type { ComputedRef, Ref } from 'vue' import { diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 9de520ff92..a510c05de0 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -825,6 +825,7 @@ export function useMultiSelect( const propsToPaste: string[] = [] let pastedRows = 0 + let isInfoShown = false for (let i = 0; i < pasteMatrixRows; i++) { const pasteRow = rowsToPaste[i] @@ -838,6 +839,10 @@ export function useMultiSelect( const pasteCol = colsToPaste[j] if (!isPasteable(pasteRow, pasteCol)) { + if ((isBt(pasteCol) || isMm(pasteCol)) && !isInfoShown) { + message.info(t('msg.info.groupPasteIsNotSupportedOnLinksColumn')) + isInfoShown = true + } continue } @@ -1070,13 +1075,20 @@ export function useMultiSelect( const props = [] let pasteValue + let isInfoShown = false + const files = e.clipboardData?.files + for (const row of rows) { // TODO handle insert new row if (!row || row.rowMeta.new) continue for (const col of cols) { if (!col.title || !isPasteable(row, col)) { + if ((isBt(col) || isMm(col)) && !isInfoShown) { + message.info(t('msg.info.groupPasteIsNotSupportedOnLinksColumn')) + isInfoShown = true + } continue } diff --git a/packages/nc-gui/composables/useSmartsheetRowStore.ts b/packages/nc-gui/composables/useSmartsheetRowStore.ts index 0e68daada8..ad86ab3366 100644 --- a/packages/nc-gui/composables/useSmartsheetRowStore.ts +++ b/packages/nc-gui/composables/useSmartsheetRowStore.ts @@ -190,8 +190,6 @@ const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState( try { if (!column || !isLinksOrLTAR(column)) return - const relatedTableMeta = metas.value?.[(column?.colOptions)?.fk_related_model_id as string] - if (isNew.value) { state.value[column.title!] = null } else if (currentRow.value) { diff --git a/packages/nc-gui/composables/useViewSorts.ts b/packages/nc-gui/composables/useViewSorts.ts index ab510c2237..75032b0eab 100644 --- a/packages/nc-gui/composables/useViewSorts.ts +++ b/packages/nc-gui/composables/useViewSorts.ts @@ -1,7 +1,7 @@ import type { ColumnType, SortType, ViewType } from 'nocodb-sdk' import type { Ref } from 'vue' -import type { UndoRedoAction } from '~/lib' import type { EventHook } from '@vueuse/core' +import type { UndoRedoAction } from '~/lib' import { IsPublicInj, ReloadViewDataHookInj, diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.json index a2786d1463..cf09521c93 100644 --- a/packages/nc-gui/lang/en.json +++ b/packages/nc-gui/lang/en.json @@ -1255,7 +1255,10 @@ "thankYou": "Thank you!", "submittedFormData": "You have successfully submitted the form data.", "editingSystemKeyNotSupported": "Editing system key not supported", - "notAvailableAtTheMoment": "Not available at the moment" + "notAvailableAtTheMoment": "Not available at the moment", + "groupPasteIsNotSupportedOnLinksColumn": "Group paste operation is not supported on Links/LinkToAnotherRecord column", + "groupClearIsNotSupportedOnLinksColumn": "Group clear operation is not supported on Links/LinkToAnotherRecord column" + }, "error": { "scopesRequired": "Scopes required", diff --git a/packages/nc-gui/utils/dataUtils.ts b/packages/nc-gui/utils/dataUtils.ts index 1bea695361..566d5e5404 100644 --- a/packages/nc-gui/utils/dataUtils.ts +++ b/packages/nc-gui/utils/dataUtils.ts @@ -1,7 +1,7 @@ import { RelationTypes, UITypes, isLinksOrLTAR, isSystemColumn, isVirtualCol } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk' -import type { Row } from '~/lib' import { isColumnRequiredAndNull } from './columnUtils' +import type { Row } from '~/lib' export const extractPkFromRow = (row: Record, columns: ColumnType[]) => { if (!row || !columns) return null diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index e0bfb3f3ee..b6a7c16034 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5168,6 +5168,7 @@ class BaseModelSqlv2 { ]), ); }); + if (parentTable.primaryKeys.length > 1) { childRowsQb.where((qb) => { for (const childId of childIds) {