Skip to content
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-2729/UIU-2730: Number generator usage for user barcode #2231

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
671d1c8
feat: Number Generator Barcode
EthanFreestone Jul 15, 2022
0e33e43
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Jul 28, 2022
edacb4f
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Aug 3, 2022
a4c5dc2
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Sep 8, 2022
a6f8d4e
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Sep 8, 2022
53f376f
feat: NumberGen Settings
EthanFreestone Sep 8, 2022
a6fbf08
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Sep 15, 2022
3d7a406
test: Added test
EthanFreestone Sep 15, 2022
45b527f
test: Test tweak
EthanFreestone Sep 15, 2022
2df4c66
chore: Quick tweak to default
EthanFreestone Sep 15, 2022
65f4bc7
chore: Interface stuff
EthanFreestone Sep 16, 2022
de40082
build: package rejig
EthanFreestone Sep 16, 2022
a99798d
Merge branch 'master' into feat/number_generator
EthanFreestone Nov 11, 2022
61c658a
Merge branch 'master' into feat/number_generator
EthanFreestone Nov 11, 2022
80faad3
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Jan 13, 2023
7a409e5
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Feb 3, 2023
792a410
chore: Tweaks
EthanFreestone Feb 3, 2023
586034e
fix: Generator code
EthanFreestone Feb 16, 2023
80993f8
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Feb 22, 2023
063a7a9
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Jun 20, 2023
24e58e3
build: OptionalOkapiInterfaces
EthanFreestone Jun 20, 2023
4d663f6
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Aug 7, 2023
74ebca3
build: use new service-interaction
EthanFreestone Aug 7, 2023
3ce0f62
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Aug 21, 2023
8a94633
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Sep 8, 2023
ab09c0e
chore: UX Tweaks
EthanFreestone Sep 8, 2023
3afb721
chore: Change test import
EthanFreestone Sep 8, 2023
a8ab57a
test: Fixes
EthanFreestone Sep 8, 2023
ba0470f
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Sep 13, 2023
f5835c7
chore: Button UX
EthanFreestone Sep 29, 2023
aefd058
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Sep 29, 2023
b8a6e03
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Oct 23, 2023
fae6f18
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Nov 1, 2023
611495a
chore: Perm visible
EthanFreestone Nov 2, 2023
2232744
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Dec 8, 2023
63a03f2
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Mar 1, 2024
97a3c2b
chore: Console logs
EthanFreestone Mar 1, 2024
77142f0
fix: Whoopsie
EthanFreestone Mar 1, 2024
ab6bfce
test: Test fix
EthanFreestone Mar 1, 2024
0c7af37
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Mar 5, 2024
c93f908
Merge branch 'master' of github.com:folio-org/ui-users into feat/numb…
EthanFreestone Mar 13, 2024
e492651
build: Change service interaction dependency to ^3.0.0
EthanFreestone Mar 28, 2024
5d46ddc
chore: MessageBanner
EthanFreestone May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"loan-storage": "4.0 5.0 6.0 7.0",
"notes": "2.0 3.0",
"request-storage": "2.5 3.0 4.0 5.0 6.0",
"servint": "2.0 3.0",
"batch-print": "1.0"
},
"permissionSets": [
Expand Down Expand Up @@ -981,6 +982,13 @@
],
"visible": true
},
{
"permissionName": "ui-users.settings.numberGenerator.manage",
"displayName": "Settings (Users): Manage number generator options",
"subPermissions": [
"settings.users.enabled"
]
},
{
"permissionName": "ui-users.profile-pictures.view",
"displayName": "Users: Can view profile pictures",
Expand Down Expand Up @@ -1079,6 +1087,7 @@
"@babel/preset-react": "^7.9.0",
"@folio/eslint-config-stripes": "^7.0.0",
"@folio/jest-config-stripes": "^2.0.0",
"@folio/service-interaction": "^3.0.0",
"@folio/stripes": "^9.0.0",
"@folio/stripes-cli": "^3.0.0",
"@formatjs/cli": "^6.1.3",
Expand Down Expand Up @@ -1118,6 +1127,7 @@
"uuid": "^9.0.0"
},
"peerDependencies": {
"@folio/service-interaction": "^3.0.0",
"@folio/stripes": "^9.0.0",
"moment": "^2.24.0",
"react": "^18.2.0",
Expand Down
37 changes: 33 additions & 4 deletions src/components/EditSections/EditUserInfo/EditUserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Field } from 'react-final-form';
import { OnChange } from 'react-final-form-listeners';
import { FormattedMessage, injectIntl } from 'react-intl';

