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 10 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
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@
"ui-inventory.instance.view"
],
"visible": true
},
{
"permissionName": "ui-users.settings.numberGenerator.manage",
"displayName": "Settings (Users): Manage number generator options",
"subPermissions": [
"settings.users.enabled"
],
"visible": true
}
]
},
Expand Down Expand Up @@ -905,7 +913,8 @@
"react-router-dom": "^5.2.0",
"redux": "^4.0.0",
"regenerator-runtime": "^0.13.9",
"sinon": "^7.1.1"
"sinon": "^7.1.1",
"@folio/service-interaction": "^1.0.0"
},
"dependencies": {
"final-form-set-field-data": "^1.0.2",
Expand All @@ -928,7 +937,8 @@
"react": "^17.0.2",
"react-intl": "^5.8.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0"
"react-router-dom": "^5.2.0",
"@folio/service-interaction": "^1.0.0"
},
"optionalDependencies": {
"@folio/plugin-find-user": "^6.0.0"
Expand Down
41 changes: 33 additions & 8 deletions src/components/EditSections/EditUserInfo/EditUserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import moment from 'moment-timezone';
import { OnChange } from 'react-final-form-listeners';

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

import {
Button,
Select,
Expand All @@ -32,6 +34,7 @@ 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({
timezone: PropTypes.string.isRequired,
store: PropTypes.shape({
Expand Down Expand Up @@ -111,8 +114,14 @@ class EditUserInfo extends React.Component {
accordionId,
intl,
uniquenessValidator,
form: { change },
settings
} = this.props;


const numberGeneratorSettings = JSON.parse((settings?.find(sett => sett.configName === 'number_generator') ?? { value: '{}' }).value);
const barcodeGeneratorSetting = numberGeneratorSettings?.barcodeGeneratorSetting;

const { barcode } = initialValues;

const isUserExpired = () => {
Expand Down Expand Up @@ -305,14 +314,30 @@ class EditUserInfo extends React.Component {
)}
</Col>
<Col xs={12} md={3}>
<Field
label={<FormattedMessage id="ui-users.information.barcode" />}
name="barcode"
id="adduser_barcode"
component={TextField}
validate={asyncValidateField('barcode', barcode, uniquenessValidator)}
fullWidth
/>
<Row>
<Col xs={12}>
<Field
disabled={barcodeGeneratorSetting === 'useGenerator'}
label={<FormattedMessage id="ui-users.information.barcode" />}
name="barcode"
id="adduser_barcode"
component={TextField}
validate={asyncValidateField('barcode', barcode, uniquenessValidator)}
fullWidth
/>
</Col>
{(
barcodeGeneratorSetting === 'useGenerator' ||
barcodeGeneratorSetting === 'useBoth'
) &&
<Col xs={12}>
<NumberGeneratorModalButton
callback={(generated) => change('barcode', generated)}
generator="Patron"
/>
</Col>
}
</Row>
</Col>
</Row>
</Accordion>
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 @@ -8,6 +8,10 @@ import '__mock__/stripesComponents.mock';
import renderWithRouter from 'helpers/renderWithRouter';
import EditUserInfo from './EditUserInfo';

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

const onSubmit = jest.fn();

const arrayMutators = {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/UserRecordContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class UserRecordContainer extends React.Component {
settings: {
type: 'okapi',
records: 'configs',
path: 'configurations/entries?query=(module==USERS and configName==profile_pictures)',
path: 'configurations/entries?query=(module==USERS and (configName==profile_pictures or configName==number_generator))',
},
requestPreferences: {
type: 'okapi',
Expand Down
85 changes: 85 additions & 0 deletions src/settings/NumberGeneratorOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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, RadioButton, Row } from '@folio/stripes/components';

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) { } // eslint-disable-line no-empty
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}>
<Field
component={RadioButton}
id="useGenerator"
name="barcodeGeneratorSetting"
label={<FormattedMessage id="ui-users.settings.numberGeneratorOptions.useGeneratorForBarcode" />}
type="radio"
value="useGenerator"
/>
<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"
/>
</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 '@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();
});
});
7 changes: 7 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,12 @@ const settingsGeneral = [
component: DepartmentsSettings,
perm: 'ui-users.settings.departments.view'
},
{
route: 'numbergeneratoroptions',
label: <FormattedMessage id="ui-users.settings.numberGeneratorOptions" />,
component: NumberGeneratorOptions,
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 @@ -117,6 +117,7 @@ class UserEdit extends React.Component {
'addressTypes',
'servicePoints',
'departments',
'settings'
);

return formData;
Expand Down
1 change: 1 addition & 0 deletions src/views/UserEdit/UserForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class UserForm extends React.Component {
accordionId="editUserInfo"
initialValues={initialValues}
patronGroups={formData.patronGroups}
settings={formData.settings}
stripes={stripes}
form={form}
selectedPatronGroup={selectedPatronGroup}
Expand Down
1 change: 1 addition & 0 deletions test/jest/__mock__/stripesSmartComponent.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jest.mock('@folio/stripes/smart-components', () => {
...jest.requireActual('@folio/stripes/smart-components'),
AddressEditList: () => <div data-testid="address-edit-list">AddressEditList</div>,
ChangeDueDateDialog: (props) => <div data-testid="change-duedate-dialog">ChangeDueDateDialog</div>,
ConfigManager: () => <div data-testid="config-manager">ConfigManager</div>,
ControlledVocab: ({ validate }) => <div data-testid="controlled-vocab">ControlledVocab</div>,
DueDatePicker: () => <div data-testid="due-date-picker">DueDatePicker</div>,
LocationLookup: () => <div>LocationLookup</div>,
Expand Down
4 changes: 4 additions & 0 deletions translations/ui-users/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"settings.departments.users": "Users",
"settings.manualBlockTemplates": "Templates",
"settings.manualBlockTemplates.paneTitle": "Patron block templates",
"settings.numberGeneratorOptions": "Number generator options",
"settings.numberGeneratorOptions.useGeneratorForBarcode": "Use number generator for user barcode.",
"settings.numberGeneratorOptions.useTextFieldForBarcode": "Use text field for user barcode.",
"settings.numberGeneratorOptions.useBothForBarcode": "Use number generator for user barcode but allow editing via text field.",
"manualBlockTemplates.templateInformation": "Template information",
"manualBlockTemplates.templateName": "Template name",
"manualBlockTemplates.blockCode": "Block code",
Expand Down