π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(nc-gui): show error message in tooltip if error occured while executing button action
Ramesh Mane79dd26ad412b
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.ts b/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.tsindex e8b8672e1c..b9b8f539f4 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.ts@@ -241,6 +241,16 @@ export const ButtonCellRenderer: CellRenderer = {const isLoading = actionManager.isLoading(pk, column.id!)const afterActionStatus = actionManager.getAfterActionStatus(pk, column.id!)+ if (afterActionStatus?.tooltip) {+ Object.assign(cellRenderStore, {+ invalidUrlTooltip: afterActionStatus.tooltip,+ })+ } else {+ Object.assign(cellRenderStore, {+ invalidUrlTooltip: '',+ })+ }+let disabledState = isLoading || disabled?.isInvalidctx.textAlign = 'left'@@ -342,7 +352,7 @@ export const ButtonCellRenderer: CellRenderer = {}} else if (afterActionStatus) {spriteLoader.renderIcon(ctx, {- icon: afterActionStatus === 'success' ? 'ncCheck' : 'ncInfo',+ icon: afterActionStatus.status === 'success' ? 'ncCheck' : 'ncInfo',size: iconSize,x: contentX,y: contentY,diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts b/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.tsindex 53092fddbe..19ab08625d 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts@@ -38,7 +38,13 @@ export class ActionManager {// key is rowId-columnId, value is startTimeprivate loadingColumns = new Map<string, number>()- private afterActionStatus = new Map<string, 'success' | 'error'>()+ private afterActionStatus = new Map<+ string,+ {+ status: 'success' | 'error'+ tooltip?: string+ }+ >()private rafId: number | null = nullprivate getKey(rowId: string, columnId: string): string {@@ -71,40 +77,44 @@ export class ActionManager {this.startAnimationLoop()+ let isErrorOccured = false+try {const res = await action()rowIds.forEach((id) => {- this.afterActionStatus.set(this.getKey(id, columnId), 'success')+ this.afterActionStatus.set(this.getKey(id, columnId), { status: 'success' })affectedColumnIds.forEach((colId) => {- this.afterActionStatus.set(this.getKey(id, colId), 'success')+ this.afterActionStatus.set(this.getKey(id, colId), { status: 'success' })})})- // Remove success columns after 2 seconds- ncDelay(2000).then(() => {- rowIds.forEach((id) => {- this.afterActionStatus.delete(this.getKey(id, columnId))+ return res+ } catch (e: any) {+ isErrorOccured = true- affectedColumnIds.forEach((colId) => {- this.afterActionStatus.delete(this.getKey(id, colId))- })+ const errorMsg = await extractSdkResponseErrorMsg(e)+ rowIds.forEach((id) => {+ this.afterActionStatus.set(this.getKey(id, columnId), { status: 'error', tooltip: errorMsg ?? 'Something went wrong' })++ affectedColumnIds.forEach((colId) => {+ this.afterActionStatus.set(this.getKey(id, colId), { status: 'error', tooltip: errorMsg ?? 'Something went wrong' })})})- return res- } catch (e) {+ throw e+ } finally {rowIds.forEach((id) => {- this.afterActionStatus.set(this.getKey(id, columnId), 'error')+ this.loadingColumns.delete(this.getKey(id, columnId))affectedColumnIds.forEach((colId) => {- this.afterActionStatus.set(this.getKey(id, colId), 'error')+ this.loadingColumns.delete(this.getKey(id, colId))})})- // Remove error columns after 3 seconds- ncDelay(3000).then(() => {+ // Remove error columns after 3 seconds if error occured, otherwise after 2 seconds+ ncDelay(isErrorOccured ? 3000 : 2000).then(() => {rowIds.forEach((id) => {this.afterActionStatus.delete(this.getKey(id, columnId))@@ -113,15 +123,6 @@ export class ActionManager {})})})- throw e- } finally {- rowIds.forEach((id) => {- this.loadingColumns.delete(this.getKey(id, columnId))-- affectedColumnIds.forEach((colId) => {- this.loadingColumns.delete(this.getKey(id, colId))- })- })}}