Skip to content

Commit

Permalink
7592 - Relationships save fix (#7687)
Browse files Browse the repository at this point in the history
* remove extra action

* dispatch the correct action based on entity
  • Loading branch information
Zasa-san authored Feb 20, 2025
1 parent 78ac5fd commit 4d42a55
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
9 changes: 6 additions & 3 deletions app/react/Relationships/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,12 @@ function saveRelationships() {
])
)
.then(([response, parentEntity]) => {
dispatch(actions.set('entityView/entity', parentEntity));
dispatch(actions.set('viewer/doc', parentEntity));

if (parentEntity.documents?.length) {
const defaultDoc = getState().documentViewer.doc.get('defaultDoc');
dispatch(actions.set('viewer/doc', { ...parentEntity, defaultDoc }));
} else {
dispatch(actions.set('entityView/entity', parentEntity));
}
dispatch(uiActions.closePanel());
dispatch(
edit(
Expand Down
61 changes: 55 additions & 6 deletions app/react/Relationships/actions/specs/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { fromJS as Immutable } from 'immutable';
import { mockID } from 'shared/uniqueID.js';
import { RequestParams } from 'app/utils/RequestParams';
import SearchApi from 'app/Search/SearchAPI';

import api from 'app/utils/api';
import * as types from '../actionTypes';
import * as actions from '../actions';

import * as routeUtils from '../../utils/routeUtils';

const middlewares = [thunk];
Expand Down Expand Up @@ -235,6 +233,13 @@ describe('Relationships actions', () => {
describe('saveRelationships', () => {
let store;
let hubs;
let entity = {
_id: '1',
sharedId: 'entityId',
entity: 'fullEntity',
searchResults: 'storeSearchResults',
};
let defaultDoc;

function getState() {
return {
Expand All @@ -246,6 +251,9 @@ describe('Relationships actions', () => {
},
hubs,
},
documentViewer: {
doc: Immutable({ ...entity, ...(defaultDoc && { defaultDoc, documents: [defaultDoc] }) }),
},
};
}

Expand Down Expand Up @@ -313,7 +321,7 @@ describe('Relationships actions', () => {
]);

spyOn(api, 'post').and.returnValue(Promise.resolve('POSTresponse'));
spyOn(api, 'get').and.returnValue(Promise.resolve({ json: { rows: ['entity'] } }));
spyOn(api, 'get').and.returnValue(Promise.resolve({ json: { rows: [entity] } }));
spyOn(routeUtils, 'requestState').and.returnValue(
Promise.resolve(['reloadedConnectionsGroups', 'reloadedSearchResults'])
);
Expand All @@ -332,8 +340,49 @@ describe('Relationships actions', () => {
value: 'reloadedConnectionsGroups',
},
{ type: 'relationships/list/searchResults/SET', value: 'reloadedSearchResults' },
{ type: 'entityView/entity/SET', value: 'entity' },
{ type: 'viewer/doc/SET', value: 'entity' },
{ type: 'entityView/entity/SET', value: entity },
{ type: 'CLOSE_RELATIONSHIPS_PANEL' },
{
type: 'EDIT_RELATIONSHIPS',
value: false,
results: 'storeSearchResults',
parentEntity: 'fullEntity',
editing: false,
},
{ type: 'SAVED_RELATIONSHIPS', response: 'POSTresponse' },
{
type: 'NOTIFY',
notification: { message: 'Relationships saved', type: 'success', id: 'unique_id' },
},
{
type: 'SET_REFERENCES',
references: {
rows: [entity],
},
},
]);
done();
});
});

it('should update the store to update the document viewer if the entity has document', done => {
defaultDoc = { _id: '1', title: 'MyDoc' };
entity.documents = [defaultDoc];

actions
.saveRelationships()(store.dispatch, getState)
.then(() => {
expect(store.getActions()).toEqual([
{ type: types.SAVING_RELATIONSHIPS },
{
type: 'relationships/list/connectionsGroups/SET',
value: 'reloadedConnectionsGroups',
},
{ type: 'relationships/list/searchResults/SET', value: 'reloadedSearchResults' },
{
type: 'viewer/doc/SET',
value: { ...entity, defaultDoc: Immutable(defaultDoc) },
},
{ type: 'CLOSE_RELATIONSHIPS_PANEL' },
{
type: 'EDIT_RELATIONSHIPS',
Expand All @@ -350,7 +399,7 @@ describe('Relationships actions', () => {
{
type: 'SET_REFERENCES',
references: {
rows: ['entity'],
rows: [entity],
},
},
]);
Expand Down

0 comments on commit 4d42a55

Please sign in to comment.