-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UICIRC-1118: Implement feature toggle for ECS and not ECS envs
- Loading branch information
1 parent
1cab325
commit ec90f98
Showing
15 changed files
with
883 additions
and
20 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
58 changes: 58 additions & 0 deletions
58
src/deprecated/settings/TitleLevelRequests/TitleLevelRequests.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,58 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { injectIntl } from 'react-intl'; | ||
|
||
import { ConfigManager } from '@folio/stripes/smart-components'; | ||
import { | ||
withStripes, | ||
TitleManager, | ||
} from '@folio/stripes/core'; | ||
|
||
import TitleLevelRequestsForm from './TitleLevelRequestsForm'; | ||
import { | ||
getInitialValues, | ||
normalizeData, | ||
} from './utils'; | ||
import { | ||
MODULE_NAMES, | ||
} from '../../../constants'; | ||
|
||
export const CONFIG_NAMES = { | ||
TLR: 'TLR', | ||
PRINT_HOLD_REQUESTS: 'PRINT_HOLD_REQUESTS', | ||
}; | ||
|
||
const TitleLevelRequests = ({ | ||
stripes, | ||
intl: { | ||
formatMessage, | ||
}, | ||
}) => { | ||
const ConnectedConfigManager = stripes.connect(ConfigManager); | ||
|
||
return ( | ||
<TitleManager | ||
page={formatMessage({ id: 'ui-circulation.settings.title.general' })} | ||
record={formatMessage({ id: 'ui-circulation.settings.title.titleLevelRequests' })} | ||
> | ||
<ConnectedConfigManager | ||
label={formatMessage({ id: 'ui-circulation.settings.titleLevelRequests.paneTitle' })} | ||
moduleName={MODULE_NAMES.SETTINGS} | ||
configName={CONFIG_NAMES.TLR} | ||
configFormComponent={TitleLevelRequestsForm} | ||
stripes={stripes} | ||
getInitialValues={getInitialValues} | ||
onBeforeSave={normalizeData} | ||
/> | ||
</TitleManager> | ||
); | ||
}; | ||
|
||
TitleLevelRequests.propTypes = { | ||
stripes: PropTypes.shape({ | ||
connect: PropTypes.func.isRequired, | ||
}).isRequired, | ||
intl: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStripes(injectIntl(TitleLevelRequests)); |
68 changes: 68 additions & 0 deletions
68
src/deprecated/settings/TitleLevelRequests/TitleLevelRequests.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,68 @@ | ||
import { | ||
render, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import { ConfigManager } from '@folio/stripes/smart-components'; | ||
import { TitleManager } from '@folio/stripes/core'; | ||
|
||
import TitleLevelRequests, { | ||
CONFIG_NAMES, | ||
} from './TitleLevelRequests'; | ||
import TitleLevelRequestsForm from './TitleLevelRequestsForm'; | ||
import { | ||
getInitialValues, | ||
normalizeData, | ||
} from './utils'; | ||
import { | ||
MODULE_NAMES, | ||
} from '../../../constants'; | ||
|
||
describe('deprecated TitleLevelRequests', () => { | ||
const paneTitleLabelId = 'ui-circulation.settings.titleLevelRequests.paneTitle'; | ||
const mockedStripes = { | ||
connect: jest.fn((component) => component), | ||
}; | ||
const labelIds = { | ||
generalTitle: 'ui-circulation.settings.title.general', | ||
titleLevelRequestsTitle: 'ui-circulation.settings.title.titleLevelRequests', | ||
}; | ||
|
||
beforeEach(() => { | ||
render( | ||
<TitleLevelRequests | ||
stripes={mockedStripes} | ||
/> | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
ConfigManager.mockClear(); | ||
mockedStripes.connect.mockClear(); | ||
}); | ||
|
||
it('should connect "ConfigManager" to stripes', () => { | ||
expect(mockedStripes.connect).toHaveBeenLastCalledWith(ConfigManager); | ||
}); | ||
|
||
it('should execute "ConfigManager" with passed props', () => { | ||
const expectedResult = { | ||
label: paneTitleLabelId, | ||
moduleName: MODULE_NAMES.SETTINGS, | ||
configName: CONFIG_NAMES.TLR, | ||
configFormComponent: TitleLevelRequestsForm, | ||
stripes: mockedStripes, | ||
getInitialValues, | ||
onBeforeSave: normalizeData, | ||
}; | ||
|
||
expect(ConfigManager).toHaveBeenLastCalledWith(expectedResult, {}); | ||
}); | ||
|
||
it('should trigger TitleManager with correct props', () => { | ||
const expectedProps = { | ||
page: labelIds.generalTitle, | ||
record: labelIds.titleLevelRequestsTitle, | ||
}; | ||
|
||
expect(TitleManager).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
src/deprecated/settings/TitleLevelRequests/TitleLevelRequestsForm.css
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,7 @@ | ||
.titleLevelRequestsForm { | ||
height: 100%; | ||
} | ||
|
||
.tlrSettings { | ||
margin: 1.5em 0 2em; | ||
} |
212 changes: 212 additions & 0 deletions
212
src/deprecated/settings/TitleLevelRequests/TitleLevelRequestsForm.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,212 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { injectIntl } from 'react-intl'; | ||
|
||
import { Field } from 'react-final-form'; | ||
|
||
import stripesFinalForm from '@folio/stripes/final-form'; | ||
import { stripesConnect } from '@folio/stripes/core'; | ||
import { | ||
Button, | ||
Checkbox, | ||
Col, | ||
Pane, | ||
Row, | ||
PaneFooter, | ||
Modal, | ||
} from '@folio/stripes/components'; | ||
|
||
import NoticeTemplates from '../../../settings/TLRPatronNotices/NoticeTemplates'; | ||
import { | ||
patronNoticeCategoryIds, | ||
MAX_UNPAGED_RESOURCE_COUNT, | ||
TITLE_LEVEL_REQUESTS, | ||
OPEN_REQUESTS_STATUSES, | ||
REQUEST_LEVEL, | ||
} from '../../../constants'; | ||
|
||
import css from './TitleLevelRequestsForm.css'; | ||
|
||
const statusesQueryPart = OPEN_REQUESTS_STATUSES.map(status => `status=="${status}"`).join(' OR '); | ||
|
||
const TitleLevelRequestsForm = (props) => { // NOSONAR | ||
const { | ||
handleSubmit, | ||
intl: { formatMessage }, | ||
label, | ||
pristine, | ||
submitting, | ||
form, | ||
resources, | ||
mutator, | ||
} = props; | ||
|
||
const [isErrorModalOpen, setIsErrorModalOpen] = useState(false); | ||
const templates = resources.templates?.records || []; | ||
const { values: titleLevelRequestsValues } = form.getState(); | ||
|
||
const renderFooter = () => ( | ||
<PaneFooter | ||
renderEnd={( | ||
<Button | ||
type="submit" | ||
buttonStyle="primary paneHeaderNewButton" | ||
disabled={pristine || submitting} | ||
marginBottom0 | ||
> | ||
{formatMessage({ id: 'stripes-core.button.save' })} | ||
</Button> | ||
)} | ||
/> | ||
); | ||
|
||
const handleTlrCheckboxClick = async () => { | ||
if (!titleLevelRequestsValues[TITLE_LEVEL_REQUESTS.TLR_ENABLED]) { | ||
form.change(TITLE_LEVEL_REQUESTS.TLR_ENABLED, true); | ||
|
||
return; | ||
} | ||
|
||
const activeTitleRequests = await mutator.requests.GET(); | ||
|
||
if (activeTitleRequests.length) { | ||
setIsErrorModalOpen(true); | ||
|
||
return; | ||
} | ||
|
||
form.change(TITLE_LEVEL_REQUESTS.TLR_ENABLED, false); | ||
}; | ||
|
||
const handleModalClose = () => setIsErrorModalOpen(false); | ||
|
||
const modalFooter = ( | ||
<Button | ||
onClick={handleModalClose} | ||
buttonStyle="primary" | ||
> | ||
{formatMessage({ id: 'stripes-core.button.close' })} | ||
</Button> | ||
); | ||
|
||
return ( | ||
<form | ||
data-testid="tlrForm" | ||
id="title-level-requests-form" | ||
className={css.titleLevelRequestsForm} | ||
noValidate | ||
onSubmit={handleSubmit} | ||
> | ||
<Pane | ||
id="title-level-requests-pane" | ||
data-testid="tlrPane" | ||
defaultWidth="fill" | ||
fluidContentWidth | ||
paneTitle={label} | ||
footer={renderFooter()} | ||
> | ||
<Row> | ||
<Col xs={12}> | ||
<Field | ||
data-testid="tlrSwitchCheckbox" | ||
name={TITLE_LEVEL_REQUESTS.TLR_ENABLED} | ||
type="checkbox" | ||
label={formatMessage({ id: 'ui-circulation.settings.titleLevelRequests.allow' })} | ||
component={Checkbox} | ||
onChange={handleTlrCheckboxClick} | ||
/> | ||
</Col> | ||
</Row> | ||
{ | ||
titleLevelRequestsValues[TITLE_LEVEL_REQUESTS.TLR_ENABLED] && | ||
<> | ||
<div className={css.tlrSettings}> | ||
<Field | ||
name={TITLE_LEVEL_REQUESTS.CREATE_TLR_BY_DEFAULT} | ||
type="checkbox" | ||
label={formatMessage({ id: 'ui-circulation.settings.titleLevelRequests.createTLR' })} | ||
component={Checkbox} | ||
/> | ||
<Field | ||
name={TITLE_LEVEL_REQUESTS.TLR_HOLD_SHOULD_FOLLOW_CIRCULATION_RULES} | ||
type="checkbox" | ||
label={formatMessage({ id: 'ui-circulation.settings.titleLevelRequests.tlrHoldShouldFollowCirculationRules' })} | ||
component={Checkbox} | ||
/> | ||
</div> | ||
<div className={css.tlrNoticeSection}> | ||
<NoticeTemplates | ||
templates={templates} | ||
/> | ||
</div> | ||
</> | ||
} | ||
<Modal | ||
data-testid="forbiddenDisableTlrModal" | ||
label={formatMessage({ id: 'ui-circulation.settings.titleLevelRequests.forbiddenDisableTlrModal.title' })} | ||
open={isErrorModalOpen} | ||
onClose={handleModalClose} | ||
dismissible | ||
footer={modalFooter} | ||
> | ||
{formatMessage({ id: 'ui-circulation.settings.titleLevelRequests.forbiddenDisableTlrModal.description' })} | ||
</Modal> | ||
</Pane> | ||
</form> | ||
); | ||
}; | ||
|
||
TitleLevelRequestsForm.manifest = Object.freeze({ | ||
templates: { | ||
type: 'okapi', | ||
path: 'templates', | ||
records: 'templates', | ||
params: { | ||
query: `cql.allRecords=1 AND category="${patronNoticeCategoryIds.REQUEST}" AND active="true"`, | ||
}, | ||
perRequest: MAX_UNPAGED_RESOURCE_COUNT, | ||
}, | ||
requests: { | ||
type: 'okapi', | ||
path: 'circulation/requests', | ||
records: 'requests', | ||
accumulate: true, | ||
fetch: false, | ||
params: { | ||
query: `${statusesQueryPart} AND requestLevel=="${REQUEST_LEVEL.TITLE}"`, | ||
limit: '1', | ||
}, | ||
}, | ||
}); | ||
|
||
TitleLevelRequestsForm.propTypes = { | ||
handleSubmit: PropTypes.func.isRequired, | ||
intl: PropTypes.object.isRequired, | ||
label: PropTypes.string.isRequired, | ||
pristine: PropTypes.bool.isRequired, | ||
submitting: PropTypes.bool.isRequired, | ||
form: PropTypes.object.isRequired, | ||
resources: PropTypes.shape({ | ||
templates: PropTypes.shape({ | ||
records: PropTypes.arrayOf(PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
})), | ||
}), | ||
requests: PropTypes.shape({ | ||
records: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
}).isRequired, | ||
}).isRequired, | ||
mutator: PropTypes.shape({ | ||
requests: PropTypes.shape({ | ||
GET: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
const withStripes = stripesConnect(TitleLevelRequestsForm); | ||
|
||
export default injectIntl(stripesFinalForm({ | ||
navigationCheck: true, | ||
subscription: { values: true }, | ||
})(withStripes)); |
Oops, something went wrong.