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
pull/17676/head
Andrew Watkins 2020-04-08 08:31:31 -07:00 committed by GitHub
parent 45250eeda2
commit 9d791d12ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 32 deletions

View File

@ -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<Dashboard, DashboardEntities, string>(
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<View, ViewEntities, string>(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)
}
}

View File

@ -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'
}

View File

@ -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
}
}

View File

@ -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<Props, State> {
dashboards,
view,
dismiss,
notify,
orgID,
} = this.props
const {targetDashboardIDs} = this.state
@ -186,21 +183,16 @@ class SaveAsCellForm extends PureComponent<Props, State> {
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()

View File

@ -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))
}
}

View File

@ -107,6 +107,7 @@ export const createEndpoint = (endpoint: NotificationEndpoint) => async (
dispatch(checkEndpointsLimits())
} catch (error) {
console.error(error)
dispatch(notify(copy.createEndpointFailed(error.message)))
}
}

View File

@ -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 => ({