Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): show error when update notebook fail #7009

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/flows/context/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ 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 +24,10 @@ 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 +46,18 @@ 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