From 9d791d12ed31fe7ea4ec438eeef3b27d5ce9f53f Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Wed, 8 Apr 2020 08:31:31 -0700 Subject: [PATCH] fix: read only errors (#17664) * fix: display notification on ne create * fix: create dashboard from DE notify * fix: keep user logged in on /write 403 --- ui/src/cells/actions/thunks.ts | 25 +++++++++++-------- ui/src/client/index.ts | 4 ++- ui/src/dashboards/actions/thunks.ts | 2 +- .../components/SaveAsCellForm.tsx | 24 ++++++------------ ui/src/dataLoaders/actions/dataLoaders.ts | 4 ++- .../notifications/endpoints/actions/thunks.ts | 1 + ui/src/shared/copy/notifications.ts | 15 ++++++++--- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/ui/src/cells/actions/thunks.ts b/ui/src/cells/actions/thunks.ts index 28d37fc91c..9728a718e5 100644 --- a/ui/src/cells/actions/thunks.ts +++ b/ui/src/cells/actions/thunks.ts @@ -22,6 +22,7 @@ import { // Actions import {setView} from 'src/views/actions/creators' import {notify} from 'src/shared/actions/notifications' +import {setDashboard} from 'src/dashboards/actions/creators' import {setCells, setCell, removeCell} from 'src/cells/actions/creators' // Utils @@ -84,13 +85,14 @@ export const createCellWithView = ( throw new Error(resp.data.message) } - const {entities, result} = normalize< - Dashboard, - DashboardEntities, - string - >(resp.data, dashboardSchema) + const normDash = normalize( + resp.data, + dashboardSchema + ) + const {entities, result} = normDash dashboard = entities.dashboards[result] + dispatch(setDashboard(resp.data.id, RemoteDataState.Done, normDash)) } const cell: NewCell = getNewDashboardCell(state, dashboard, clonedCell) @@ -115,11 +117,11 @@ export const createCellWithView = ( // Refresh variables in use on dashboard const normView = normalize(newView, viewSchema) - dispatch(setView(cellID, RemoteDataState.Done, normView)) dispatch(setCell(cellID, RemoteDataState.Done, normCell)) - } catch (err) { - notify(copy.cellAddFailed()) - throw err + dispatch(setView(cellID, RemoteDataState.Done, normView)) + } catch (error) { + dispatch(notify(copy.cellAddFailed(error.message))) + throw error } } @@ -142,9 +144,10 @@ export const createDashboardWithView = ( } await dispatch(createCellWithView(resp.data.id, view)) + dispatch(notify(copy.dashboardCreateSuccess())) } catch (error) { console.error(error) - notify(copy.cellAddFailed()) + dispatch(notify(copy.cellAddFailed(error.message))) throw error } } @@ -171,6 +174,7 @@ export const updateCells = (dashboardID: string, cells: Cell[]) => async ( dispatch(setCells(dashboardID, RemoteDataState.Done, normCells)) } catch (error) { + dispatch(notify(copy.cellUpdateFailed())) console.error(error) } } @@ -187,6 +191,7 @@ export const copyCell = (dashboard: Dashboard, cell: Cell) => dispatch => { dispatch(setCell(cell.id, RemoteDataState.Done, normCell)) dispatch(notify(copy.cellAdded())) } catch (error) { + dispatch(notify(copy.cellCopyFailed())) console.error(error) } } diff --git a/ui/src/client/index.ts b/ui/src/client/index.ts index 39dfd98cb1..66ab85835a 100644 --- a/ui/src/client/index.ts +++ b/ui/src/client/index.ts @@ -14,7 +14,9 @@ setRequestHandler((url, query, init) => { }) setResponseHandler((status, headers, data) => { - if (status === 403) { + // if the user is inactive log them out + // influxdb/http/authentication_middleware.go + if (status === 403 && data.message === 'User is inactive') { postSignout({}) window.location.href = '/signin' } diff --git a/ui/src/dashboards/actions/thunks.ts b/ui/src/dashboards/actions/thunks.ts index 4f6d0717f2..241d28a176 100644 --- a/ui/src/dashboards/actions/thunks.ts +++ b/ui/src/dashboards/actions/thunks.ts @@ -478,7 +478,7 @@ export const saveVEOView = (dashboardID: string) => async ( } } catch (error) { console.error(error) - dispatch(notify(copy.cellAddFailed())) + dispatch(notify(copy.cellAddFailed(error.message))) throw error } } diff --git a/ui/src/dataExplorer/components/SaveAsCellForm.tsx b/ui/src/dataExplorer/components/SaveAsCellForm.tsx index 8b8e565268..e24af776cb 100644 --- a/ui/src/dataExplorer/components/SaveAsCellForm.tsx +++ b/ui/src/dataExplorer/components/SaveAsCellForm.tsx @@ -13,8 +13,6 @@ import {Form, Input, Button, Grid} from '@influxdata/clockface' import {ErrorHandling} from 'src/shared/decorators/errors' import DashboardsDropdown from 'src/dataExplorer/components/DashboardsDropdown' -// Constants -import {cellAddFailed, cellAdded} from 'src/shared/copy/notifications' import { DashboardTemplate, DEFAULT_DASHBOARD_NAME, @@ -173,7 +171,6 @@ class SaveAsCellForm extends PureComponent { dashboards, view, dismiss, - notify, orgID, } = this.props const {targetDashboardIDs} = this.state @@ -186,21 +183,16 @@ class SaveAsCellForm extends PureComponent { try { targetDashboardIDs.forEach(dashID => { - let targetDashboardName = '' - try { - if (dashID === DashboardTemplate.id) { - targetDashboardName = newDashboardName || DEFAULT_DASHBOARD_NAME - onCreateDashboardWithView(orgID, newDashboardName, viewWithProps) - } else { - const selectedDashboard = dashboards.find(d => d.id === dashID) - targetDashboardName = selectedDashboard.name - onCreateCellWithView(selectedDashboard.id, viewWithProps) - } - notify(cellAdded(cellName, targetDashboardName)) - } catch { - notify(cellAddFailed(cellName, targetDashboardName)) + if (dashID === DashboardTemplate.id) { + onCreateDashboardWithView(orgID, newDashboardName, viewWithProps) + return } + + const selectedDashboard = dashboards.find(d => d.id === dashID) + onCreateCellWithView(selectedDashboard.id, viewWithProps) }) + } catch (error) { + console.error(error) } finally { this.resetForm() dismiss() diff --git a/ui/src/dataLoaders/actions/dataLoaders.ts b/ui/src/dataLoaders/actions/dataLoaders.ts index 021e479fcf..dc5359e2ba 100644 --- a/ui/src/dataLoaders/actions/dataLoaders.ts +++ b/ui/src/dataLoaders/actions/dataLoaders.ts @@ -621,12 +621,14 @@ export const writeLineProtocolAction = ( } else if (resp.status === 429) { dispatch(notify(readWriteCardinalityLimitReached(resp.data.message))) dispatch(setLPStatus(RemoteDataState.Error)) + } else if (resp.status === 403) { + dispatch(setLPStatus(RemoteDataState.Error, resp.data.message)) } else { + dispatch(setLPStatus(RemoteDataState.Error, 'failed to write data')) throw new Error(get(resp, 'data.message', 'Failed to write data')) } } catch (error) { console.error(error) - dispatch(setLPStatus(RemoteDataState.Error, error.message)) } } diff --git a/ui/src/notifications/endpoints/actions/thunks.ts b/ui/src/notifications/endpoints/actions/thunks.ts index 2da88f8faa..864ef0e9a2 100644 --- a/ui/src/notifications/endpoints/actions/thunks.ts +++ b/ui/src/notifications/endpoints/actions/thunks.ts @@ -107,6 +107,7 @@ export const createEndpoint = (endpoint: NotificationEndpoint) => async ( dispatch(checkEndpointsLimits()) } catch (error) { console.error(error) + dispatch(notify(copy.createEndpointFailed(error.message))) } } diff --git a/ui/src/shared/copy/notifications.ts b/ui/src/shared/copy/notifications.ts index 5974828523..286d6a68fe 100644 --- a/ui/src/shared/copy/notifications.ts +++ b/ui/src/shared/copy/notifications.ts @@ -166,6 +166,11 @@ export const dashboardCreateFailed = () => ({ message: 'Failed to create dashboard.', }) +export const dashboardCreateSuccess = () => ({ + ...defaultSuccessNotification, + message: 'Created dashboard successfully', +}) + export const dashboardDeleteFailed = ( name: string, errorMessage: string @@ -194,11 +199,15 @@ export const cellAdded = ( }) export const cellAddFailed = ( - cellName?: string, - dashboardName?: string + message: string = 'unknown error' ): Notification => ({ ...defaultErrorNotification, - message: `Failed to add cell ${cellName + ' '}to dashboard ${dashboardName}`, + message: `Failed to add cell: ${message}`, +}) + +export const cellCopyFailed = (): Notification => ({ + ...defaultErrorNotification, + message: 'Cell copy failed', }) export const cellUpdateFailed = (): Notification => ({