Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Fix translation for select placeholder. (UIDATIMP-1756)
* Always allow redirect to `/logout` on session termination. (UIDATIMP-1764)
* Fix error when user tries to save edited Job profile with `Delete MARC Authority` action. (UIDATIMP-1776)
* Prevent deleting action profile from both places in Job profile when it is used twice and user deletes it in one place. (UIDATIMP-1794)

## [10.0.0](https://github.com/folio-org/ui-data-import/tree/v10.0.0) (2026-04-15)
[Full Changelog](https://github.com/folio-org/ui-data-import/compare/v9.0.2...v10.0.0)
Expand Down
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const { config } = require('@folio/jest-config-stripes');
const config = require('@folio/jest-config-stripes');
const acqConfigs = require('@folio/stripes-acq-components/jest.config');

const transformIgnorePattern = config.transformIgnorePatterns[0]
.replace(')', '|keyboardjs)');

module.exports = {
...config,
transform: {
...acqConfigs.transform,
},
transformIgnorePatterns: [transformIgnorePattern],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@babel/eslint-parser": "^7.17.0",
"@babel/plugin-transform-runtime": "^7.22.15",
"@folio/eslint-config-stripes": "^8.0.0",
"@folio/jest-config-stripes": "^4.0.0",
"@folio/jest-config-stripes": "^3.1.0",
"@folio/stripes": "^10.1.0",
"@folio/stripes-cli": "^5.0.0",
"@folio/stripes-components": "^13.1.0",
Expand Down
44 changes: 26 additions & 18 deletions src/components/ProfileTree/ProfileTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,26 @@ export const ProfileTree = memo(({
&& (rel.reactTo !== undefined ? rel.reactTo === reactTo : reactTo === null)));
};

const getSubtreeProfileIds = (line, ids = []) => {
ids.push(line.content.id);
const getSubtreeRelations = (line, masterProfileId, reactTo, relations = []) => {
relations.push({
masterProfileId,
detailProfileId: line.profileId || line.content.id,
reactTo,
});

(line.childSnapshotWrappers || []).forEach(child => getSubtreeProfileIds(child, ids));
(line.childSnapshotWrappers || []).forEach(child => {
if (child.contentType !== PROFILE_TYPES.MAPPING_PROFILE) {
getSubtreeRelations(child, child.profileId || child.content.id, child.reactTo, relations);
}
});

return ids;
return relations;
};

const getRelationKey = ({ masterProfileId, detailProfileId, reactTo }) => (
JSON.stringify([masterProfileId, detailProfileId, reactTo || null])
);

const composeRelations = ({
lines,
masterId,
Expand Down Expand Up @@ -206,10 +218,10 @@ export const ProfileTree = memo(({
reactTo,
localDataKey,
}) => {
const subtreeProfileIds = getSubtreeProfileIds(line);
const subtreeRelations = getSubtreeRelations(line, masterId, reactTo);
const subtreeRelationKeys = new Set(subtreeRelations.map(getRelationKey));
const relsToAdd = [...addedRelations].filter(rel => {
return !subtreeProfileIds.includes(rel.masterProfileId)
&& !subtreeProfileIds.includes(rel.detailProfileId);
return !subtreeRelationKeys.has(getRelationKey(rel));
});

if (relsToAdd.length !== addedRelations.length) {
Expand Down Expand Up @@ -243,8 +255,7 @@ export const ProfileTree = memo(({
setDeletedRelations(relsToDel);
} else {
const remainingAddedRelations = [...addedRelations]
.filter(rel => !subtreeProfileIds.includes(rel.masterProfileId)
&& !subtreeProfileIds.includes(rel.detailProfileId));
.filter(rel => !subtreeRelationKeys.has(getRelationKey(rel)));

// set added relations to form field
onLink(remainingAddedRelations);
Expand All @@ -259,20 +270,17 @@ export const ProfileTree = memo(({

setParentData(newSectionData);

const getNewProfileTreeData = function buildData(array, lineToCompare) {
return array.filter(item => {
if (lineToCompare.childSnapshotWrappers?.length) {
return buildData(lineToCompare.childSnapshotWrappers, item).length;
}

return item.id !== lineToCompare.id;
});
const subtreeProfiles = new Set();
const collectSubtreeProfiles = item => {
subtreeProfiles.add(item);
(item.childSnapshotWrappers || []).forEach(collectSubtreeProfiles);
};
collectSubtreeProfiles(line);

const sectionDataForStorage = set({}, localDataKey, newSectionData);

dispatch(setCurrentProfileTreeContent(sectionDataForStorage));
dispatch(setProfileTreeContent(getNewProfileTreeData([...profileTreeContent], line)));
dispatch(setProfileTreeContent(profileTreeContent.filter(item => !subtreeProfiles.has(item))));
};

return (
Expand Down
79 changes: 79 additions & 0 deletions src/components/ProfileTree/ProfileTree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
fireEvent,
waitFor,
} from '@folio/jest-config-stripes/testing-library/react';
import { combineReducers, createStore } from 'redux';
import { Provider } from 'react-redux';
import { noop } from 'lodash';
import { runAxeTest } from '@folio/stripes-testing';

Expand All @@ -20,6 +22,7 @@ import {
STATE_MANAGEMENT,
DEFAULT_DELETE_MARC_AUTH_ACTION_ID,
} from '../../utils';
import { reducer } from '../../redux';
import { ProfileTree } from './ProfileTree';

jest.mock('@folio/stripes/components', () => ({
Expand Down Expand Up @@ -220,6 +223,82 @@ describe('ProfileTree component', () => {
expect(container.querySelector('#type-selector-dropdown-linker-root')).not.toBeInTheDocument();
});

it('should only unlink the selected occurrence of a shared action profile', async () => {
const matchAction = {
id: 'action-id',
profileId: 'action-id',
contentType: 'ACTION_PROFILE',
reactTo: 'MATCH',
content: {
id: 'action-id',
name: 'Shared action',
},
childSnapshotWrappers: [],
};
const nonMatchAction = {
...matchAction,
reactTo: 'NON_MATCH',
};
const matchProfile = {
id: 'match-id',
profileId: 'match-id',
contentType: 'MATCH_PROFILE',
content: {
id: 'match-id',
name: 'Parent match',
},
childSnapshotWrappers: [matchAction, nonMatchAction],
};
const matchRelation = {
masterProfileId: 'match-id',
detailProfileId: 'action-id',
reactTo: 'MATCH',
};
const nonMatchRelation = {
masterProfileId: 'match-id',
detailProfileId: 'action-id',
reactTo: 'NON_MATCH',
};
const onLink = jest.fn();
const initialState = {
[STATE_MANAGEMENT.REDUCER]: {
profileTreeData: [matchProfile, matchAction, nonMatchAction],
jobProfiles: {},
},
};
const store = createStore(
combineReducers({ [STATE_MANAGEMENT.REDUCER]: reducer }),
initialState,
);
const props = profileTreeProps({
allowUnlink: true,
allowDelete: false,
});
const { container, findByText } = renderWithIntl(
<Provider store={store}>
<ProfileTree
{...props}
contentData={[matchProfile]}
relationsToAdd={[matchRelation, nonMatchRelation]}
onLink={onLink}
/>
</Provider>,
translationsProperties,
);

fireEvent.click(container.querySelectorAll('button[data-test-profile-unlink]')[1]);
fireEvent.click(await findByText('Confirm'));

await waitFor(() => {
expect(onLink).toHaveBeenLastCalledWith([nonMatchRelation]);
});
expect(container.querySelectorAll('[data-test-profile-branch]')).toHaveLength(2);
expect(store.getState()[STATE_MANAGEMENT.REDUCER].profileTreeData).toEqual([
matchProfile,
nonMatchAction,
]);
});

it('should be rendered', async () => {
global.fetch.mockReturnValue({
ok: true,
Expand Down
3 changes: 2 additions & 1 deletion test/jest/__mock__/resizeObserver.mock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.ResizeObserver = jest.fn(() => ({
window.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
Loading