WIP delete mapping in redux

pull/2755/head
Iris Scholten 2018-01-30 11:27:30 -08:00
parent 6f0b3ae48e
commit a460e6c81f
4 changed files with 19 additions and 3 deletions

View File

@ -117,6 +117,13 @@ export const createMapping = mapping => ({
},
})
export const deleteMapping = mapping => ({
type: 'CHRONOGRAF_DELETE_MAPPING',
payload: {
mapping,
},
})
// async actions (thunks)
export const loadUsersAsync = url => async dispatch => {
try {

View File

@ -21,6 +21,7 @@ class ProvidersTable extends Component {
handleCreateMap = newMap => {
const {onCreateMap} = this.props
//todo: better way of getting mapping id
this.setState({isCreatingMap: false})
const newMapID = this.props.mappings.length.toString()
newMap.id = newMapID

View File

@ -6,7 +6,6 @@ import * as adminChronografActionCreators from 'src/admin/actions/chronograf'
import {publishAutoDismissingNotification} from 'shared/dispatchers'
import ProvidersTable from 'src/admin/components/chronograf/ProvidersTable'
import {createMapping} from '../actions/chronograf'
class ProvidersPage extends Component {
constructor(props) {
@ -24,7 +23,6 @@ class ProvidersPage extends Component {
}
handleCreateMap = mapping => {
// update the redux store
this.props.actions.createMapping(mapping)
}
@ -35,7 +33,9 @@ class ProvidersPage extends Component {
// update the server
}
handleDeleteMap = () => {}
handleDeleteMap = mapping => {
this.props.actions.deleteMapping(mapping)
}
render() {
const {organizations, mappings = []} = this.props

View File

@ -123,6 +123,14 @@ const adminChronograf = (state = initialState, action) => {
mappings: [...state.mappings, mapping],
}
}
case 'CHRONOGRAF_DELETE_MAPPING': {
const {mapping} = action.payload
return {
...state,
mappings: state.mappings.filter(m => m.id !== mapping.id),
}
}
}
return state