-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6779 from owncloud/accounts-filter
Add search to usersManagement
- Loading branch information
Showing
11 changed files
with
312 additions
and
15 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
55 changes: 55 additions & 0 deletions
55
packages/web-app-user-management/src/search/filter/index.ts
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,55 @@ | ||
import { SearchProvider } from 'search/src/types' | ||
import { EventBus } from 'web-pkg/src/event' | ||
import VueRouter, { Route } from 'vue-router' | ||
|
||
function $gettext(msg) { | ||
return msg | ||
} | ||
|
||
const kind = (currentRoute: Route): 'users' | 'groups' | undefined => { | ||
switch (currentRoute.name) { | ||
case 'user-management-users': | ||
return 'users' | ||
case 'user-management-groups': | ||
return 'groups' | ||
default: | ||
return undefined | ||
} | ||
} | ||
|
||
export default class Provider extends EventBus implements SearchProvider { | ||
public readonly id: string | ||
private readonly router: VueRouter | ||
|
||
constructor(router: VueRouter) { | ||
super() | ||
|
||
this.id = 'usersManagement.filter' | ||
this.router = router | ||
} | ||
|
||
public get label(): string { | ||
switch (kind(this.router.currentRoute)) { | ||
case 'users': | ||
return $gettext('Search users ↵') | ||
case 'groups': | ||
return $gettext('Search groups ↵') | ||
} | ||
} | ||
|
||
public activate(term: string): void { | ||
/* noop */ | ||
} | ||
|
||
public reset(): void { | ||
/* noop */ | ||
} | ||
|
||
public updateTerm(term: string): void { | ||
this.publish('updateTerm', { kind: kind(this.router.currentRoute), term }) | ||
} | ||
|
||
public get available(): boolean { | ||
return !!kind(this.router.currentRoute) | ||
} | ||
} |
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 @@ | ||
export { default as FilterSearch } from './filter' |
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 @@ | ||
export { default as Registry } from './registry' |
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,5 @@ | ||
import { FilterSearch } from '../search' | ||
|
||
export default class Registry { | ||
static search: FilterSearch | ||
} |
73 changes: 73 additions & 0 deletions
73
packages/web-app-user-management/tests/unit/components/Groups/GroupsList.spec.js
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,73 @@ | ||
import Vuex from 'vuex' | ||
import { mount, createLocalVue } from '@vue/test-utils' | ||
import UsersList from '../../../../src/components/Groups/GroupsList' | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
|
||
afterEach(() => jest.clearAllMocks()) | ||
|
||
describe('GroupsList', () => { | ||
describe('method "orderBy"', () => { | ||
it('should return an ascending ordered list while desc is set to false', () => { | ||
const wrapper = getMountedWrapper() | ||
|
||
expect( | ||
wrapper.vm.orderBy( | ||
[{ displayName: 'users' }, { displayName: 'admins' }], | ||
'displayName', | ||
false | ||
) | ||
).toEqual([{ displayName: 'admins' }, { displayName: 'users' }]) | ||
}) | ||
it('should return an descending ordered list while desc is set to true', () => { | ||
const wrapper = getMountedWrapper() | ||
|
||
expect( | ||
wrapper.vm.orderBy( | ||
[{ displayName: 'admins' }, { displayName: 'users' }], | ||
'displayName', | ||
true | ||
) | ||
).toEqual([{ displayName: 'users' }, { displayName: 'admins' }]) | ||
}) | ||
}) | ||
|
||
describe('method "filter"', () => { | ||
it('should return a list containing record admins if search term is "ad"', () => { | ||
const wrapper = getMountedWrapper() | ||
|
||
expect( | ||
wrapper.vm.filter([{ displayName: 'users' }, { displayName: 'admins' }], 'ad') | ||
).toEqual([{ displayName: 'admins' }]) | ||
}) | ||
it('should return an an empty list if search term does not match any entry', () => { | ||
const wrapper = getMountedWrapper() | ||
|
||
expect( | ||
wrapper.vm.filter([{ displayName: 'admins' }, { displayName: 'users' }], 'ownClouders') | ||
).toEqual([]) | ||
}) | ||
}) | ||
}) | ||
|
||
function getMountedWrapper({ propsData = {} } = {}) { | ||
return mount(UsersList, { | ||
localVue, | ||
mocks: { | ||
$gettext: jest.fn(), | ||
$gettextInterpolate: jest.fn() | ||
}, | ||
propsData: { | ||
groups: [], | ||
selectedGroups: [], | ||
...propsData | ||
}, | ||
stubs: { | ||
'avatar-image': true, | ||
'oc-checkbox': true, | ||
'oc-button': true, | ||
'oc-table': { template: '<div></div>' } | ||
} | ||
}) | ||
} |
Oops, something went wrong.