-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip - needs some clean up * See description - Deletes unused code - Pulls out state access into the ActivityLog page context * More code deletion; Adds user context function - Deletes unnecessary code from the composed filter - Adds a new function the users context - Adds needed context calls to the ActivityLog channel module * Renaming Renames some declarations * Refactors activity_log channel * Fixes warning Fix for identityFunctionCheck warning in console. * Runs formatter * Renaming * Adds some tests - channel test for activity log - activity log state test * Runs js code formatter * Fix for failing tests Adds a hook that passes in requisite state to the ActivityLogPage component * Deletes an unused import; format * Some cleanup Specific users in list are not necessary * Adds a system user Previously a system user was not returned; now it is possible to filter the system activity log entries. * Refactors ActivityLogPage test * Adds test for activityLog users selector * Adds tests for ActivityLogChannel * Adds a test for a Users context function * Addresses PR comments Renaming * Handles scenario with deleted users Collapses usernames from deleted users into a username without timestamp suffix * Renaming alUsers -> activityLogUsers * Adds test case for non-empty initial state * Formatting * Makes refresh interval a parameter According to PR conversation, the update push interval from the channel is now a compile time Application env variable. * Addresses PR comment The users context function modified here now returns username tupled with the deleted_at timestamp. This simplifies somewhat the implementation of the collapse_usernames function in the ActivityLogChannel module. Specifically, this function no longer needs to do any DateTime parsing to infer soft deleted users/associated usernames. * Adds an additional jest test This test makes use of non empty/non default state to assert on number of user filter options rendered. * Updates tests Some changes introduced post rebase were breaking a test. This commit fixes the failing test. * Formatting - import re-ordering/spacing, etc. * Adds a saga test * Renames users context function Removes the trailing _ts * Reodering imports In order to minimize diffs/conflicts
- Loading branch information
1 parent
aa25160
commit 37aa303
Showing
20 changed files
with
288 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createAction, createSlice } from '@reduxjs/toolkit'; | ||
|
||
export const initialState = { | ||
users: [], | ||
}; | ||
|
||
export const activityLogSlice = createSlice({ | ||
name: 'activityLog', | ||
initialState, | ||
reducers: { | ||
setUsers(state, { payload: { users } }) { | ||
state.users = users; | ||
}, | ||
}, | ||
}); | ||
|
||
export const ACTIVITY_LOG_USERS_PUSHED = 'ACTIVITY_LOG_USERS_PUSHED'; | ||
export const activityLogUsersPushed = createAction(ACTIVITY_LOG_USERS_PUSHED); | ||
export const { setUsers } = activityLogSlice.actions; | ||
|
||
export default activityLogSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { userFactory } from '@lib/test-utils/factories/users'; | ||
|
||
import activityLogReducer, { setUsers, initialState } from './activityLog'; | ||
|
||
describe('activityLog reducer', () => { | ||
it('should set the users for activity log when setUsers is dispatched', () => { | ||
const { username: username1 } = userFactory.build(); | ||
const { username: username2 } = userFactory.build(); | ||
const users = [username1, username2]; | ||
const action = setUsers({ users }); | ||
expect(activityLogReducer(initialState, action)).toEqual({ | ||
users, | ||
}); | ||
}); | ||
|
||
it('should set the users for activity log when setUsers is dispatched with non empty initial state', () => { | ||
const { username: username1 } = userFactory.build(); | ||
const { username: username2 } = userFactory.build(); | ||
const { username: username3 } = userFactory.build(); | ||
const users = [username1, username2]; | ||
const nonEmptyInitialState = { users: [username3] }; | ||
const action = setUsers({ users }); | ||
expect(activityLogReducer(nonEmptyInitialState, action)).toEqual({ | ||
users, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { put, takeEvery } from 'redux-saga/effects'; | ||
import { setUsers, ACTIVITY_LOG_USERS_PUSHED } from '@state/activityLog'; | ||
|
||
export function* activityLogUsersUpdate({ payload: { users } }) { | ||
yield put(setUsers({ users })); | ||
} | ||
|
||
export function* watchActivityLogActions() { | ||
yield takeEvery(ACTIVITY_LOG_USERS_PUSHED, activityLogUsersUpdate); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { recordSaga } from '@lib/test-utils'; | ||
import { userFactory } from '@lib/test-utils/factories/users'; | ||
import { setUsers } from '@state/activityLog'; | ||
import { activityLogUsersUpdate } from './activityLog'; | ||
|
||
describe('Activity Logs saga', () => { | ||
it('should set users when activity log users are updated', async () => { | ||
const users = userFactory.buildList(5).map((user) => user.username); | ||
|
||
const dispatched = await recordSaga(activityLogUsersUpdate, { | ||
payload: { users }, | ||
}); | ||
|
||
expect(dispatched).toEqual([setUsers({ users })]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { | |
setExecutionStarted, | ||
} from '@state/lastExecutions'; | ||
import { userUpdated } from '@state/user'; | ||
import { activityLogUsersPushed } from '@state/activityLog'; | ||
|
||
import { watchSocketEvents } from './channels'; | ||
|
||
|
@@ -48,6 +49,7 @@ const channels = { | |
'monitoring:databases': new MockChannel(), | ||
'monitoring:executions': new MockChannel(), | ||
[`users:${USER_ID}`]: new MockChannel(), | ||
[`activity_log:${USER_ID}`]: new MockChannel(), | ||
}; | ||
|
||
const mockSocket = { | ||
|
@@ -125,4 +127,18 @@ describe('Channels saga', () => { | |
|
||
expect(dispatched).toEqual([userUpdated({ email: '[email protected]' })]); | ||
}); | ||
it('should listen to specific activity log events', async () => { | ||
const { saga, dispatched } = runWatchSocketEventsSaga(mockSocket); | ||
|
||
channels[`activity_log:${USER_ID}`].emit('al_users_pushed', { | ||
users: ['user1', 'user2', 'user3'], | ||
}); | ||
|
||
closeSocket(); | ||
await saga; | ||
|
||
expect(dispatched).toEqual([ | ||
activityLogUsersPushed({ users: ['user1', 'user2', 'user3'] }), | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
|
||
export const getActivityLogUsers = createSelector( | ||
[(state) => state.activityLog], | ||
(activityLog) => activityLog.users | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getActivityLogUsers } from './activityLog'; | ||
|
||
describe('Activity Log users selector', () => { | ||
it('should return a list of users from activity log state', () => { | ||
const users = ['user1', 'user2', 'user3']; | ||
const state = { | ||
activityLog: { users }, | ||
}; | ||
|
||
expect(getActivityLogUsers(state)).toEqual(users); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.