Skip to content

Commit

Permalink
feat: show error when update notebook fail
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenHoangSon96 committed Feb 14, 2025
1 parent 0f38e66 commit 5462ef5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/flows/context/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
deleteNotebook,
getNotebooks,
} from 'src/client/notebooksRoutes'
import {notebookUpdateFail} from 'src/shared/copy/notifications'
import {notebookEditFail, notebookUpdateFail} from 'src/shared/copy/notifications'
import {notify} from 'src/shared/actions/notifications'

const DEFAULT_API_FLOW: PatchNotebookParams = {
Expand All @@ -21,7 +21,7 @@ let reportMaxTimeout = null
const REPORT_DECAY = 500 // number of miliseconds to wait after last event before sending
const REPORT_MAX_WAIT = 5000 // max number of miliseconds to wait between sends

export const pooledUpdateAPI = (flow: PatchNotebookParams) => {
export const pooledUpdateAPI = (flow: PatchNotebookParams, dispatch: Function) => {
stagedFlow = flow

if (!!reportDecayTimeout) {
Expand All @@ -40,14 +40,14 @@ export const pooledUpdateAPI = (flow: PatchNotebookParams) => {

clearTimeout(reportDecayTimeout)
reportDecayTimeout = null
updateAPI(stagedFlow)
updateAPI(stagedFlow).catch(err => dispatch(notify(notebookEditFail(err.message))))

stagedFlow = DEFAULT_API_FLOW
}, REPORT_MAX_WAIT)
}

reportDecayTimeout = setTimeout(() => {
updateAPI(stagedFlow)
updateAPI(stagedFlow).catch(err => dispatch(notify(notebookEditFail(err.message))))

stagedFlow = DEFAULT_API_FLOW
}, REPORT_DECAY)
Expand Down
6 changes: 3 additions & 3 deletions src/flows/context/flow.current.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {FC, useCallback, useRef, useState, useEffect} from 'react'
import React, {FC, useCallback, useEffect, useRef, useState} from 'react'
import {Flow, PipeData, PipeMeta} from 'src/types/flows'
import {customAlphabet} from 'nanoid'
import {PIPE_DEFINITIONS, PROJECT_NAME_PLURAL} from 'src/flows'
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
import {Doc} from 'yjs'
import {WebsocketProvider} from 'y-websocket'
import {serialize, hydrate} from 'src/flows/context/flow.list'
import {hydrate, serialize} from 'src/flows/context/flow.list'
import {useParams} from 'react-router-dom'
import {
deleteNotebook,
Expand Down Expand Up @@ -195,7 +195,7 @@ export const FlowProvider: FC = ({children}) => {
...flow,
})

pooledUpdateAPI({id, ...apiFlow})
pooledUpdateAPI({id, ...apiFlow}, dispatch)
},
[id]
)
Expand Down
5 changes: 5 additions & 0 deletions src/shared/copy/notifications/categories/notebooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const notebookDeleteSuccess = (): Notification => ({
message: 'Notebook was deleted successfully',
})

export const notebookEditFail = (message: string): Notification => ({
...defaultErrorNotification,
message: `Failed to edit Notebook: ${message}`,
})

export const csvUploaderErrorNotification = (
message: string
): Notification => ({
Expand Down

0 comments on commit 5462ef5

Please sign in to comment.