Add edit rp tests and refactor edit rp action

pull/10616/head
Andrew Watkins 2017-03-21 17:08:02 -07:00
parent e293acc78d
commit e2eabbaed6
6 changed files with 18 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import {
editUser,
editRole,
editDatabase,
editRetentionPolicy,
loadRoles,
loadPermissions,
deleteRole,
@ -209,6 +210,16 @@ describe('Admin.Reducers', () => {
expect(actual.databases).to.deep.equal(expected)
})
it('can edit a retention policy', () => {
const updates = {name: 'rpOne', duration: '100y', replication: '42'}
const actual = reducer(state, editRetentionPolicy(db1, rp1, updates))
const expected = [
{...db1, retentionPolicies: [{...rp1, ...updates}]},
]
expect(actual.databases).to.deep.equal(expected)
})
})
it('it can add a user', () => {

View File

@ -198,11 +198,12 @@ export const removeDatabaseDeleteCode = (database) => ({
},
})
export const editRetentionPolicy = (database, retentionPolicy) => ({
export const editRetentionPolicy = (database, retentionPolicy, updates) => ({
type: 'EDIT_RETENTION_POLICY',
payload: {
database,
retentionPolicy,
updates,
},
})
@ -288,10 +289,10 @@ export const createRetentionPolicyAsync = (url, retentionPolicy) => async (dispa
}
}
export const updateRetentionPolicyAsync = (database, retentionPolicy) => async (dispatch) => {
export const updateRetentionPolicyAsync = (database, retentionPolicy, updates) => async (dispatch) => {
try {
// TODO: implement once server is up
dispatch(editRetentionPolicy(database, retentionPolicy))
dispatch(editRetentionPolicy(database, retentionPolicy, updates))
// const {data} = await createRetentionPolicyAJAX(url, retentionPolicy)
dispatch(publishNotification('success', 'Retention policy updated successfully'))
// dispatch(syncRetentionPolicy(retentionPolicy, {...data, id: uuid.v4()}))

View File

@ -12,7 +12,6 @@ const DatabaseManager = ({
onStartDeleteDatabase,
onDatabaseDeleteConfirm,
onAddRetentionPolicy,
onEditRetentionPolicy,
onStopEditRetentionPolicy,
onCancelRetentionPolicy,
onCreateRetentionPolicy,
@ -39,7 +38,6 @@ const DatabaseManager = ({
onStartDeleteDatabase={onStartDeleteDatabase}
onDatabaseDeleteConfirm={onDatabaseDeleteConfirm}
onAddRetentionPolicy={onAddRetentionPolicy}
onEditRetentionPolicy={onEditRetentionPolicy}
onStopEditRetentionPolicy={onStopEditRetentionPolicy}
onCancelRetentionPolicy={onCancelRetentionPolicy}
onCreateRetentionPolicy={onCreateRetentionPolicy}

View File

@ -133,7 +133,7 @@ class DatabaseRow extends Component {
return
}
onUpdate(database, {...retentionPolicy, ...validInputs})
onUpdate(database, retentionPolicy, validInputs)
this.handleEndEdit()
}

View File

@ -34,7 +34,6 @@ class DatabaseManagerPage extends Component {
onConfirmDatabase={actions.createDatabaseAsync}
onStartDeleteDatabase={actions.addDatabaseDeleteCode}
onAddRetentionPolicy={actions.addRetentionPolicy}
onEditRetentionPolicy={actions.editRetentionPolicy}
onCreateRetentionPolicy={actions.createRetentionPolicyAsync}
onUpdateRetentionPolicy={actions.updateRetentionPolicyAsync}
onRemoveRetentionPolicy={actions.removeRetentionPolicy}
@ -106,7 +105,6 @@ DatabaseManagerPage.propTypes = {
removeDatabase: func,
startDeleteDatabase: func,
removeDatabaseDeleteCode: func,
editRetentionPolicy: func,
removeRetentionPolicy: func,
}),
notify: func,

View File

@ -128,12 +128,12 @@ export default function admin(state = initialState, action) {
}
case 'EDIT_RETENTION_POLICY': {
const {database, retentionPolicy} = action.payload
const {database, retentionPolicy, updates} = action.payload
const newState = {
databases: state.databases.map(db => db.links.self === database.links.self ? {
...db,
retentionPolicies: db.retentionPolicies.map(rp => rp.links.self === retentionPolicy.links.self ? {...rp, ...retentionPolicy} : rp),
retentionPolicies: db.retentionPolicies.map(rp => rp.links.self === retentionPolicy.links.self ? {...rp, ...updates} : rp),
} : db),
}