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

UIORGS-336: Creating or changing a vendor code using number generator in Organizations App #536

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
556ce31
feat: Number Generator
EthanFreestone Sep 15, 2022
7a04e05
chore: Interfaces
EthanFreestone Sep 16, 2022
515dfb7
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Feb 3, 2023
b3d112e
chore: Tweaks
EthanFreestone Feb 3, 2023
2bdaba9
fix: Generator code
EthanFreestone Feb 16, 2023
0017207
feat: Permission
EthanFreestone Feb 16, 2023
6a1e4dc
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Feb 22, 2023
03fe682
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Jun 20, 2023
f9a299d
build: OptionalOkapiInterfaces
EthanFreestone Jun 20, 2023
ec4f60a
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Aug 7, 2023
ce20f23
build: New service interaction
EthanFreestone Aug 7, 2023
b4c1a43
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Aug 21, 2023
3305486
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Sep 8, 2023
5366269
feat: Number generator
EthanFreestone Sep 8, 2023
dab366d
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Sep 13, 2023
fbaabdf
chore: Button UX
EthanFreestone Sep 29, 2023
d79dcd9
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Sep 29, 2023
5b3bde5
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Oct 23, 2023
be51dbf
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Dec 8, 2023
588afcf
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Dec 8, 2023
68419c4
Merge branch 'feat/number_generator' of github.com:folio-org/ui-organ…
EthanFreestone Dec 8, 2023
d618b90
chore: Revert to state on master
EthanFreestone Dec 8, 2023
28d2d16
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
EthanFreestone Mar 1, 2024
5724de3
test: mock useSettings
EthanFreestone Mar 1, 2024
e0f9cff
test: Updated jest snapshot
EthanFreestone Mar 1, 2024
2fdb4e7
test: Test fails on CI because of non mocked component -- easy fix
EthanFreestone Mar 1, 2024
79e4c34
build: Change service interaction dependency to ^3.0.0
EthanFreestone Mar 28, 2024
5e4e4c2
refactor: Refactor tweaks
EthanFreestone Apr 12, 2024
bae809d
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
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@
"organizations-storage.banking-account-types.item.put",
"organizations-storage.banking-account-types.item.delete"
]
},
{
"permissionName": "ui-organizations.settings.numberGenerator.manage",
"displayName": "Settings (Organizations): Manage number generator options",
"subPermissions": [
"settings.organizations.enabled"
],
"visible": true
}
]
},
Expand Down Expand Up @@ -323,6 +331,7 @@
"@bigtest/react": "^0.1.2",
"@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 @@ -362,6 +371,7 @@
"redux-form": "^8.3.0"
},
"peerDependencies": {
"@folio/service-interaction": "^3.0.0",
"@folio/stripes": "^9.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -374,5 +384,8 @@
"optionalDependencies": {
"@folio/plugin-find-contact": "^5.0.0",
"@folio/plugin-find-interface": "^5.0.0"
},
"optionalOkapiInterfaces": {
"servint": "2.0 3.0"
}
}
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 => {
Expand All @@ -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';
Copy link
Contributor

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

}

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' ||
Copy link
Contributor

Choose a reason for hiding this comment

The 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)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to not create functions and objects in return section

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing trailing comma

Check failure on line 58 in src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing trailing comma
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix plinter please

}}
/>
</Col>
}
</Row>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing trailing comma

Check failure on line 26 in src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing trailing comma
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix linter please

}));

const TestForm = stripesFinalForm({})(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,50 @@ exports[`OrganizationSummaryForm should render correct structure 1`] = `
class="col-xs-6 col-md-3"
>
<div
class="textField"
class="row"
>
<label
class="label"
for="text-input-1"
>
ui-organizations.summary.code
<span
aria-hidden="true"
class="asterisk"
>
*
</span>
</label>
<div
class="formControl inputGroup"
class="col-xs-12"
>
<input
aria-invalid="false"
aria-required="true"
autocapitalize="off"
autocomplete="off"
autocorrect="off"
error=""
id="text-input-1"
name="code"
required=""
spellcheck="false"
type="text"
value="AMAZ"
warning=""
/>
<div
class="textField"
>
<label
class="label"
for="text-input-1"
>
ui-organizations.summary.code
<span
aria-hidden="true"
class="asterisk"
>
*
</span>
</label>
<div
class="formControl inputGroup"
>
<input
aria-invalid="false"
aria-required="true"
autocapitalize="off"
autocomplete="off"
autocorrect="off"
error=""
id="text-input-1"
name="code"
required=""
spellcheck="false"
type="text"
value="AMAZ"
warning=""
/>
</div>
<div
role="alert"
/>
</div>
</div>
<div
role="alert"
/>
</div>
</div>
<div
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);
}
95 changes: 95 additions & 0 deletions src/Settings/NumberGeneratorOptions.js
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);
22 changes: 21 additions & 1 deletion src/Settings/SettingsPage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useMemo } from 'react';
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';

import { Settings } from '@folio/stripes/smart-components';

import { useBankingInformationSettings } from '../common/hooks';
import { CategorySettings } from './CategorySettings';
import { TypeSettings } from './TypeSettings';
import NumberGeneratorOptions from './NumberGeneratorOptions';
import { BankingAccountTypeSettings } from './BankingAccountTypeSettings';
import { BankingInformationSettings } from './BankingInformationSettings';

Expand All @@ -22,6 +24,13 @@ const pages = [
perm: 'settings.organizations.enabled',
route: 'type',
},
{
component: NumberGeneratorOptions,
label: <FormattedMessage id="ui-organizations.settings.numberGeneratorOptions" />,
perm: 'ui-organizations.settings.numberGenerator.manage',
interface: 'servint',
route: 'numberGeneratorOptions',
},
{
component: BankingInformationSettings,
label: <FormattedMessage id="ui-organizations.settings.bankingInformation" />,
Expand Down Expand Up @@ -52,4 +61,15 @@ const SettingsPage = (props) => {
);
};

SettingsPage.propTypes = {
stripes: PropTypes.shape({
hasInterface: PropTypes.func.isRequired,
timezone: PropTypes.string.isRequired,
store: PropTypes.shape({
dispatch: PropTypes.func.isRequired,
getState: PropTypes.func,
}),
}).isRequired,
};

export default SettingsPage;
2 changes: 2 additions & 0 deletions src/common/constants/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
1 change: 1 addition & 0 deletions src/common/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './useLinkedAgreements';
export * from './useOrganizationBankingInformation';
export * from './useTranslatedCategories';
export * from './useTypes';
export * from './useSettings';
1 change: 1 addition & 0 deletions src/common/hooks/useSettings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useSettings } from './useSettings';
Loading
Loading