import { ViewMetaData } from '@folio/stripes/smart-components';
import { NumberGeneratorModalButton } from '@folio/service-interaction';

import {
Button,
Select,
Expand All @@ -18,7 +21,6 @@ import {
Modal,
ModalFooter,
} from '@folio/stripes/components';
import { ViewMetaData } from '@folio/stripes/smart-components';

import { USER_TYPES, USER_TYPE_FIELD } from '../../../constants';
import { isConsortiumEnabled } from '../../util';
Expand All @@ -37,7 +39,9 @@ class EditUserInfo extends React.Component {
intl: PropTypes.object.isRequired,
onToggle: PropTypes.func,
patronGroups: PropTypes.arrayOf(PropTypes.object),
settings: PropTypes.arrayOf(PropTypes.object),
stripes: PropTypes.shape({
hasInterface: PropTypes.func.isRequired,
timezone: PropTypes.string.isRequired,
store: PropTypes.shape({
dispatch: PropTypes.func.isRequired,
Expand Down Expand Up @@ -118,19 +122,27 @@ class EditUserInfo extends React.Component {

render() {
const {
disabled,
patronGroups,
initialValues,
expanded,
onToggle,
accordionId,
intl,
stripes,
uniquenessValidator,
disabled,
form: { change },
settings,
stripes,
profilePictureConfig,
form,
} = this.props;

let barcodeGeneratorSetting = 'useTextField';
if (stripes.hasInterface('servint')) {
const numberGeneratorSettings = JSON.parse((settings?.find(sett => sett.configName === 'number_generator') ?? { value: '{}' }).value);
barcodeGeneratorSetting = numberGeneratorSettings?.barcodeGeneratorSetting ?? 'useTextField';
}

const isConsortium = isConsortiumEnabled(stripes);
const { barcode } = initialValues;

Expand Down Expand Up @@ -374,8 +386,25 @@ class EditUserInfo extends React.Component {
component={TextField}
validate={asyncValidateField('barcode', barcode, uniquenessValidator)}
fullWidth
disabled={disabled}
disabled={disabled || barcodeGeneratorSetting === 'useGenerator'}
/>
{(
barcodeGeneratorSetting === 'useGenerator' ||
barcodeGeneratorSetting === 'useBoth'
) &&
<Col xs={12}>
<NumberGeneratorModalButton
buttonLabel={<FormattedMessage id="ui-users.numberGenerator.generateUserBarcode" />}
callback={(generated) => change('barcode', generated)}
id="userbarcode"
generateButtonLabel={<FormattedMessage id="ui-users.numberGenerator.generateUserBarcode" />}
generator="users_patronBarcode"
modalProps={{
label: <FormattedMessage id="ui-users.numberGenerator.userBarcodeGenerator" />
}}
/>
</Col>
}
</Col>
</Row>
</Col>
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditSections/EditUserInfo/EditUserInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jest.mock('../../util', () => ({
isConsortiumEnabled: jest.fn(() => true),
}));

jest.mock('@folio/service-interaction', () => ({
NumberGeneratorModalButton: () => <div>NumberGeneratorModalButton</div>
}));

jest.mock('./components', () => ({
EditUserProfilePicture : jest.fn(() => 'Profile Picture'),
ChangeUserTypeModal: jest.fn(({ onChange, initialUserType, open }) => {
Expand Down
8 changes: 8 additions & 0 deletions src/routes/UserRecordContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ class UserRecordContainer extends React.Component {
type: 'okapi',
path: 'users/configurations/entry',
},
configSettings: {
type: 'okapi',
records: 'configs',
path: 'configurations/entries?query=(module==USERS and configName==number_generator)',
},
requestPreferences: {
type: 'okapi',
throwErrors: false,
Expand Down Expand Up @@ -215,6 +220,9 @@ class UserRecordContainer extends React.Component {
settings: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
configSettings: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
loansHistory: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
Expand Down
5 changes: 5 additions & 0 deletions src/settings/NumberGeneratorOptions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import '@folio/stripes-components/lib/variables';

.marginBottomGutter {
margin-bottom: var(--gutter);
}
100 changes: 100 additions & 0 deletions src/settings/NumberGeneratorOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Field } from 'react-final-form';

import { stripesConnect, withStripes } from '@folio/stripes/core';
import { ConfigManager } from '@folio/stripes/smart-components';

import { Col, MessageBanner, RadioButton, Row } from '@folio/stripes/components';

import css from './NumberGeneratorOptions.css';

class NumberGeneratorOptions extends React.Component {
static propTypes = {
stripes: PropTypes.object,
};

constructor(props) {
super(props);
this.connectedConfigManager = stripesConnect(ConfigManager);
}

defaultValues = {
barcodeGeneratorSetting: 'useTextField'
};

beforeSave(data) {
return JSON.stringify(data);
}

getInitialValues = (settings) => {
let loadedValues = {};
try {
const value = settings.length === 0 ? '' : settings[0].value;
loadedValues = JSON.parse(value);
} catch (e) {
// Make sure we return _something_ because ConfigManager no longer has a safety check here
return {};
}

return {
...this.defaultValues,
...loadedValues,
};
}

render() {
return (
<this.connectedConfigManager
configName="number_generator"
getInitialValues={this.getInitialValues}
label={<FormattedMessage id="ui-users.settings.numberGeneratorOptions" />}
moduleName="USERS"
onBeforeSave={this.beforeSave}
stripes={this.props.stripes}
formType="final-form"
>
<Row>
<Col xs={12}>
<div className={css.marginBottomGutter}>
<MessageBanner>
<FormattedMessage id="ui-users.settings.numberGeneratorOptions.info" />
</MessageBanner>
</div>
</Col>
</Row>
<Row>
<Col xs={12}>
<Field
component={RadioButton}
id="useTextField"
name="barcodeGeneratorSetting"
label={<FormattedMessage id="ui-users.settings.numberGeneratorOptions.useTextFieldForBarcode" />}
type="radio"
value="useTextField"
/>
<Field
component={RadioButton}
id="useBoth"
name="barcodeGeneratorSetting"
label={<FormattedMessage id="ui-users.settings.numberGeneratorOptions.useBothForBarcode" />}
type="radio"
value="useBoth"
/>
<Field
component={RadioButton}
id="useGenerator"
name="barcodeGeneratorSetting"
label={<FormattedMessage id="ui-users.settings.numberGeneratorOptions.useGeneratorForBarcode" />}
type="radio"
value="useGenerator"
/>
</Col>
</Row>
</this.connectedConfigManager>
);
}
}

export default withStripes(NumberGeneratorOptions);
22 changes: 22 additions & 0 deletions src/settings/NumberGeneratorOptions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

import { screen } from '@folio/jest-config-stripes/testing-library/react';

import '__mock__/stripesCore.mock';
import '__mock__/stripesSmartComponent.mock';
import '__mock__/intl.mock';

import renderWithRouter from 'helpers/renderWithRouter';
import NumberGeneratorOptions from './NumberGeneratorOptions';

jest.unmock('@folio/stripes/components');

const renderNumberGeneratorSettings = (props) => renderWithRouter(<NumberGeneratorOptions {...props} />);

describe('Number generator settings', () => {
it('renders', () => {
renderNumberGeneratorSettings();

expect(screen.getByTestId('config-manager')).toBeTruthy();
});
});
8 changes: 8 additions & 0 deletions src/settings/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import LimitsSettings from './LimitsSettings';
import DepartmentsSettings from './DepartmentsSettings';
import BlockTemplates from './patronBlocks/BlockTemplates';
import TransferCriteriaSettings from './TransferCriteriaSettings';
import NumberGeneratorOptions from './NumberGeneratorOptions';

const settingsGeneral = [
{
Expand All @@ -44,6 +45,13 @@ const settingsGeneral = [
component: DepartmentsSettings,
perm: 'ui-users.settings.departments.view'
},
{
route: 'numbergeneratoroptions',
label: <FormattedMessage id="ui-users.settings.numberGeneratorOptions" />,
component: NumberGeneratorOptions,
interface: 'servint',
perm: 'ui-users.settings.numberGenerator.manage'
},
// Profile pictures are currently unsupported in Folio and the existence of this setting has
// confused implementers. Commenting out for now as opposed to deleting it so the existing
// files and components aren't orphaned.
Expand Down
1 change: 1 addition & 0 deletions src/views/UserEdit/UserEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class UserEdit extends React.Component {
'addressTypes',
'servicePoints',
'departments',
'configSettings'
);

return formData;
Expand Down
Loading
Loading