-
Notifications
You must be signed in to change notification settings - Fork 3
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
UIORGS-336: Creating or changing a vendor code using number generator in Organizations App #536
base: master
Are you sure you want to change the base?
Changes from all commits
556ce31
7a04e05
515dfb7
b3d112e
2bdaba9
0017207
6a1e4dc
03fe682
f9a299d
ec4f60a
ce20f23
b4c1a43
3305486
5366269
dab366d
fbaabdf
d79dcd9
5b3bde5
be51dbf
588afcf
68419c4
d618b90
28d2d16
5724de3
e0f9cff
2fdb4e7
79e4c34
5e4e4c2
bae809d
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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import React, { useCallback } from 'react'; | ||
import { Field } from 'react-final-form'; | ||
import { Field, useForm } from 'react-final-form'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { stripesConnect } from '@folio/stripes/core'; | ||
import { TextField } from '@folio/stripes/components'; | ||
import { stripesConnect, useStripes } from '@folio/stripes/core'; | ||
import { Col, Row, TextField } from '@folio/stripes/components'; | ||
import { NumberGeneratorModalButton } from '@folio/service-interaction'; | ||
|
||
import { fetchOrgsByParam } from '../../../../common/resources'; | ||
import { validateOrgCode } from './validateOrgCode'; | ||
import { useSettings } from '../../../../common/hooks'; | ||
|
||
const CONFIG_NAME = 'number_generator'; | ||
|
||
const FieldCode = ({ orgId, mutator }) => { | ||
const validate = useCallback(value => { | ||
|
@@ -16,15 +20,47 @@ | |
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[orgId]); | ||
|
||
const { change } = useForm(); | ||
const stripes = useStripes(); | ||
|
||
const { settings } = useSettings([CONFIG_NAME]); | ||
let vendorCodeSetting = 'useTextField'; | ||
|
||
if (stripes.hasInterface('servint')) { | ||
vendorCodeSetting = settings?.find(sett => sett?.configName === CONFIG_NAME)?.parsedSettings?.vendorGeneratorSetting ?? 'useTextField'; | ||
} | ||
|
||
return ( | ||
<Field | ||
component={TextField} | ||
fullWidth | ||
label={<FormattedMessage id="ui-organizations.summary.code" />} | ||
name="code" | ||
required | ||
validate={validate} | ||
/> | ||
<Row> | ||
<Col xs={12}> | ||
<Field | ||
component={TextField} | ||
disabled={vendorCodeSetting === 'useGenerator'} | ||
fullWidth | ||
label={<FormattedMessage id="ui-organizations.summary.code" />} | ||
name="code" | ||
required | ||
validate={validate} | ||
/> | ||
</Col> | ||
{( | ||
vendorCodeSetting === 'useGenerator' || | ||
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. plz don't use magic words, additionally IMO you can return boolean values from hook (see previous comment) |
||
vendorCodeSetting === 'useBoth' | ||
) && | ||
<Col xs={12}> | ||
<NumberGeneratorModalButton | ||
buttonLabel={<FormattedMessage id="ui-organizations.numberGenerator.generateVendorCode" />} | ||
callback={(generated) => change('code', generated)} | ||
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. it would be nice to not create functions and objects in |
||
id="vendor-code-generator" | ||
generateButtonLabel={<FormattedMessage id="ui-organizations.numberGenerator.generateVendorCode" />} | ||
generator="organizations_vendorCode" | ||
modalProps={{ | ||
label: <FormattedMessage id="ui-organizations.numberGenerator.vendorCodeGenerator" /> | ||
Check failure on line 58 in src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js GitHub Actions / github-actions-ci
|
||
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. fix plinter please |
||
}} | ||
/> | ||
</Col> | ||
} | ||
</Row> | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,19 @@ | |
|
||
jest.mock('../../../common/hooks', () => ({ | ||
useTypes: jest.fn(), | ||
useSettings: jest.fn(() => ([ | ||
{ | ||
id: 'f2b84177-d85a-4b0c-93dd-279e8f9d1d42', | ||
module: 'ORGANIZATIONS', | ||
configName: 'number_generator', | ||
enabled: true, | ||
value: '{"vendorGeneratorSetting":"useBoth"}', | ||
}, | ||
])), | ||
})); | ||
|
||
jest.mock('@folio/service-interaction', () => ({ | ||
NumberGeneratorModalButton: () => <div>NumberGeneratorModalButton</div> | ||
Check failure on line 26 in src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js GitHub Actions / github-actions-ci
|
||
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. fix linter please |
||
})); | ||
|
||
const TestForm = stripesFinalForm({})( | ||
|
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
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'; | ||
|
||
const ConnectedConfigManager = stripesConnect(ConfigManager); | ||
|
||
const NumberGeneratorOptions = (props) => { | ||
const beforeSave = (data) => { | ||
return JSON.stringify(data); | ||
}; | ||
|
||
const 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 { | ||
...loadedValues, | ||
}; | ||
}; | ||
|
||
return ( | ||
<ConnectedConfigManager | ||
configName="number_generator" | ||
getInitialValues={getInitialValues} | ||
formType="final-form" | ||
label={<FormattedMessage id="ui-organizations.settings.numberGeneratorOptions" />} | ||
moduleName="ORGANIZATIONS" | ||
onBeforeSave={beforeSave} | ||
stripes={props.stripes} | ||
> | ||
<Row> | ||
<Col xs={12}> | ||
<div className={css.marginBottomGutter}> | ||
<MessageBanner> | ||
<FormattedMessage id="ui-organizations.settings.numberGeneratorOptions.info" /> | ||
</MessageBanner> | ||
</div> | ||
</Col> | ||
</Row> | ||
<Row> | ||
<Col xs={12}> | ||
<Field | ||
component={RadioButton} | ||
id="useTextField" | ||
name="vendorGeneratorSetting" | ||
label={<FormattedMessage id="ui-organizations.settings.numberGeneratorOptions.useTextFieldForVendor" />} | ||
type="radio" | ||
value="useTextField" | ||
/> | ||
<Field | ||
component={RadioButton} | ||
id="useBoth" | ||
name="vendorGeneratorSetting" | ||
label={<FormattedMessage id="ui-organizations.settings.numberGeneratorOptions.useBothForVendor" />} | ||
type="radio" | ||
value="useBoth" | ||
/> | ||
<Field | ||
component={RadioButton} | ||
id="useGenerator" | ||
name="vendorGeneratorSetting" | ||
label={<FormattedMessage id="ui-organizations.settings.numberGeneratorOptions.useGeneratorForVendor" />} | ||
type="radio" | ||
value="useGenerator" | ||
/> | ||
</Col> | ||
</Row> | ||
</ConnectedConfigManager> | ||
); | ||
}; | ||
|
||
NumberGeneratorOptions.propTypes = { | ||
stripes: PropTypes.object, | ||
}; | ||
|
||
export default withStripes(NumberGeneratorOptions); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ export const PRIVILEGED_CONTACTS_API = 'organizations-storage/privileged-contact | |
export const SETTINGS_API = 'organizations-storage/settings'; | ||
export const TYPES_API = 'organizations-storage/organization-types'; | ||
|
||
export const CONFIG_API = 'configurations/entries'; | ||
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. configurations is deprecated and shouldn't be used for new functionality |
||
|
||
export const MAX_LIMIT = 2147483647; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useSettings } from './useSettings'; |
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.
this and related code should be moved to hook