-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UITEN-278 - create reading room from tenant settings
- Loading branch information
1 parent
d0f9fa0
commit 54fca50
Showing
4 changed files
with
277 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import React from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import { Field } from 'redux-form'; | ||
import _ from 'lodash'; | ||
|
||
import { TitleManager, useStripes } from '@folio/stripes/core'; | ||
import { | ||
Checkbox, | ||
Label, | ||
MultiSelection, | ||
} from '@folio/stripes/components'; | ||
import { ControlledVocab } from '@folio/stripes/smart-components'; | ||
|
||
const hiddenFields = ['numberOfObjects', 'lastUpdated']; | ||
const visibleFields = ['name', 'isPublic', 'servicePoints']; | ||
const formatter = { | ||
'isPublic': (record) => <Checkbox checked={record.isPublic} disabled />, | ||
'servicePoints': (record) => { | ||
const asp = record.servicePoints || []; | ||
const items = asp.map(a => <li key={a.label}>{a.label}</li>); | ||
return <ul className="marginBottom0">{items}</ul>; | ||
} | ||
}; | ||
const translations = { | ||
cannotDeleteTermHeader: 'ui-tenant-settings.settings.addresses.cannotDeleteTermHeader', | ||
cannotDeleteTermMessage: 'ui-tenant-settings.settings.addresses.cannotDeleteTermMessage', | ||
deleteEntry: 'ui-tenant-settings.settings.reading-room-access.deleteEntry', | ||
termDeleted: 'ui-tenant-settings.settings.reading-room-access.termDeleted', | ||
termWillBeDeleted: 'ui-tenant-settings.settings.reading-room-access.termWillBeDeleted', | ||
}; | ||
|
||
const ReadingRoomAccess = (props) => { | ||
const intl = useIntl(); | ||
const stripes = useStripes(); | ||
const { resources } = props; | ||
// service points defined in the tenant | ||
const servicePoints = _.get(resources, ['RRAServicePoints', 'records', 0, 'servicepoints'], []); | ||
/** | ||
* A reading room can have more than one service points assigned to it. | ||
* but a servicepoint cannot be mapped to more than one reading room | ||
*/ | ||
const sps = []; | ||
const rrs = _.get(resources, ['values', 'records']); | ||
rrs.forEach(rr => { | ||
const asp = rr.servicePoints || []; | ||
asp.forEach(s => { | ||
if (!sps.includes(s.value)) { | ||
sps.push(s.value); | ||
} | ||
}); | ||
}); | ||
|
||
const options = []; | ||
servicePoints.forEach(s => { | ||
if (!sps.includes(s.id) || s.name === 'None') { | ||
options.push({ value: s.id, label: s.name }); | ||
} | ||
}); | ||
|
||
const columnMapping = { | ||
name: ( | ||
<Label tagName="span" required> | ||
{ | ||
intl.formatMessage({ id:'ui-tenant-settings.settings.reading-room-access.name' }) | ||
} | ||
</Label>), | ||
isPublic: intl.formatMessage({ id:'ui-tenant-settings.settings.reading-room-access.public' }), | ||
servicePoints: ( | ||
<Label tagName="span" required> | ||
{ | ||
intl.formatMessage({ id:'ui-tenant-settings.settings.reading-room-access.asp' }) | ||
} | ||
</Label>), | ||
}; | ||
|
||
const fieldComponents = { | ||
isPublic: ({ fieldProps }) => ( | ||
<Field | ||
{...fieldProps} | ||
component={Checkbox} | ||
type="checkbox" | ||
/> | ||
), | ||
servicePoints: ({ fieldProps }) => { | ||
return ( | ||
<Field | ||
{...fieldProps} | ||
id="rra-service-point" | ||
component={MultiSelection} | ||
aria-labelledby="associated-service-point-label" | ||
dataOptions={options} | ||
renderToOverlay | ||
marginBottom0 | ||
validationEnabled | ||
onBlur={e => e.preventDefault()} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
const editable = true; // stripes.hasPerm('ui-users.settings.reading-room-access.all'); | ||
|
||
return ( | ||
<TitleManager page={intl.formatMessage({ id: 'ui-tenant-settings.settings.reading-room.title' })}> | ||
<ControlledVocab | ||
{...props} | ||
id="reading-room-access-settings" | ||
baseUrl="reading-room" | ||
stripes={stripes} | ||
label={intl.formatMessage({ id: 'ui-tenant-settings.settings.reading-room-access.label' })} | ||
objectLabel={intl.formatMessage({ id: 'ui-tenant-settings.settings.reading-room-access.label' })} | ||
records="readingRooms" | ||
visibleFields={visibleFields} | ||
columnMapping={columnMapping} | ||
hiddenFields={hiddenFields} | ||
formatter={formatter} | ||
translations={translations} | ||
editable={editable} | ||
fieldComponents={fieldComponents} | ||
actionSuppressor={{ | ||
edit: () => true, | ||
delete: () => true, | ||
}} | ||
/> | ||
</TitleManager> | ||
); | ||
}; | ||
|
||
ReadingRoomAccess.manifest = Object.freeze({ | ||
values: { | ||
type: 'okapi', | ||
records: 'readingRooms', | ||
path: 'reading-room', | ||
GET: { | ||
path: 'reading-room?query=cql.allRecords=1 sortby name&limit=100' | ||
} | ||
}, | ||
updaterIds: [], | ||
RRAServicePoints: { | ||
type: 'okapi', | ||
resource: 'service-points', | ||
path: 'service-points?limit=200', | ||
}, | ||
}); | ||
|
||
export default ReadingRoomAccess; |
122 changes: 122 additions & 0 deletions
122
src/settings/ReadingRoomAccess/ReadingRoomAccess.test.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,122 @@ | ||
import { screen } from '@testing-library/react'; | ||
|
||
import '../../../test/jest/__mocks__'; | ||
import buildStripes from '../../../test/jest/__new_mocks__/stripesCore.mock'; | ||
|
||
import { | ||
renderWithRouter, | ||
renderWithReduxForm, | ||
} from '../../../test/jest/helpers'; | ||
|
||
import ReadingRoomAccess from './ReadingRoomAccess'; | ||
|
||
const STRIPES = buildStripes(); | ||
|
||
const mutatorMock = { | ||
values: { | ||
// PUT: jest.fn(() => Promise.resolve()), | ||
// DELETE: jest.fn(() => Promise.resolve()), | ||
GET: jest.fn(() => Promise.resolve()), | ||
POST: jest.fn(() => Promise.resolve()), | ||
}, | ||
}; | ||
|
||
const resourcesMock = { | ||
values: { | ||
dataKey: 'reading-room', | ||
failed: false, | ||
hasLoaded: true, | ||
httpStatus: 200, | ||
isPending: false, | ||
module: '@folio/tenant-settings', | ||
records: [ | ||
{ | ||
'id': '04efd73f-f7e3-4c19-8614-861941dd1d8e', | ||
'name': 'readingroom-422', | ||
'isPublic': true, | ||
'servicePoints': [ | ||
{ | ||
'value': '7c5abc9f-f3d7-4856-b8d7-6712462ca007', | ||
'label': 'Online' | ||
} | ||
], | ||
'metadata': { | ||
'createdDate': '2024-04-22T11:41:52.904334', | ||
'createdByUserId': '2db30b15-7a36-4f02-9c77-999dbb470874' | ||
} | ||
}, | ||
{ | ||
'id': '75e44262-f68c-418c-ab4c-88c9198669c1', | ||
'name': 'reading-room-4221', | ||
'isPublic': true, | ||
'servicePoints': [ | ||
{ | ||
'value': '3a40852d-49fd-4df2-a1f9-6e2641a6e91f', | ||
'label': 'Circ Desk 1' | ||
} | ||
], | ||
'metadata': { | ||
'createdDate': '2024-04-22T11:48:50.255863', | ||
'createdByUserId': '2db30b15-7a36-4f02-9c77-999dbb470874' | ||
} | ||
}, | ||
{ | ||
'id': '7c5abc9f-f3d7-4856-b8d7-6712462ca009', | ||
'name': 'reading-room-555', | ||
'isPublic': false, | ||
'servicePoints': [ | ||
{ | ||
'value': 'c4c90014-c8c9-4ade-8f24-b5e313319f4b', | ||
'label': 'Circ Desk 4' | ||
} | ||
], | ||
'metadata': { | ||
'createdDate': '2024-04-19T11:56:15.192057', | ||
'createdByUserId': '2db30b15-7a36-4f02-9c77-999dbb470874', | ||
'updatedDate': '2024-04-22T04:38:00.75285', | ||
'updatedByUserId': '2db30b15-7a36-4f02-9c77-999dbb470874' | ||
} | ||
} | ||
], | ||
}, | ||
}; | ||
|
||
const renderReadingRoomAccess = (props) => { | ||
const component = () => ( | ||
<ReadingRoomAccess {...props} /> | ||
); | ||
|
||
return renderWithRouter(renderWithReduxForm(component)); | ||
}; | ||
|
||
describe('Reading Room Access', () => { | ||
describe('when records exist', () => { | ||
const props = { | ||
mutator: mutatorMock, | ||
resources: resourcesMock, | ||
stripes:{ STRIPES } | ||
}; | ||
|
||
beforeEach(() => { | ||
renderReadingRoomAccess(props); | ||
}); | ||
|
||
it('should render a Pane with title "Reading room access"', () => { | ||
expect(screen.getByLabelText('ui-tenant-settings.settings.reading-room-access.label')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render new button', () => { | ||
expect(screen.getByRole('button', { name: 'stripes-core.button.new' })).toBeVisible(); | ||
}); | ||
|
||
it('should render correct result column', () => { | ||
const columnHeaders = [ | ||
/settings.reading-room-access.name/, | ||
/settings.reading-room-access.public/, | ||
/settings.reading-room-access.asp/ | ||
]; | ||
|
||
columnHeaders.forEach((el) => expect(screen.getByRole('columnheader', { name: el })).toBeVisible()); | ||
}); | ||
}); | ||
}); |