DashboardsPage can now delete a dashboard (tho not reflected in UI except on refresh)
parent
5b7d6bd0ae
commit
c2c805a596
|
@ -1,11 +1,14 @@
|
||||||
import {
|
import {
|
||||||
getDashboards as getDashboardsAJAX,
|
getDashboards as getDashboardsAJAX,
|
||||||
updateDashboard as updateDashboardAJAX,
|
updateDashboard as updateDashboardAJAX,
|
||||||
|
deleteDashboard as deleteDashboardAJAX,
|
||||||
updateDashboardCell as updateDashboardCellAJAX,
|
updateDashboardCell as updateDashboardCellAJAX,
|
||||||
addDashboardCell as addDashboardCellAJAX,
|
addDashboardCell as addDashboardCellAJAX,
|
||||||
deleteDashboardCell as deleteDashboardCellAJAX,
|
deleteDashboardCell as deleteDashboardCellAJAX,
|
||||||
} from 'src/dashboards/apis'
|
} from 'src/dashboards/apis'
|
||||||
|
|
||||||
|
import {publishNotification} from 'src/shared/actions/notifications';
|
||||||
|
|
||||||
import {NEW_DEFAULT_DASHBOARD_CELL} from 'src/dashboards/constants'
|
import {NEW_DEFAULT_DASHBOARD_CELL} from 'src/dashboards/constants'
|
||||||
|
|
||||||
export const loadDashboards = (dashboards, dashboardID) => ({
|
export const loadDashboards = (dashboards, dashboardID) => ({
|
||||||
|
@ -37,6 +40,20 @@ export const updateDashboard = (dashboard) => ({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const deleteDashboard = (dashboard) => ({
|
||||||
|
type: 'DELETE_DASHBOARD',
|
||||||
|
payload: {
|
||||||
|
dashboard,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export const undoDeleteDashboard = (dashboard) => ({
|
||||||
|
type: 'UNDO_DELETE_DASHBOARD',
|
||||||
|
payload: {
|
||||||
|
dashboard,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
export const updateDashboardCells = (cells) => ({
|
export const updateDashboardCells = (cells) => ({
|
||||||
type: 'UPDATE_DASHBOARD_CELLS',
|
type: 'UPDATE_DASHBOARD_CELLS',
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -109,6 +126,17 @@ export const updateDashboardCell = (cell) => (dispatch) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const deleteDashboardAsync = (dashboard) => async (dispatch) => {
|
||||||
|
dispatch(deleteDashboard(dashboard))
|
||||||
|
try {
|
||||||
|
await deleteDashboardAJAX(dashboard)
|
||||||
|
dispatch(publishNotification('success', 'Dashboard deleted successfully.'))
|
||||||
|
} catch (error) {
|
||||||
|
dispatch(undoDeleteDashboard(dashboard)) // undo optimistic update
|
||||||
|
dispatch(publishNotification('error', `Failed to delete dashboard: ${error.data.message}.`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const addDashboardCellAsync = (dashboard) => async (dispatch) => {
|
export const addDashboardCellAsync = (dashboard) => async (dispatch) => {
|
||||||
try {
|
try {
|
||||||
const {data} = await addDashboardCellAJAX(dashboard, NEW_DEFAULT_DASHBOARD_CELL)
|
const {data} = await addDashboardCellAJAX(dashboard, NEW_DEFAULT_DASHBOARD_CELL)
|
||||||
|
|
|
@ -36,6 +36,18 @@ export const createDashboard = async (dashboard) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const deleteDashboard = async (dashboard) => {
|
||||||
|
try {
|
||||||
|
return await AJAX({
|
||||||
|
method: 'DELETE',
|
||||||
|
url: dashboard.links.self,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const addDashboardCell = async (dashboard, cell) => {
|
export const addDashboardCell = async (dashboard, cell) => {
|
||||||
try {
|
try {
|
||||||
return await AJAX({
|
return await AJAX({
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
import React, {PropTypes} from 'react'
|
import React, {PropTypes} from 'react'
|
||||||
import {Link, withRouter} from 'react-router'
|
import {Link, withRouter} from 'react-router'
|
||||||
import SourceIndicator from '../../shared/components/SourceIndicator'
|
import {connect} from 'react-redux'
|
||||||
|
import {bindActionCreators} from 'redux'
|
||||||
|
|
||||||
|
import SourceIndicator from 'shared/components/SourceIndicator'
|
||||||
|
import DeleteConfirmTableCell from 'shared/components/DeleteConfirmTableCell'
|
||||||
|
|
||||||
import {getDashboards, createDashboard} from '../apis'
|
import {getDashboards, createDashboard} from '../apis'
|
||||||
|
import {deleteDashboardAsync} from 'src/dashboards/actions'
|
||||||
|
|
||||||
import {NEW_DASHBOARD} from 'src/dashboards/constants'
|
import {NEW_DASHBOARD} from 'src/dashboards/constants'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -26,6 +32,7 @@ const DashboardsPage = React.createClass({
|
||||||
push: func.isRequired,
|
push: func.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
addFlashMessage: func,
|
addFlashMessage: func,
|
||||||
|
handleDeleteDashboard: func.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
|
@ -50,6 +57,10 @@ const DashboardsPage = React.createClass({
|
||||||
push(`/sources/${id}/dashboards/${data.id}`)
|
push(`/sources/${id}/dashboards/${data.id}`)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleDeleteDashboard(dashboard) {
|
||||||
|
this.props.handleDeleteDashboard(dashboard)
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const dashboardLink = `/sources/${this.props.source.id}`
|
const dashboardLink = `/sources/${this.props.source.id}`
|
||||||
let tableHeader
|
let tableHeader
|
||||||
|
@ -95,12 +106,13 @@ const DashboardsPage = React.createClass({
|
||||||
{
|
{
|
||||||
this.state.dashboards.map((dashboard) => {
|
this.state.dashboards.map((dashboard) => {
|
||||||
return (
|
return (
|
||||||
<tr key={dashboard.id}>
|
<tr key={dashboard.id} className="">
|
||||||
<td className="monotype">
|
<td className="monotype">
|
||||||
<Link to={`${dashboardLink}/dashboards/${dashboard.id}`}>
|
<Link to={`${dashboardLink}/dashboards/${dashboard.id}`}>
|
||||||
{dashboard.name}
|
{dashboard.name}
|
||||||
</Link>
|
</Link>
|
||||||
</td>
|
</td>
|
||||||
|
<DeleteConfirmTableCell onDelete={this.handleDeleteDashboard} item={dashboard} />
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
@ -125,4 +137,8 @@ const DashboardsPage = React.createClass({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export default withRouter(DashboardsPage)
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
handleDeleteDashboard: bindActionCreators(deleteDashboardAsync, dispatch),
|
||||||
|
})
|
||||||
|
|
||||||
|
export default connect(null, mapDispatchToProps)(withRouter(DashboardsPage))
|
||||||
|
|
|
@ -48,6 +48,26 @@ export default function ui(state = initialState, action) {
|
||||||
return {...state, ...newState}
|
return {...state, ...newState}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'DELETE_DASHBOARD': {
|
||||||
|
const {dashboard} = action.payload
|
||||||
|
const newState = {
|
||||||
|
dashboards: state.dashboards.filter((d) => d.id !== dashboard.id),
|
||||||
|
}
|
||||||
|
|
||||||
|
return {...state, ...newState}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'UNDO_DELETE_DASHBOARD': {
|
||||||
|
const {dashboard} = action.payload
|
||||||
|
const newState = {
|
||||||
|
dashboards: [
|
||||||
|
_.cloneDeep(dashboard),
|
||||||
|
...state.dashboards,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
return {...state, ...newState}
|
||||||
|
}
|
||||||
|
|
||||||
case 'UPDATE_DASHBOARD_CELLS': {
|
case 'UPDATE_DASHBOARD_CELLS': {
|
||||||
const {cells} = action.payload
|
const {cells} = action.payload
|
||||||
const {dashboard} = state
|
const {dashboard} = state
|
||||||
|
|
Loading…
Reference in New Issue