Add edit rp tests and refactor edit rp action
parent
e293acc78d
commit
e2eabbaed6
|
@ -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', () => {
|
||||
|
|
|
@ -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()}))
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -133,7 +133,7 @@ class DatabaseRow extends Component {
|
|||
return
|
||||
}
|
||||
|
||||
onUpdate(database, {...retentionPolicy, ...validInputs})
|
||||
onUpdate(database, retentionPolicy, validInputs)
|
||||
this.handleEndEdit()
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue