From e2eabbaed6ac7b353ab6a20d80892198899ab9d8 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Tue, 21 Mar 2017 17:08:02 -0700 Subject: [PATCH] Add edit rp tests and refactor edit rp action --- ui/spec/admin/reducers/adminSpec.js | 11 +++++++++++ ui/src/admin/actions/index.js | 7 ++++--- ui/src/admin/components/DatabaseManager.js | 2 -- ui/src/admin/components/DatabaseRow.js | 2 +- ui/src/admin/containers/DatabaseManagerPage.js | 2 -- ui/src/admin/reducers/admin.js | 4 ++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ui/spec/admin/reducers/adminSpec.js b/ui/spec/admin/reducers/adminSpec.js index ff15d75529..5d8dec75e8 100644 --- a/ui/spec/admin/reducers/adminSpec.js +++ b/ui/spec/admin/reducers/adminSpec.js @@ -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', () => { diff --git a/ui/src/admin/actions/index.js b/ui/src/admin/actions/index.js index 873925ecc6..7cfb9894e8 100644 --- a/ui/src/admin/actions/index.js +++ b/ui/src/admin/actions/index.js @@ -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()})) diff --git a/ui/src/admin/components/DatabaseManager.js b/ui/src/admin/components/DatabaseManager.js index 22769291d2..5568de6a93 100644 --- a/ui/src/admin/components/DatabaseManager.js +++ b/ui/src/admin/components/DatabaseManager.js @@ -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} diff --git a/ui/src/admin/components/DatabaseRow.js b/ui/src/admin/components/DatabaseRow.js index 519da08121..e18ee85920 100644 --- a/ui/src/admin/components/DatabaseRow.js +++ b/ui/src/admin/components/DatabaseRow.js @@ -133,7 +133,7 @@ class DatabaseRow extends Component { return } - onUpdate(database, {...retentionPolicy, ...validInputs}) + onUpdate(database, retentionPolicy, validInputs) this.handleEndEdit() } diff --git a/ui/src/admin/containers/DatabaseManagerPage.js b/ui/src/admin/containers/DatabaseManagerPage.js index 02680ed1ca..d4ca446b0c 100644 --- a/ui/src/admin/containers/DatabaseManagerPage.js +++ b/ui/src/admin/containers/DatabaseManagerPage.js @@ -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, diff --git a/ui/src/admin/reducers/admin.js b/ui/src/admin/reducers/admin.js index 1dd1bb610e..2f607add9e 100644 --- a/ui/src/admin/reducers/admin.js +++ b/ui/src/admin/reducers/admin.js @@ -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), }