π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(nc-gui): show loader while uploading attachment
Ramesh Mane8fef4a82f904
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.tsindex 6536782495..cf94a69e92 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts@@ -949,6 +949,7 @@ export function useCanvasTable({updateOrSaveRow,getRows,getDataCache,+ actionManager,})const { handleFillEnd, handleFillMove, handleFillStart } = useFillHandler({diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.tsindex 10265809cf..ec11c469dc 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts@@ -22,6 +22,7 @@ import { SelectTypeConversionError } from '../../../../../error/select-type-convimport { TypeConversionError } from '../../../../../error/type-conversion.error'import type { SuppressedError } from '../../../../../error/suppressed.error'import { EDIT_INTERACTABLE } from '../utils/constants'+import type { ActionManager } from '../loaders/ActionManager'const MAX_ROWS = 5000@@ -40,6 +41,8 @@ export function useCopyPaste({updateOrSaveRow,getRows,getDataCache,++ actionManager,}: {activeCell: Ref<{row?: number@@ -108,6 +111,7 @@ export function useCopyPaste({selectedRows: ComputedRef<Array<Row>>isRowSortRequiredRows: ComputedRef<Array<Row>>}+ actionManager: ActionManager}) {const { $api } = useNuxtApp()const { isDataReadOnly } = useRoles()@@ -687,13 +691,23 @@ export function useCopyPaste({}if (columnObj.uidt === UITypes.Attachment && e.clipboardData?.files?.length && pasteValue?.length) {- const newAttachments =- (await handleFileUploadAndGetCellValue(pasteValue, columnObj.id!, rowObj.row[columnObj.title!])) || []+ const pasteRowPk = extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[])++ const uploadAction = async () => {+ const newAttachments =+ (await handleFileUploadAndGetCellValue(pasteValue, columnObj.id!, rowObj.row[columnObj.title!])) || []++ const oldAttachments = ncIsArray(rowObj.row[columnObj.title!]) ? 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+ }- rowObj.row[columnObj.title!] =- newAttachments.length || oldAttachments.length ? JSON.stringify(oldAttachments.concat(newAttachments)) : null+ if (pasteRowPk) {+ await actionManager.executeUploadAction(pasteRowPk, columnObj.id!, [], uploadAction)+ } else {+ await uploadAction()+ }} else if (pasteValue !== undefined) {rowObj.row[columnObj.title!] = pasteValue}@@ -758,9 +772,28 @@ export function useCopyPaste({)if (fileUploadPayload?.length) {- const newAttachments = await handleFileUploadAndGetCellValue(fileUploadPayload, col.id!, row.row[col.title!])+ const uploadAction = async () => {+ const newAttachments = await handleFileUploadAndGetCellValue(+ fileUploadPayload,+ col.id!,+ row.row[col.title!],+ )++ pasteValue = newAttachments ? JSON.stringify(newAttachments) : null+ }- pasteValue = newAttachments ? JSON.stringify(newAttachments) : null+ const pasteRowsPk = rows+ .map((row) => {+ return extractPkFromRow(row.row, meta.value?.columns as ColumnType[])+ })+ .filter(Boolean) as string[]++ if (pasteRowsPk.length) {+ // We do upload action for first row only and use uploaded url in other rows+ await actionManager.executeUploadAction(pasteRowsPk, col.id!, [], uploadAction)+ } else {+ await uploadAction()+ }}}} else {@@ -1134,20 +1167,26 @@ export function useCopyPaste({if (!dropValue?.length) return- const newAttachments = (await handleFileUploadAndGetCellValue(dropValue, columnObj.id!, rowObj.row[columnObj.title!])) || []+ const dropRowPk = extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[])+ if (!dropRowPk) return- const oldAttachments = ncIsArray(rowObj.row[columnObj.title!]) ? rowObj.row[columnObj.title!] : []+ await actionManager.executeUploadAction(dropRowPk, columnObj.id!, [], async () => {+ const newAttachments =+ (await handleFileUploadAndGetCellValue(dropValue, columnObj.id!, rowObj.row[columnObj.title!])) || []- rowObj.row[columnObj.title!] =- newAttachments.length || oldAttachments.length ? JSON.stringify(oldAttachments.concat(newAttachments)) : null+ const oldAttachments = ncIsArray(rowObj.row[columnObj.title!]) ? rowObj.row[columnObj.title!] : []- await syncCellData?.(- {- row: attachmentCellDropOver.rowIndex,- column: attachmentCellDropOver.colIndex,- },- attachmentCellDropOver.path,- )+ rowObj.row[columnObj.title!] =+ newAttachments.length || oldAttachments.length ? JSON.stringify(oldAttachments.concat(newAttachments)) : null++ await syncCellData?.(+ {+ row: attachmentCellDropOver.rowIndex,+ column: attachmentCellDropOver.colIndex,+ },+ attachmentCellDropOver.path,+ )+ })} catch (ex) {console.log(ex)message.error(t('msg.error.errorOccuredWhileDroppingAttachments'))diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue b/packages/nc-gui/components/smartsheet/grid/canvas/index.vueindex 647287c6d0..52a608ad52 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue+++ b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue@@ -2643,6 +2643,16 @@ const onDrop = (files: File[] | null) => {return}+ selection.value.clear()+ editEnabled.value = null+ activeCell.value = {+ row: attachmentCellDropOver.value.rowIndex,+ column: attachmentCellDropOver.value.colIndex,+ path: attachmentCellDropOver.value.path,+ }+ resetRowSelection()+ onActiveCellChanged()+try {handleAttachmentCellDrop(files, attachmentCellDropOver.value)} finally {diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts b/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.tsindex 88790119c2..3cf6ae976c 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts@@ -367,6 +367,10 @@ export class ActionManager {}}+ async executeUploadAction(...args: Parameters<typeof this.executeAction>): Promise<ReturnType<typeof this.executeAction>> {+ return this.executeAction(...args)+ }+// Public state query methodsisLoading(rowId: string, columnId: string): boolean {const key = this.getKey(rowId, columnId)diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex 75336abd7e..b4e3603745 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -459,44 +459,7 @@ interface CellRendererOptions {isRowChecked?: booleanisCellInSelectionRange?: booleanisGroupHeader?: boolean- rowMeta?: {- // Used in InfiniteScroll Grid View- isLastRow?: number- rowIndex?: number- isLoading?: boolean- isValidationFailed?: boolean- isRowOrderUpdated?: boolean- isDragging?: boolean- rowProgress?: {- message: string- progress: number- }-- new?: boolean- selected?: boolean- commentCount?: number- changed?: boolean- saving?: boolean- ltarState?: Record<string, Record<string, any> | Record<string, any>[] | null>- fromExpandedForm?: boolean- // use in datetime picker component- isUpdatedFromCopyNPaste?: Record<string, boolean>- // Used in Calendar view- style?: Partial<CSSStyleDeclaration>- range?: {- fk_from_col: ColumnType- fk_to_col: ColumnType | null- is_readonly?: boolean- }- id?: string- position?: string- dayIndex?: number- overLapIteration?: number- numberOfOverlaps?: number- minutes?: number- recordIndex?: number // For week spanning records in month view- maxSpanning?: number- } & RowMetaRowColorInfo+ rowMeta?: Row['rowMeta']allowLocalUrl?: boolean/*** `isRootCell` is used to determine if the cell is the root cell of the row or nested cell