Skip to content

Commit

Permalink
Merge branch 'master' into UIIN-2452
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrHladchenko1 authored Oct 26, 2023
2 parents 22ec665 + 09b0d1b commit b5c1604
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* User receives an error when searching for an item in the Inventory app. Fixes UIIN-2634.
* Create new instance success toast no longer shows the instance HRID. Fixes UIIN-2635.
* Optimistic locking message not working for instances in non-consortial tenant. Fixes UIIN-2628.
* Add immediate warning message when a local instance is shared. Refs UIIN-2617.

## [10.0.0](https://github.com/folio-org/ui-inventory/tree/v10.0.0) (2023-10-13)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v9.4.12...v10.0.0)
Expand Down
97 changes: 60 additions & 37 deletions src/Instance/InstanceDetails/InstanceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const InstanceDetails = forwardRef(({
userTenantPermissions,
isShared,
isLoading,
isInstanceSharing,
...rest
}, ref) => {
const intl = useIntl();
Expand All @@ -85,12 +86,15 @@ const InstanceDetails = forwardRef(({
const accordionState = useMemo(() => getAccordionState(instance, accordions), [instance]);
const [helperApp, setHelperApp] = useState();

const isBasicPane = isInstanceSharing || isLoading;
const tags = instance?.tags?.tagList;
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);

const canCreateHoldings = stripes.hasPerm('ui-inventory.holdings.create');

const detailsLastMenu = useMemo(() => {
if (isBasicPane) return null;

return (
<PaneMenu>
{
Expand All @@ -106,31 +110,15 @@ const InstanceDetails = forwardRef(({
}
</PaneMenu>
);
}, [tagsEnabled, tags, intl]);

if (isLoading) {
return (
<Pane
id="pane-instancedetails"
defaultWidth="fill"
paneTitle={intl.formatMessage({ id: 'ui-inventory.edit' })}
appIcon={<AppIcon app="inventory" iconKey="instance" />}
dismissible
onClose={onClose}
>
<div style={{ paddingTop: '1rem' }}>
<Icon
icon="spinner-ellipsis"
width="100px"
/>
</div>
</Pane>
);
}

const isConsortialHoldingsVisible = instance?.shared || isInstanceShadowCopy(instance?.source);
}, [isBasicPane, tagsEnabled, tags, intl]);
const detailsActionMenu = useMemo(
() => (isBasicPane ? null : actionMenu),
[isBasicPane, actionMenu],
);

const renderPaneTitle = () => {
if (isBasicPane) return intl.formatMessage({ id: 'ui-inventory.edit' });

const isInstanceShared = Boolean(isShared || isInstanceShadowCopy(instance?.source));

return (
Expand All @@ -146,6 +134,8 @@ const InstanceDetails = forwardRef(({
};

const renderPaneSubtitle = () => {
if (isBasicPane) return null;

return (
<FormattedMessage
id="ui-inventory.instanceRecordSubtitle"
Expand All @@ -157,20 +147,32 @@ const InstanceDetails = forwardRef(({
);
};

return (
<>
<Pane
{...rest}
data-test-instance-details
appIcon={<AppIcon app="inventory" iconKey="instance" />}
paneTitle={renderPaneTitle()}
paneSub={renderPaneSubtitle()}
dismissible
onClose={onClose}
actionMenu={actionMenu}
defaultWidth="fill"
lastMenu={detailsLastMenu}
>
const renderDetails = () => {
if (isInstanceSharing) {
return (
<div>
<MessageBanner show={Boolean(isInstanceSharing)} type="warning">
<FormattedMessage id="ui-inventory.warning.instance.sharingLocalInstance" />
</MessageBanner>
</div>
);
}

if (isLoading) {
return (
<div>
<Icon
icon="spinner-ellipsis"
width="100px"
/>
</div>
);
}

const isConsortialHoldingsVisible = instance?.shared || isInstanceShadowCopy(instance?.source);

return (
<>
<TitleManager record={instance.title} />

<AccordionStatus ref={ref}>
Expand Down Expand Up @@ -291,6 +293,25 @@ const InstanceDetails = forwardRef(({
/>
</AccordionSet>
</AccordionStatus>
</>
);
};

return (
<>
<Pane
{...rest}
data-test-instance-details
appIcon={<AppIcon app="inventory" iconKey="instance" />}
paneTitle={renderPaneTitle()}
paneSub={renderPaneSubtitle()}
actionMenu={detailsActionMenu}
lastMenu={detailsLastMenu}
dismissible
onClose={onClose}
defaultWidth="fill"
>
{renderDetails()}
</Pane>
{ helperApp && <HelperApp appName={helperApp} onClose={setHelperApp} />}
</>
Expand All @@ -306,13 +327,15 @@ InstanceDetails.propTypes = {
tagsEnabled: PropTypes.bool,
userTenantPermissions: PropTypes.arrayOf(PropTypes.object),
isLoading: PropTypes.bool,
isInstanceSharing: PropTypes.bool,
isShared: PropTypes.bool,
};

InstanceDetails.defaultProps = {
instance: {},
tagsEnabled: false,
isLoading: false,
isInstanceSharing: false,
isShared: false,
};

Expand Down
7 changes: 7 additions & 0 deletions src/Instance/InstanceDetails/InstanceDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ describe('InstanceDetails', () => {
expect(screen.getByText('Instance relationship (analytics and bound-with)')).toBeInTheDocument();
});

it('should show a correct Warning message banner when instance sharing is in progress', () => {
renderInstanceDetails({ isInstanceSharing: true });

expect(screen.getByText('Sharing this local instance will take a few moments.' +
' A success message and updated details will be displayed upon completion.')).toBeInTheDocument();
});

it('should show a correct Warning message banner when staff suppressed', () => {
const staffSuppressedInstance = {
...instance,
Expand Down
16 changes: 11 additions & 5 deletions src/ViewInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ViewInstance extends React.Component {
this.log = logger.log.bind(logger);

this.state = {
isLoading: false,
isInstanceSharing: false,
marcRecord: null,
findInstancePluginOpened: false,
isItemsMovement: false,
Expand Down Expand Up @@ -493,14 +493,14 @@ class ViewInstance extends React.Component {
this.setState({
isUnlinkAuthoritiesModalOpen: false,
isShareLocalInstanceModalOpen: false,
isLoading: true
isInstanceSharing: true,
});

await this.waitForInstanceSharingComplete({ sourceTenantId, instanceIdentifier, instanceTitle });
})
.then(async () => {
await this.props.refetchInstance();
this.setState({ isLoading: false });
this.setState({ isInstanceSharing: false });
this.calloutRef.current.sendCallout({
type: 'success',
message: <FormattedMessage id="ui-inventory.shareLocalInstance.toast.successful" values={{ instanceTitle }} />,
Expand Down Expand Up @@ -883,8 +883,12 @@ class ViewInstance extends React.Component {
canUseSingleRecordImport,
isCentralTenantPermissionsLoading,
isShared,
isLoading,
} = this.props;
const { linkedAuthoritiesLength } = this.state;
const {
linkedAuthoritiesLength,
isInstanceSharing,
} = this.state;
const ci = makeConnectedInstance(this.props, stripes.logger);
const instance = ci.instance();

Expand Down Expand Up @@ -918,7 +922,7 @@ class ViewInstance extends React.Component {
handler: (e) => collapseAllSections(e, this.accordionStatusRef),
},
];
const isInstanceLoading = this.state.isLoading || !instance || isCentralTenantPermissionsLoading;
const isInstanceLoading = isLoading || !instance || isCentralTenantPermissionsLoading;
const keyInStorageToHoldingsAccsState = ['holdings'];

return (
Expand All @@ -938,6 +942,7 @@ class ViewInstance extends React.Component {
ref={this.accordionStatusRef}
userTenantPermissions={this.state.userTenantPermissions}
isLoading={isInstanceLoading}
isInstanceSharing={isInstanceSharing}
isShared={isShared}
>
{
Expand Down Expand Up @@ -1093,6 +1098,7 @@ ViewInstance.propTypes = {
}).isRequired,
tagsEnabled: PropTypes.bool,
updateLocation: PropTypes.func.isRequired,
isLoading: PropTypes.bool,
};

export default flowRight(
Expand Down
3 changes: 2 additions & 1 deletion src/ViewInstanceWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ViewInstanceWrapper = (props) => {
const userId = stripes?.user?.user?.id;
const centralTenantId = stripes.user.user?.consortium?.centralTenantId;
const consortiumId = stripes.user.user?.consortium?.id;
const { instance, refetch } = useInstance(id);
const { instance, isLoading, refetch } = useInstance(id);

const isShared = Boolean(instance?.shared);
const tenantId = instance?.tenantId ?? stripes.okapi.tenant;
Expand All @@ -41,6 +41,7 @@ const ViewInstanceWrapper = (props) => {
consortiumId={consortiumId}
refetchInstance={refetch}
selectedInstance={instance}
isLoading={isLoading}
centralTenantPermissions={centralTenantPermissions}
isCentralTenantPermissionsLoading={isCentralTenantPermissionsLoading}
/>
Expand Down
6 changes: 5 additions & 1 deletion src/common/hooks/useInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const useInstance = (id) => {
const instanceTenantId = _instance?.tenantId;
const isShared = _instance?.shared;

const { isLoading, instance: data, refetch } = useInstanceQuery(
const { isLoading: isInstanceLoading, instance: data, refetch } = useInstanceQuery(
id,
{ tenantId: instanceTenantId },
{ enabled: Boolean(id && !isSearchInstanceByIdLoading) }
Expand All @@ -23,6 +23,10 @@ const useInstance = (id) => {
}),
[data, isShared, instanceTenantId],
);
const isLoading = useMemo(
() => isSearchInstanceByIdLoading || isInstanceLoading,
[isSearchInstanceByIdLoading, isInstanceLoading],
);

return {
instance,
Expand Down
1 change: 1 addition & 0 deletions translations/ui-inventory/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@
"warning.instance.suppressedFromDiscovery": "Warning: Instance is marked suppressed from discovery",
"warning.instance.staffSuppressed": "Warning: Instance is marked staff suppressed",
"warning.instance.suppressedFromDiscoveryAndStaffSuppressed": "Warning: Instance is marked suppressed from discovery and staff suppressed",
"warning.instance.sharingLocalInstance": "Sharing this local instance will take a few moments. A success message and updated details will be displayed upon completion.",
"warning.holdingsRecord.suppressedFromDiscovery": "Warning: Holdings is marked suppressed from discovery",
"warning.item.suppressedFromDiscovery": "Warning: Item is marked suppressed from discovery",
"discoverySuppressed": "Suppressed from discovery",
Expand Down

0 comments on commit b5c1604

Please sign in to comment.