Skip to content

Commit

Permalink
UITEN-292: Change visibility rules for routing service points
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy-Litvinenko committed Sep 2, 2024
1 parent eea2bf5 commit 8a68ed2
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* [UITEN-278] (https://issues.folio.org/browse/UITEN-278) Reading Room Access (settings): Create new reading room.
* [UITEN-282] (https://issues.folio.org/browse/UITEN-282) Reading Room Access (settings): Update reading room.
* [UITEN-283] (https://issues.folio.org/browse/UITEN-283) Reading Room Access (settings): Delete reading room.
* [UITEN-281](https://folio-org.atlassian.net/browse/UITEN-281) Add Routing service point option to Service point page(ECS only).
* [UITEN-285](https://folio-org.atlassian.net/browse/UITEN-285) Disable edit of Routing service point field (ECS only).
* [UITEN-294](https://folio-org.atlassian.net/browse/UITEN-294) Show routing service points on settings -> tenant -> servicePoints.
* [UITEN-290] (https://issues.folio.org/browse/UITEN-290) Make dependency on mod-reading-rooms optional.
* [UITEN-298] (https://issues.folio.org/browse/UITEN-298) Update translation ids for reading room.
* [UITEN-301] (https://issues.folio.org/browse/UITEN-301) Display Reading room access in alphabetical order on settings page.
Expand All @@ -20,6 +23,7 @@
* [UITEN-281](https://folio-org.atlassian.net/browse/UITEN-281) Add Routing service point option to Service point page(ECS only).
* [UITEN-285](https://folio-org.atlassian.net/browse/UITEN-285) Disable edit of Routing service point field (ECS only).
* [UITEN-294](https://folio-org.atlassian.net/browse/UITEN-294) Show routing service points on settings -> tenant -> servicePoints.
* [UITEN-292](https://folio-org.atlassian.net/browse/UITEN-292) Change visibility rules for routing service points.

## [8.1.0](https://github.com/folio-org/ui-tenant-settings/tree/v8.1.0)(2024-03-19)
[Full Changelog](https://github.com/folio-org/ui-tenant-settings/compare/v8.0.0...v8.1.0)
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"inventory-storage.location-units.libraries.collection.get",
"inventory-storage.service-points.collection.get",
"inventory-storage.service-points.item.get",
"circulation-storage.staff-slips.collection.get"
"circulation-storage.staff-slips.collection.get",
"circulation.settings.collection.get"
],
"visible": false
},
Expand Down Expand Up @@ -284,6 +285,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-intl": "^6.4.4",
"react-query": "^3.6.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.2.0",
"redux": "^4.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as useCirculationSettingsEcsTlrFeature } from './useCirculationSettingsEcsTlrFeature';
1 change: 1 addition & 0 deletions src/hooks/useCirculationSettingsEcsTlrFeature/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './useCirculationSettingsEcsTlrFeature';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useQuery } from 'react-query';

import { useNamespace, useOkapiKy } from '@folio/stripes/core';

import { getEcsTlrFeature } from '../../settings/ServicePoints/utils';

const useCirculationSettingsEcsTlrFeature = (enabled) => {
const ky = useOkapiKy();
const [namespace] = useNamespace({ key: 'circulationSettingsEcsTlrFeature' });
const searchParams = {
query: 'name==ecsTlrFeature',
};
const { isLoading, data, refetch, isFetching } = useQuery(
[namespace],
() => ky.get('circulation/settings', { searchParams }).json(),
{ enabled },
);

return ({
titleLevelRequestsFeatureEnabled: getEcsTlrFeature(data?.circulationSettings),
isLoading,
isFetching,
refetch,
});
};

export default useCirculationSettingsEcsTlrFeature;
12 changes: 6 additions & 6 deletions src/settings/ServicePoints/ServicePointDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class ServicePointDetail extends React.Component {
intl: PropTypes.object,
stripes: PropTypes.shape({
connect: PropTypes.func.isRequired,
hasInterface: PropTypes.func.isRequired,
}).isRequired,
initialValues: PropTypes.object,
parentResources: PropTypes.object,
parentMutator: PropTypes.object
parentMutator: PropTypes.object,
titleLevelRequestsFeatureEnabled: PropTypes.bool,
};

constructor(props) {
Expand Down Expand Up @@ -83,7 +83,7 @@ class ServicePointDetail extends React.Component {
}

render() {
const { initialValues, parentResources, stripes } = this.props;
const { initialValues, parentResources, titleLevelRequestsFeatureEnabled } = this.props;
const locations = (parentResources.locations || {}).records || [];
const staffSlips = orderBy((parentResources.staffSlips || {}).records || [], 'name');
const servicePoint = initialValues;
Expand Down Expand Up @@ -136,7 +136,7 @@ class ServicePointDetail extends React.Component {
/>
</Col>
</Row>
{isEcsRequestRoutingVisible(stripes) && (
{isEcsRequestRoutingVisible(titleLevelRequestsFeatureEnabled) && (
<Row>
<Col xs={8}>
<KeyValue label={<FormattedMessage id="ui-tenant-settings.settings.servicePoints.ecsRequestRouting" />}>
Expand All @@ -148,7 +148,7 @@ class ServicePointDetail extends React.Component {
</Col>
</Row>
)}
{isEcsRequestRoutingAssociatedFieldsVisible(stripes, servicePoint.ecsRequestRouting) && (
{isEcsRequestRoutingAssociatedFieldsVisible(titleLevelRequestsFeatureEnabled, servicePoint.ecsRequestRouting) && (
<>
<Row>
<Col xs={8}>
Expand Down Expand Up @@ -196,7 +196,7 @@ class ServicePointDetail extends React.Component {
)}
</Accordion>

{isEcsRequestRoutingAssociatedFieldsVisible(stripes, servicePoint.ecsRequestRouting) && (
{isEcsRequestRoutingAssociatedFieldsVisible(titleLevelRequestsFeatureEnabled, servicePoint.ecsRequestRouting) && (
<LocationList
locations={locations}
servicePoint={servicePoint}
Expand Down
12 changes: 8 additions & 4 deletions src/settings/ServicePoints/ServicePointForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import {
isEcsRequestRoutingAssociatedFieldsVisible,
} from './utils';

import {
useCirculationSettingsEcsTlrFeature,
} from '../../hooks';

import {
shortTermExpiryPeriod,
shortTermClosedDateManagementMenu,
Expand Down Expand Up @@ -75,6 +79,7 @@ const ServicePointForm = ({
handleSubmit,
onCancel,
}) => {
const { titleLevelRequestsFeatureEnabled } = useCirculationSettingsEcsTlrFeature(true);
const [sections, setSections] = useState({
generalSection: true,
locationSection: true
Expand Down Expand Up @@ -302,7 +307,7 @@ const ServicePointForm = ({
/>
</Col>
</Row>
{isEcsRequestRoutingVisible(stripes) && (
{isEcsRequestRoutingVisible(titleLevelRequestsFeatureEnabled) && (
<Row>
<Col xs={2}>
<Field
Expand All @@ -317,7 +322,7 @@ const ServicePointForm = ({
</Col>
</Row>
)}
{isEcsRequestRoutingAssociatedFieldsVisible(stripes, formValues.ecsRequestRouting) && (
{isEcsRequestRoutingAssociatedFieldsVisible(titleLevelRequestsFeatureEnabled, formValues.ecsRequestRouting) && (
<>
<Row>
<Col xs={4}>
Expand Down Expand Up @@ -376,7 +381,7 @@ const ServicePointForm = ({
</>
)}
</Accordion>
{isEcsRequestRoutingAssociatedFieldsVisible(stripes, formValues.ecsRequestRouting) && (
{isEcsRequestRoutingAssociatedFieldsVisible(titleLevelRequestsFeatureEnabled, formValues.ecsRequestRouting) && (
<LocationList
locations={locations}
servicePoint={servicePoint}
Expand Down Expand Up @@ -407,7 +412,6 @@ ServicePointForm.propTypes = {
}).isRequired,
submitting: PropTypes.bool,
stripes: PropTypes.shape({
hasInterface: PropTypes.func.isRequired,
hasPerm: PropTypes.func.isRequired,
}).isRequired,
form: PropTypes.object.isRequired,
Expand Down
4 changes: 4 additions & 0 deletions src/settings/ServicePoints/ServicePointFormContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
import ServicePointFormContainer from './ServicePointFormContainer';
import { parentMutatorMock, parentResourcesMock } from './test/setup';

jest.mock('../../hooks', () => ({
useCirculationSettingsEcsTlrFeature: jest.fn().mockReturnValue({ titleLevelRequestsFeatureEnabled: true }),
}));

const onSave = jest.fn();
const staffSlips = [true, true, true, true];

Expand Down
12 changes: 12 additions & 0 deletions src/settings/ServicePoints/ServicePointManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TitleManager } from '@folio/stripes/core';
import { injectIntl } from 'react-intl';
import ServicePointDetail from './ServicePointDetail';
import ServicePointFormContainer from './ServicePointFormContainer';
import { getEcsTlrFeature } from './utils';

class ServicePointManager extends React.Component {
static manifest = Object.freeze({
Expand Down Expand Up @@ -49,6 +50,11 @@ class ServicePointManager extends React.Component {
limit: '1000',
},
},
settings: {
type: 'okapi',
path: 'circulation/settings?query=(name==ecsTlrFeature)',
records: 'circulationSettings',
},
});

static propTypes = {
Expand All @@ -57,6 +63,9 @@ class ServicePointManager extends React.Component {
entries: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
settings: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
staffSlips: PropTypes.object,
}).isRequired,
mutator: PropTypes.shape({
Expand Down Expand Up @@ -87,6 +96,8 @@ class ServicePointManager extends React.Component {
}

render() {
const { resources } = this.props;
const titleLevelRequestsFeatureEnabled = getEcsTlrFeature(resources?.settings?.records);
let entryList = sortBy((this.props.resources.entries || {}).records || [], ['name']);
entryList = entryList.map(item => {
item.pickupLocation = item.pickupLocation || false;
Expand Down Expand Up @@ -117,6 +128,7 @@ class ServicePointManager extends React.Component {
nameKey="name"
editable={isEditable}
permissions={permissions}
titleLevelRequestsFeatureEnabled={titleLevelRequestsFeatureEnabled}
/>
</TitleManager>
);
Expand Down
13 changes: 9 additions & 4 deletions src/settings/ServicePoints/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { get } from 'lodash';

export const validateServicePointForm = (values) => {
const errors = {};
Expand Down Expand Up @@ -54,10 +55,14 @@ export const getUniquenessValidation = (field, mutator) => {
};
};

export const isEcsRequestRoutingVisible = (stripes) => (
stripes.hasInterface('consortia') && stripes.hasInterface('ecs-tlr')
export const isEcsRequestRoutingVisible = (titleLevelRequestsFeatureEnabled) => (
!!titleLevelRequestsFeatureEnabled
);

export const isEcsRequestRoutingAssociatedFieldsVisible = (stripes, ecsRequestRouting) => (
(isEcsRequestRoutingVisible(stripes) && !ecsRequestRouting) || !isEcsRequestRoutingVisible(stripes)
export const isEcsRequestRoutingAssociatedFieldsVisible = (titleLevelRequestsFeatureEnabled, ecsRequestRouting) => (
(isEcsRequestRoutingVisible(titleLevelRequestsFeatureEnabled) && !ecsRequestRouting) || !isEcsRequestRoutingVisible(titleLevelRequestsFeatureEnabled)
);

export const getEcsTlrFeature = (data = []) => (
get(data, '[0].value.enabled', false)
);
Loading

0 comments on commit 8a68ed2

Please sign in to comment.