Skip to content

Commit

Permalink
UIIN-3167: Fix infinite loading animation after cancel edit/duplicate…
Browse files Browse the repository at this point in the history
… or 'Save & Close' consortial holdings/items
  • Loading branch information
OleksandrHladchenko1 committed Jan 6, 2025
1 parent 6137977 commit c77c904
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Remove the ability to share local instance when `Inventory: View, create instances` permission is assigned. Fixes UIIN-3166.
* Display holdings names in `Consortial holdings` accordion for user without inventory permissions in member tenants. Fixes UIIN-3159
* Add "linked-data 1.0" interface to "optionalOkapiInterfaces". Refs UIIN-3166.
* Fix infinite loading animation after cancel edit/duplicate or 'Save & Close' consortial holdings/items. Fixes UIIN-3167.

## [12.0.7](https://github.com/folio-org/ui-inventory/tree/v12.0.7) (2024-12-17)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v12.0.6...v12.0.7)
Expand Down
6 changes: 4 additions & 2 deletions src/Holding/DuplicateHolding/DuplicateHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DuplicateHolding = ({
state: {
backPathname: locationState,
tenantFrom,
initialTenantId,
} = {},
},
referenceTables,
Expand Down Expand Up @@ -72,12 +73,13 @@ const DuplicateHolding = ({
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}`,
search,
state: { initialTenantId },
});
}, [search, instanceId]);

const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);
await switchAffiliation(stripes, initialTenantId, goBack);
}, [stripes, initialTenantId, goBack]);

const onSubmit = useCallback(holdingValues => (
mutateHolding(holdingValues)
Expand Down
20 changes: 7 additions & 13 deletions src/Holding/EditHolding/EditHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import {
} from '../../hooks';
import HoldingsForm from '../../edit/holdings/HoldingsForm';
import withLocation from '../../withLocation';
import {
parseHttpError,
switchAffiliation,
} from '../../utils';
import { parseHttpError } from '../../utils';

const EditHolding = ({
goTo,
Expand All @@ -35,7 +32,7 @@ const EditHolding = ({
search,
state: {
backPathname: locationState,
tenantFrom,
initialTenantId,
} = {},
} = location;
const stripes = useStripes();
Expand All @@ -59,16 +56,13 @@ const EditHolding = ({
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}/${holdingId}`,
search,
state: { initialTenantId },
});
}, [search, instanceId, holdingId]);

const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);

const onSuccess = useCallback(async () => {
const onSuccess = useCallback(() => {
if (!keepEditing.current) {
await switchAffiliation(stripes, tenantFrom, goBack);
goBack();
} else {
refetchHolding();
}
Expand All @@ -80,7 +74,7 @@ const EditHolding = ({
values={{ hrid: holding?.hrid }}
/>,
});
}, [switchAffiliation, stripes, tenantFrom, goBack, refetchHolding, holding, callout]);
}, [goBack, refetchHolding, holding, callout]);

