-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UIU-2943: ECS - Filter users by "User Type" #2555
Changes from 8 commits
9fae86c
b950576
9caff0b
301e14a
10d70d4
defa483
83c0208
6ed49c7
89fd81d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,23 @@ import { | |
retrieveNoteReferredEntityDataFromLocationState, | ||
getClosedRequestStatusesFilterString, | ||
getOpenRequestStatusesFilterString, | ||
getCentralTenantId, | ||
isConsortiumEnabled, | ||
getRequestUrl, | ||
} from './util'; | ||
|
||
const STRIPES = { | ||
hasPerm: jest.fn().mockReturnValue(true), | ||
hasInterface: jest.fn().mockReturnValue(true), | ||
user: { | ||
user: { | ||
consortium: { | ||
centralTenantId: 'centralTenantId' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
describe('accountsMatchStatus', () => { | ||
it('returns true if all accounts match', () => { | ||
const status = 'monkey'; | ||
|
@@ -366,6 +380,30 @@ describe('getContributors', () => { | |
}); | ||
}); | ||
|
||
describe('isConsortiumEnabled', () => { | ||
it('should return false', () => { | ||
const data = isConsortiumEnabled(); | ||
expect(data).toBeFalsy(); | ||
}); | ||
|
||
it('should return true', () => { | ||
const data = isConsortiumEnabled(STRIPES); | ||
expect(data).toBe(true); | ||
}); | ||
Comment on lines
+389
to
+392
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Eh, never mind, this is somewhat covered in the tests below. The test descriptions could still be improved though. |
||
}); | ||
|
||
describe('getCentralTenantId ', () => { | ||
it('should return undefined if consortium object is absent', () => { | ||
const data = getCentralTenantId({ ...STRIPES, user: { user: { } } }); | ||
expect(data).toBe(undefined); | ||
}); | ||
|
||
it('should return centralTenantId if consortium object and id is present', () => { | ||
const data = getCentralTenantId(STRIPES); | ||
expect(data).toBe(STRIPES.user.user.consortium.centralTenantId); | ||
}); | ||
}); | ||
|
||
describe('getRequestUrl', () => { | ||
it('should return url with user barcode', () => { | ||
const userBarcode = 'userBarcode'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,24 +4,24 @@ import { | |
FormattedMessage, | ||
injectIntl, | ||
} from 'react-intl'; | ||
import { | ||
get, | ||
} from 'lodash'; | ||
import { get } from 'lodash'; | ||
|
||
import { | ||
Accordion, | ||
AccordionSet, | ||
FilterAccordionHeader, | ||
} from '@folio/stripes/components'; | ||
|
||
import { stripesConnect } from '@folio/stripes/core'; | ||
import { | ||
CheckboxFilter, | ||
MultiSelectionFilter, | ||
} from '@folio/stripes/smart-components'; | ||
|
||
import { statusFilter } from '../../constants'; | ||
|
||
import CustomFieldsFilters from '../../components/CustomFieldsFilters'; | ||
import { isConsortiumEnabled } from '../../components/util'; | ||
import { USER_TYPES, statusFilter } from '../../constants'; | ||
|
||
const ACCORDION_ID_PREFIX = 'users_filter_accordion'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constants, ❤️ . But please keep the same value that was there previously, with hyphens instead of underscores. I know this didn't break any tests, but who knows what else might rely on that value; if we can preserve it then we should. |
||
|
||
class Filters extends React.Component { | ||
static propTypes = { | ||
|
@@ -34,6 +34,7 @@ class Filters extends React.Component { | |
resultOffset: PropTypes.shape({ | ||
replace: PropTypes.func.isRequired, | ||
}), | ||
stripes: PropTypes.object.isRequired, | ||
}; | ||
|
||
static defaultProps = { | ||
|
@@ -85,21 +86,44 @@ class Filters extends React.Component { | |
onChangeHandlers: { clearGroup }, | ||
intl: { formatMessage }, | ||
resources, | ||
stripes, | ||
} = this.props; | ||
const { | ||
active = [], | ||
pg = [], | ||
tags = [], | ||
departments = [], | ||
userType, | ||
} = activeFilters; | ||
|
||
const departmentsAreNotEmpty = !!resources.departments?.records?.length; | ||
|
||
const isConsortium = isConsortiumEnabled(stripes); | ||
const { PATRON, SHADOW, STAFF, SYSTEM } = USER_TYPES; | ||
const userTypeOptions = [ | ||
{ | ||
value: PATRON, | ||
label: formatMessage({ id: 'ui-users.information.userType.patron' }), | ||
}, | ||
{ | ||
value: STAFF, | ||
label: formatMessage({ id: 'ui-users.information.userType.staff' }), | ||
}, | ||
{ | ||
value: SHADOW, | ||
label: formatMessage({ id: 'ui-users.information.userType.shadow' }), | ||
}, | ||
{ | ||
value: SYSTEM, | ||
label: formatMessage({ id: 'ui-users.information.userType.system' }), | ||
} | ||
]; | ||
|
||
return ( | ||
<AccordionSet> | ||
<Accordion | ||
displayClearButton | ||
id="users-filter-accordion-status" | ||
id={`${ACCORDION_ID_PREFIX}_status`} | ||
alisher-epam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
header={FilterAccordionHeader} | ||
label={formatMessage({ id: 'ui-users.status' })} | ||
separator={false} | ||
|
@@ -114,7 +138,7 @@ class Filters extends React.Component { | |
</Accordion> | ||
<Accordion | ||
displayClearButton | ||
id="users-filter-accordion-patron-group" | ||
id={`${ACCORDION_ID_PREFIX}_patron_group`} | ||
alisher-epam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
header={FilterAccordionHeader} | ||
label={formatMessage({ id: 'ui-users.information.patronGroup' })} | ||
separator={false} | ||
|
@@ -130,7 +154,7 @@ class Filters extends React.Component { | |
{departmentsAreNotEmpty && ( | ||
<Accordion | ||
displayClearButton | ||
id="users-filter-accordion-departments" | ||
id={`${ACCORDION_ID_PREFIX}_departments`} | ||
alisher-epam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
header={FilterAccordionHeader} | ||
label={formatMessage({ id: 'ui-users.departments' })} | ||
separator={false} | ||
|
@@ -147,7 +171,7 @@ class Filters extends React.Component { | |
)} | ||
<Accordion | ||
displayClearButton | ||
id="users-filter-accordion-tags" | ||
id={`${ACCORDION_ID_PREFIX}_tags`} | ||
alisher-epam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
header={FilterAccordionHeader} | ||
label={formatMessage({ id: 'ui-users.tags' })} | ||
separator={false} | ||
|
@@ -161,6 +185,25 @@ class Filters extends React.Component { | |
aria-labelledby="users-filter-accordion-tags" | ||
/> | ||
</Accordion> | ||
{ | ||
isConsortium && ( | ||
<Accordion | ||
displayClearButton | ||
id={`${ACCORDION_ID_PREFIX}_userTypes`} | ||
alisher-epam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
header={FilterAccordionHeader} | ||
label={formatMessage({ id: 'ui-users.userType' })} | ||
separator={false} | ||
onClearFilter={() => clearGroup('userType')} | ||
> | ||
<CheckboxFilter | ||
dataOptions={userTypeOptions} | ||
name="userType" | ||
selectedValues={userType} | ||
onChange={this.handleFilterChange} | ||
/> | ||
</Accordion> | ||
) | ||
} | ||
|
||
<CustomFieldsFilters | ||
activeFilters={activeFilters} | ||
|
@@ -172,4 +215,4 @@ class Filters extends React.Component { | |
} | ||
} | ||
|
||
export default injectIntl(Filters); | ||
export default stripesConnect(injectIntl(Filters)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under what circumstances should it return false? This makes it sound like the function should always return false. Describe the situation you are actually testing. In this case, sth like "returns false (default) when given no data".