π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
refactor(nc-gui): dropped attachment save method
Ramesh Manec5f3de0fd8c4
diff --git a/packages/nc-gui/components/cell/attachment/index.vue b/packages/nc-gui/components/cell/attachment/index.vueindex 0198749b28..62fbef8b5e 100644--- a/packages/nc-gui/components/cell/attachment/index.vue+++ b/packages/nc-gui/components/cell/attachment/index.vue@@ -297,10 +297,6 @@ onMounted(() => {forcedNextTick(() => {if (onCellEvent(canvasCellEventData.event)) return- if (canvasCellEventData.event && canvasCellEventData.files) {- return onDrop(canvasCellEventData.files, canvasCellEventData.event)- }-const clickableSelectors = ['.view-attachments', '.add-files', '.nc-attachment', '.empty-add-files'].map((selector) => `.nc-canvas-table-editable-cell-wrapper ${selector}`).join(', ')diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.tsindex db3ddd4e55..c256d674ab 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts@@ -475,17 +475,6 @@ export function useGridCellHandler(params: {}}- const handleCellDrop = async (ctx: { e: DragEvent; row: Row; column: CanvasGridColumn; files: File[] | null }) => {- if (ctx.column?.readonly) return-- canvasCellEvents.files = ctx.files- canvasCellEvents.event = ctx.e-- makeCellEditable(ctx.row, ctx.column, true)-- return true- }-let cleanUpInterval: ReturnType<typeof setInterval> | null = nullonMounted(() => {@@ -512,6 +501,5 @@ export function useGridCellHandler(params: {handleCellClick,handleCellKeyDown,handleCellHover,- handleCellDrop,}}diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.tsindex f5b6b996e8..6536782495 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts@@ -792,7 +792,7 @@ export function useCanvasTable({}}- const { handleCellClick, renderCell, handleCellHover, handleCellKeyDown, handleCellDrop } = useGridCellHandler({+ const { handleCellClick, renderCell, handleCellHover, handleCellKeyDown } = useGridCellHandler({getCellPosition,actionManager,updateOrSaveRow,@@ -894,7 +894,7 @@ export function useCanvasTable({isExternalSource,})- const { clearCell, copyValue, isPasteable } = useCopyPaste({+ const { clearCell, copyValue, isPasteable, handleAttachmentCellDrop } = useCopyPaste({activeCell,selection,columns,@@ -1445,13 +1445,15 @@ export function useCanvasTable({copyValue,clearSelectedRangeOfCells,+ // attachment cell drop handler+ handleAttachmentCellDrop,+// Action ManageractionManager,imageLoader,baseRoleLoader,handleCellClick,handleCellHover,- handleCellDrop,renderCell,totalColumnsWidth,diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.tsindex 98b8b8c4e5..ca74ed6803 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts@@ -1098,6 +1098,61 @@ export function useCopyPaste({}}+ const handleAttachmentCellDrop = async (files: File[], attachmentCellDropOver: AttachmentCellDropOverType) => {+ if (!meta.value?.id) return++ const dataCache = getDataCache(attachmentCellDropOver.path)++ const { cachedRows } = dataCache++ const rowObj = (unref(cachedRows) as Map<number, Row>).get(attachmentCellDropOver.rowIndex!)+ const columnObj = unref(fields)[attachmentCellDropOver.colIndex]++ if (!rowObj || !columnObj) return++ let dropValue: any++ try {+ try {+ dropValue = convertCellData(+ {+ value: '',+ to: columnObj.uidt as UITypes,+ column: columnObj,+ appInfo: unref(appInfo),+ files,+ oldValue: rowObj.row[columnObj.title!],+ maxAttachmentsAllowedInCell: maxAttachmentsAllowedInCell.value,+ showUpgradeToAddMoreAttachmentsInCell,+ },+ isMysql(meta.value?.source_id),+ )+ validateColumnValue(columnObj, dropValue)+ } catch (ex) {+ dropValue = null+ }++ if (!dropValue?.length) return++ const newAttachments = (await handleFileUploadAndGetCellValue(dropValue, columnObj.id!, rowObj.row[columnObj.title!])) || []++ const oldAttachments = ncIsArray(rowObj.row[columnObj.title!]) ? rowObj.row[columnObj.title!] : []++ rowObj.row[columnObj.title!] =+ newAttachments.length || oldAttachments.length ? JSON.stringify(oldAttachments.concat(newAttachments)) : null+ await syncCellData?.(+ {+ row: attachmentCellDropOver.rowIndex,+ col: attachmentCellDropOver.colIndex,+ },+ attachmentCellDropOver.path,+ )+ } catch (ex) {+ console.log(ex)+ message.error(t('msg.error.errorOccuredWhileDroppingAttachments'))+ }+ }+function handleParseAttachmentCellData<T>(value: T): T {const parsedVal = parseProp(value)@@ -1108,5 +1163,5 @@ export function useCopyPaste({}}useEventListener(document, 'paste', handlePaste)- return { copyValue, clearCell, isPasteable }+ return { copyValue, clearCell, isPasteable, handleAttachmentCellDrop }}diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue b/packages/nc-gui/components/smartsheet/grid/canvas/index.vueindex a03084e6c7..647287c6d0 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue+++ b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue@@ -334,15 +334,15 @@ const {clearCell,clearSelectedRangeOfCells,+ // Attachment Cell Drop+ handleAttachmentCellDrop,+// Cell ClickhandleCellClick,// Cell HoverhandleCellHover,- // Cell Drop- handleCellDrop,-actionManager,imageLoader,readOnly,@@ -2624,8 +2624,8 @@ const resetAttachmentCellDropOver = () => {requestAnimationFrame(triggerRefreshCanvas)}-const onDrop = (files: File[] | null, event: DragEvent) => {- if (!attachmentCellDropOver.value) {+const onDrop = (files: File[] | null) => {+ if (!attachmentCellDropOver.value || !files?.length) {return}@@ -2633,35 +2633,18 @@ const onDrop = (files: File[] | null, event: DragEvent) => {const row =attachmentCellDropOver.value.rowIndex !== null- ? dataCache.cachedRows.value.get(attachmentCellDropOver.value.rowIndex!)+ ? dataCache.cachedRows.value.get(attachmentCellDropOver.value.rowIndex): undefined- const columnIndex = columns.value.findIndex((col) => col.id === attachmentCellDropOver.value.columnId)+ const column = columns.value[attachmentCellDropOver.value.colIndex]!- if (!row || columnIndex === -1) {+ if (!row || !column) {resetAttachmentCellDropOver()return}- const column = columns.value[columnIndex]!-- selection.value.clear()- editEnabled.value = null- activeCell.value = {- row: attachmentCellDropOver.value.rowIndex,- column: columnIndex,- path: attachmentCellDropOver.value.path,- }- resetRowSelection()- onActiveCellChanged()-try {- handleCellDrop({- files,- e: event,- row,- column,- })+ handleAttachmentCellDrop(files, attachmentCellDropOver.value)} finally {resetAttachmentCellDropOver()}@@ -2698,8 +2681,10 @@ const onOver = (_files: File[] | null, e: DragEvent) => {const { column } = findClickedColumn(mousePosition.x, scrollLeft.value)+ const colIndex = column ? columns.value.findIndex((col) => col.id === column.id) : -1+// If hover column is not attachment, skip- if (!column || column.uidt !== UITypes.Attachment) {+ if (ncIsUndefined(rowIndex) || !column || colIndex === -1 || column.uidt !== UITypes.Attachment) {return resetAttachmentCellDropOver()}@@ -2711,7 +2696,7 @@ const onOver = (_files: File[] | null, e: DragEvent) => {return}- attachmentCellDropOver.value = { rowIndex, columnId: column.id, path: groupPath }+ attachmentCellDropOver.value = { rowIndex, colIndex, columnId: column.id, path: groupPath }requestAnimationFrame(triggerRefreshCanvas)}diff --git a/packages/nc-gui/context/index.ts b/packages/nc-gui/context/index.tsindex a5a3542071..8bb3360784 100644--- a/packages/nc-gui/context/index.ts+++ b/packages/nc-gui/context/index.ts@@ -131,8 +131,7 @@ export const ClientMousePositionInj: InjectionKey<Reactive<{ clientX: number; clexport const CanvasCellEventDataInj: InjectionKey<Reactive<{keyboardKey?: string- files?: File[] | null- event?: KeyboardEvent | MouseEvent | PointerEvent | DragEvent+ event?: KeyboardEvent | MouseEvent | PointerEvent}>> = Symbol('canvas-cell-event-data-injection')diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.jsonindex d947133147..d8c810170f 100644--- a/packages/nc-gui/lang/en.json+++ b/packages/nc-gui/lang/en.json@@ -2437,7 +2437,8 @@"invalidSearchQuery": "Invalid search query","invalidSearchQueryForVisibleFields": "Invalid search query for visible fields","invalidSearchQueryForDisplayField": "Invalid search query for display field",- "promptHasDeletedColumn": "Prompt has deleted column(s): {columns}"+ "promptHasDeletedColumn": "Prompt has deleted column(s): {columns}",+ "errorOccuredWhileDroppingAttachments": "Error occured while dropping attachments"},"toast": {"exportMetadata": "Base metadata exported successfully",diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex 2aa1c8dbfe..75336abd7e 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -929,7 +929,8 @@ interface NcClipboardDataItemType {// NcClipboardDataType type ends hereinterface AttachmentCellDropOverType {- rowIndex?: number+ rowIndex: number+ colIndex: numbercolumnId: stringpath: Array<number>}