const onError = async error => {
const parsedError = await parseHttpError(error.response);
Expand All @@ -107,7 +101,7 @@ const EditHolding = ({
location={location}
initialValues={holding}
onSubmit={onSubmit}
onCancel={onCancel}
onCancel={goBack}
okapi={stripes.okapi}
instance={instance}
referenceTables={referenceTables}
Expand Down
2 changes: 1 addition & 1 deletion src/Instance/ItemsList/ItemBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ItemBarcode = ({
search,
state: {
tenantTo: tenantId,
tenantFrom: stripes.okapi.tenant,
initialTenantId: stripes.okapi.tenant,
},
});

Expand Down
1 change: 1 addition & 0 deletions src/Instance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const navigateToHoldingsViewPage = (history, location, instance, holding,
state: {
tenantTo,
tenantFrom,
initialTenantId: tenantFrom,
},
});
};
Expand Down
5 changes: 4 additions & 1 deletion src/Item/DuplicateItem/DuplicateItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ const DuplicateItem = ({
history.push({
pathname: `/inventory/view/${instanceId}/${holdingId}/${itemId}`,
search: location.search,
state: { tenantTo: stripes.okapi.tenant },
state: {
tenantTo: stripes.okapi.tenant,
initialTenantId: location?.state?.initialTenantId,
},
});
}, [location.search, instanceId, holdingId, itemId]);

Expand Down
20 changes: 9 additions & 11 deletions src/Item/EditItem/EditItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../../common';
import ItemForm from '../../edit/items/ItemForm';
import useCallout from '../../hooks/useCallout';
import { parseHttpError, switchAffiliation } from '../../utils';
import { parseHttpError } from '../../utils';
import {
useItem,
useItemMutation,
Expand Down Expand Up @@ -49,18 +49,16 @@ const EditItem = ({
history.push({
pathname: `/inventory/view/${instanceId}/${holdingId}/${itemId}`,
search: location.search,
state: { tenantTo: stripes.okapi.tenant },
state: {
tenantTo: stripes.okapi.tenant,
initialTenantId: location?.state?.initialTenantId,
},
});
}, [location.search, instanceId, holdingId, itemId]);

const onCancel = useCallback(async () => {
await switchAffiliation(stripes, location?.state?.tenantFrom, goBack);
}, [stripes, location?.state?.tenantFrom, goBack]);


const onSuccess = useCallback(async () => {
const onSuccess = useCallback(() => {
if (!keepEditing.current) {
await switchAffiliation(stripes, location?.state?.tenantFrom, goBack);
goBack();
} else {
refetchItem();
}
Expand All @@ -72,7 +70,7 @@ const EditItem = ({
values={{ hrid: item.hrid }}
/>,
});
}, [switchAffiliation, stripes, location, goBack, refetchItem, callout, item]);
}, [goBack, refetchItem, callout, item]);

const onError = async error => {
const parsedError = await parseHttpError(error.response);
Expand Down Expand Up @@ -129,7 +127,7 @@ const EditItem = ({
key={holding.id}
initialValues={item}
onSubmit={onSubmit}
onCancel={onCancel}
onCancel={goBack}
okapi={stripes.okapi}
instance={instance}
holdingsRecord={holding}
Expand Down
19 changes: 8 additions & 11 deletions src/ViewHoldingsRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class ViewHoldingsRecord extends React.Component {
stripes,
location,
} = this.props;
const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;
const tenantFrom = location?.state?.initialTenantId || stripes.okapi.tenant;

await switchAffiliation(stripes, tenantFrom, this.goToInstanceView);
}
Expand All @@ -264,17 +264,15 @@ class ViewHoldingsRecord extends React.Component {
location,
id,
holdingsrecordid,
stripes,
initialTenantId,
} = this.props;

const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;

history.push({
pathname: `/inventory/edit/${id}/${holdingsrecordid}`,
search: location.search,
state: {
backPathname: location.pathname,
tenantFrom,
initialTenantId,
},
});
}
Expand All @@ -288,16 +286,18 @@ class ViewHoldingsRecord extends React.Component {
id,
holdingsrecordid,
stripes,
initialTenantId,
} = this.props;

const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;
const tenantFrom = stripes.okapi.tenant;

history.push({
pathname: `/inventory/copy/${id}/${holdingsrecordid}`,
search: location.search,
state: {
backPathname: location.pathname,
tenantFrom,
initialTenantId,
},
});
}
Expand Down Expand Up @@ -641,10 +641,8 @@ class ViewHoldingsRecord extends React.Component {
referenceTables,
goTo,
stripes,
location,
} = this.props;
const { instance } = this.state;
const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;

if (this.isAwaitingResource()) return <LoadingView />;

Expand Down Expand Up @@ -957,9 +955,7 @@ class ViewHoldingsRecord extends React.Component {
updatedDate: getDate(holdingsRecord?.metadata?.updatedDate),
})}
dismissible
onClose={async () => {
await switchAffiliation(stripes, tenantFrom, this.onClose);
}}
onClose={this.onClose}
actionMenu={this.getPaneHeaderActionMenu}
>
<Row center="xs">
Expand Down Expand Up @@ -1390,6 +1386,7 @@ ViewHoldingsRecord.propTypes = {
goTo: PropTypes.func.isRequired,
isInstanceShared: PropTypes.bool,
onUpdateOwnership: PropTypes.func,
initialTenantId: PropTypes.string,
};

export default flowRight(
Expand Down
2 changes: 1 addition & 1 deletion src/routes/ItemRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ItemRoute = props => {
{...props}
isInstanceShared={instance?.shared}
tenantTo={state?.tenantTo || okapi.tenant}
initialTenantId={state?.initialTenantId || okapi.tenant}
referenceTables={data}
/>
)}
Expand All @@ -39,7 +40,6 @@ ItemRoute.propTypes = {
location: PropTypes.object,
resources: PropTypes.object,
stripes: PropTypes.object,
tenantFrom: PropTypes.string,
history: PropTypes.object,
};

Expand Down
1 change: 1 addition & 0 deletions src/routes/ViewHoldingRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ViewHoldingRoute = () => {
id={instanceId}
isInstanceShared={instance?.shared}
tenantTo={state?.tenantTo || okapi.tenant}
initialTenantId={state?.initialTenantId || okapi.tenant}
referenceTables={referenceTables}
holdingsrecordid={holdingsrecordid}
onUpdateOwnership={updateOwnership}
Expand Down
18 changes: 13 additions & 5 deletions src/views/ItemView.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const ItemView = props => {
},
goTo,
isInstanceShared,
initialTenantId,
} = props;

const ky = useOkapiKy();
Expand Down Expand Up @@ -176,13 +177,16 @@ const ItemView = props => {
const onClickEditItem = e => {
if (e) e.preventDefault();

const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;
const tenantFrom = stripes.okapi.tenant;
const { id, holdingsrecordid, itemid } = match.params;

history.push({
pathname: `/inventory/edit/${id}/${holdingsrecordid}/${itemid}`,
search: location.search,
state: { tenantFrom }
state: {
tenantFrom,
initialTenantId,
}
});
};

Expand All @@ -200,7 +204,7 @@ const ItemView = props => {
};

const onCloseViewItem = async () => {
const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;
const tenantFrom = location?.state?.initialTenantId || stripes.okapi.tenant;

await switchAffiliation(stripes, tenantFrom, () => goBack(tenantFrom));
};
Expand All @@ -212,12 +216,15 @@ const ItemView = props => {

const onCopy = () => {
const { itemid, id, holdingsrecordid } = match.params;
const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;
const tenantFrom = stripes.okapi.tenant;

history.push({
pathname: `/inventory/copy/${id}/${holdingsrecordid}/${itemid}`,
search: location.search,
state: { tenantFrom },
state: {
tenantFrom,
initialTenantId,
},
});
};

Expand Down Expand Up @@ -1938,6 +1945,7 @@ ItemView.propTypes = {
match: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
isInstanceShared: PropTypes.bool,
initialTenantId: PropTypes.string,
};

export default flowRight(
Expand Down

0 comments on commit c77c904

Please sign in to comment.