Skip to content

Commit

Permalink
Remove unused user filtering (#131316)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanatia authored May 2, 2022
1 parent 4f89914 commit 7e5408b
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface Group {
createdAt: string;
updatedAt: string;
contentSources: ContentSource[];
users: User[];
usersCount: number;
color?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import { DEFAULT_META } from '../../../../shared/constants';
import { ContentSource, User, Group } from '../../../types';
import { ContentSource, Group } from '../../../types';

export const mockGroupsValues = {
groups: [] as Group[],
contentSources: [] as ContentSource[],
users: [] as User[],
groupsDataLoading: true,
groupListLoading: true,
newGroupModalOpen: false,
Expand All @@ -21,10 +20,6 @@ export const mockGroupsValues = {
newGroupNameErrors: [],
filterSourcesDropdownOpen: false,
filteredSources: [],
filterUsersDropdownOpen: false,
filteredUsers: [],
allGroupUsersLoading: false,
allGroupUsers: [],
filterValue: '',
groupsMeta: DEFAULT_META,
};
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ describe('GroupOverview', () => {
...mockValues,
group: {
...groups[0],
users: [],
contentSources: [],
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ export const NO_SOURCES_MESSAGE = i18n.translate(
defaultMessage: 'No organizational content sources',
}
);
export const NO_USERS_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.groups.noUsersMessage',
{
defaultMessage: 'No users',
}
);

const dateDisplay = (date: string) =>
moment(date).isAfter(moment().subtract(DAYS_CUTOFF, 'days'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const Groups: React.FC = () => {
page: { total_results: numGroups },
},
filteredSources,
filteredUsers,
filterValue,
} = useValues(GroupsLogic);

Expand All @@ -47,7 +46,7 @@ export const Groups: React.FC = () => {
useEffect(() => {
getSearchResults(true);
return resetGroups;
}, [filteredSources, filteredUsers, filterValue]);
}, [filteredSources, filterValue]);

if (newGroup && hasMessages) {
messages[0].description = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '../../../__mocks__/kea_logic';
import { contentSources } from '../../__mocks__/content_sources.mock';
import { groups } from '../../__mocks__/groups.mock';
import { users } from '../../__mocks__/users.mock';
import { mockGroupsValues } from './__mocks__/groups_logic.mock';

import { nextTick } from '@kbn/test-jest-helpers';
Expand Down Expand Up @@ -49,13 +48,12 @@ describe('GroupsLogic', () => {
describe('actions', () => {
describe('onInitializeGroups', () => {
it('sets reducers', () => {
GroupsLogic.actions.onInitializeGroups({ contentSources, users });
GroupsLogic.actions.onInitializeGroups({ contentSources });

expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
groupsDataLoading: false,
contentSources,
users,
});
});
});
Expand Down Expand Up @@ -103,59 +101,6 @@ describe('GroupsLogic', () => {
});
});

describe('addFilteredUser', () => {
it('sets reducers', () => {
GroupsLogic.actions.addFilteredUser('foo');
GroupsLogic.actions.addFilteredUser('bar');
GroupsLogic.actions.addFilteredUser('baz');

expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
hasFiltersSet: true,
filteredUsers: ['bar', 'baz', 'foo'],
});
});
});

describe('removeFilteredUser', () => {
it('sets reducers', () => {
GroupsLogic.actions.addFilteredUser('foo');
GroupsLogic.actions.addFilteredUser('bar');
GroupsLogic.actions.addFilteredUser('baz');
GroupsLogic.actions.removeFilteredUser('foo');

expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
hasFiltersSet: true,
filteredUsers: ['bar', 'baz'],
});
});
});

describe('setGroupUsers', () => {
it('sets reducers', () => {
GroupsLogic.actions.setGroupUsers(users);

expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
allGroupUsersLoading: false,
allGroupUsers: users,
});
});
});

describe('setAllGroupLoading', () => {
it('sets reducer', () => {
GroupsLogic.actions.setAllGroupLoading(true);

expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
allGroupUsersLoading: true,
allGroupUsers: [],
});
});
});

describe('setFilterValue', () => {
it('sets reducer', () => {
GroupsLogic.actions.setFilterValue('foo');
Expand Down Expand Up @@ -190,7 +135,6 @@ describe('GroupsLogic', () => {
newGroup: groups[0],
newGroupNameErrors: [],
filteredSources: [],
filteredUsers: [],
groupsMeta: DEFAULT_META,
});
});
Expand Down Expand Up @@ -234,19 +178,6 @@ describe('GroupsLogic', () => {
});
});

describe('closeFilterUsersDropdown', () => {
it('sets reducer', () => {
// Open dropdown first
GroupsLogic.actions.toggleFilterUsersDropdown();
GroupsLogic.actions.closeFilterUsersDropdown();

expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
filterUsersDropdownOpen: false,
});
});
});

describe('setGroupsLoading', () => {
it('sets reducer', () => {
// Set to false first
Expand Down Expand Up @@ -294,7 +225,6 @@ describe('GroupsLogic', () => {
const search = {
query: '',
content_source_ids: [],
user_ids: [],
};

const payload = {
Expand Down Expand Up @@ -352,22 +282,6 @@ describe('GroupsLogic', () => {
});
});

describe('fetchGroupUsers', () => {
it('calls API and sets values', async () => {
const setGroupUsersSpy = jest.spyOn(GroupsLogic.actions, 'setGroupUsers');
http.get.mockReturnValue(Promise.resolve(users));

GroupsLogic.actions.fetchGroupUsers('123');
expect(http.get).toHaveBeenCalledWith('/internal/workplace_search/groups/123/group_users');
await nextTick();
expect(setGroupUsersSpy).toHaveBeenCalledWith(users);
});

itShowsServerErrorAsFlashMessage(http.get, () => {
GroupsLogic.actions.fetchGroupUsers('123');
});
});

describe('saveNewGroup', () => {
it('calls API and sets values', async () => {
const GROUP_NAME = 'new group';
Expand Down Expand Up @@ -430,7 +344,6 @@ describe('GroupsLogic', () => {
expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
filteredSources: [],
filteredUsers: [],
filterValue: '',
groupsMeta: DEFAULT_META,
});
Expand All @@ -449,17 +362,5 @@ describe('GroupsLogic', () => {
expect(clearFlashMessages).toHaveBeenCalled();
});
});

describe('toggleFilterUsersDropdown', () => {
it('sets reducer and clears flash messages', () => {
GroupsLogic.actions.toggleFilterUsersDropdown();

expect(GroupsLogic.values).toEqual({
...mockGroupsValues,
filterUsersDropdownOpen: true,
});
expect(clearFlashMessages).toHaveBeenCalled();
});
});
});
});
Loading

0 comments on commit 7e5408b

Please sign in to comment.