Skip to content

Commit

Permalink
Merge pull request #2094 from huridocs/fix_reindex_relationships
Browse files Browse the repository at this point in the history
Fix reindex relationships
  • Loading branch information
RafaPolit authored Nov 22, 2018
2 parents 2467f57 + 999557b commit 1806169
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 129 deletions.
2 changes: 1 addition & 1 deletion app/api/entities/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default {
}

return this.get(query, select, { skip: offset, limit })
.then(entities => Promise.all(entities.map(entity => relationships.get({ entity: entity.sharedId, language: entity.language })
.then(entities => Promise.all(entities.map(entity => relationships.get({ entity: entity.sharedId })
.then((relations) => {
entity.relationships = relations || [];
return entity;
Expand Down
31 changes: 27 additions & 4 deletions app/api/entities/specs/entities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,38 @@ describe('entities', () => {

describe('indexEntities', () => {
it('should index entities based on query params passed', (done) => {
entities.indexEntities({ sharedId: 'shared' }, { title: 1 })
entities.indexEntities({ sharedId: 'shared' })
.then(() => {
const documentsToIndex = search.bulkIndex.calls.argsFor(0)[0];
expect(documentsToIndex[0].title).toBeDefined();
expect(documentsToIndex[0].metadata).not.toBeDefined();
expect(documentsToIndex[0].fullText).not.toBeDefined();
expect(documentsToIndex[0].relationships.length).toBe(4);

expect(documentsToIndex[1].title).toBeDefined();
expect(documentsToIndex[1].fullText).not.toBeDefined();
expect(documentsToIndex[1].relationships.length).toBe(4);

expect(documentsToIndex[2].title).toBeDefined();
expect(documentsToIndex[2].fullText).not.toBeDefined();
expect(documentsToIndex[2].relationships.length).toBe(4);
done();
})
.catch(catchErrors(done));
});

it('should index entities withh fullText', (done) => {
entities.indexEntities({ sharedId: 'shared' }, '+fullText')
.then(() => {
const documentsToIndex = search.bulkIndex.calls.argsFor(0)[0];
expect(documentsToIndex[0].title).toBeDefined();
expect(documentsToIndex[0].fullText).toBeDefined();
expect(documentsToIndex[0].relationships.length).toBe(4);

expect(documentsToIndex[1].title).toBeDefined();
expect(documentsToIndex[1].metadata).not.toBeDefined();
expect(documentsToIndex[1].relationships.length).toBe(4);

expect(documentsToIndex[2].title).toBeDefined();
expect(documentsToIndex[2].metadata).not.toBeDefined();
expect(documentsToIndex[2].relationships.length).toBe(4);
done();
})
.catch(catchErrors(done));
Expand Down
20 changes: 10 additions & 10 deletions app/api/entities/specs/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ export default {
] }
],
connections: [
{ _id: referenceId, entity: 'shared', template: null, hub: hub1, language: 'en' },
{ entity: 'shared2', template: 'relation1', hub: hub1, language: 'en' },
{ entity: 'shared', template: null, hub: hub2, language: 'en' },
{ entity: 'source2', template: 'relation2', hub: hub2, language: 'en' },
{ entity: 'another', template: 'relation3', hub: hub3, language: 'en' },
{ entity: 'document', template: 'relation3', hub: hub3, language: 'en' },
{ entity: 'shared', template: 'relation2', hub: hub4, language: 'en' },
{ entity: 'shared1', template: 'relation2', hub: hub4, language: 'en' },
{ entity: 'shared1', template: 'relation2', hub: hub5, language: 'en' },
{ entity: 'shared', template: 'relation2', hub: hub5, language: 'en' }
{ _id: referenceId, entity: 'shared', template: null, hub: hub1 },
{ entity: 'shared2', template: 'relation1', hub: hub1 },
{ entity: 'shared', template: null, hub: hub2 },
{ entity: 'source2', template: 'relation2', hub: hub2 },
{ entity: 'another', template: 'relation3', hub: hub3 },
{ entity: 'document', template: 'relation3', hub: hub3 },
{ entity: 'shared', template: 'relation2', hub: hub4 },
{ entity: 'shared1', template: 'relation2', hub: hub4 },
{ entity: 'shared1', template: 'relation2', hub: hub5 },
{ entity: 'shared', template: 'relation2', hub: hub5 }
]
};

Expand Down
64 changes: 29 additions & 35 deletions app/react/Viewer/actions/documentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,18 @@ export function saveDocument(doc) {
}
});

return function (dispatch) {
return documents.api.save(updateDoc)
.then((updatedDoc) => {
dispatch(notify('Document updated', 'success'));
dispatch({ type: types.VIEWER_UPDATE_DOCUMENT, doc });
dispatch(formActions.reset('documentViewer.sidepanel.metadata'));
dispatch(actions.set('viewer/doc', updatedDoc));
dispatch(relationshipActions.reloadRelationships(updatedDoc.sharedId));
});
};
return dispatch => documents.api.save(updateDoc)
.then((updatedDoc) => {
dispatch(notify('Document updated', 'success'));
dispatch({ type: types.VIEWER_UPDATE_DOCUMENT, doc });
dispatch(formActions.reset('documentViewer.sidepanel.metadata'));
dispatch(actions.set('viewer/doc', updatedDoc));
dispatch(relationshipActions.reloadRelationships(updatedDoc.sharedId));
});
}

export function saveToc(toc) {
return function (dispatch, getState) {
return (dispatch, getState) => {
const { _id, _rev, sharedId, file } = getState().documentViewer.doc.toJS();
dispatch(formActions.reset('documentViewer.sidepanel.metadata'));
dispatch(actions.set('documentViewer/tocBeingEdited', false));
Expand All @@ -65,15 +63,13 @@ export function saveToc(toc) {
}

export function deleteDocument(doc) {
return function (dispatch) {
return documents.api.delete(doc)
.then(() => {
dispatch(notify('Document deleted', 'success'));
dispatch(resetDocumentViewer());
dispatch(removeDocument(doc));
dispatch(unselectAllDocuments());
});
};
return dispatch => documents.api.delete(doc)
.then(() => {
dispatch(notify('Document deleted', 'success'));
dispatch(resetDocumentViewer());
dispatch(removeDocument(doc));
dispatch(unselectAllDocuments());
});
}

export function getDocument(id) {
Expand All @@ -88,28 +84,26 @@ export function getDocument(id) {
}
return PDFUtils.extractPDFInfo(`${APIURL}documents/download?_id=${doc._id}`)
.then((pdfInfo) => {
doc.pdfInfo = pdfInfo;
return api.post('documents/pdfInfo', doc)
const { _id, sharedId } = doc;
return api.post('documents/pdfInfo', { _id, sharedId, pdfInfo })
.then(res => res.json);
});
});
}

export function loadTargetDocument(id) {
return function (dispatch) {
return Promise.all([
return dispatch => Promise.all([
getDocument(id),
referencesAPI.get(id)
])
.then(([targetDoc, references]) => {
dispatch(actions.set('viewer/targetDoc', targetDoc));
dispatch(actions.set('viewer/targetDocReferences', references));
});
};
])
.then(([targetDoc, references]) => {
dispatch(actions.set('viewer/targetDoc', targetDoc));
dispatch(actions.set('viewer/targetDocReferences', references));
});
}

export function cancelTargetDocument() {
return function (dispatch) {
return (dispatch) => {
dispatch({ type: connectionsTypes.CANCEL_RANGED_CONNECTION });
dispatch(actions.unset('viewer/targetDoc'));
dispatch(actions.unset('viewer/targetDocReferences'));
Expand All @@ -119,7 +113,7 @@ export function cancelTargetDocument() {
}

export function editToc(toc) {
return function (dispatch) {
return (dispatch) => {
dispatch(actions.set('documentViewer/tocBeingEdited', true));
dispatch(formActions.load('documentViewer.tocForm', toc));
dispatch(uiActions.openPanel('viewMetadataPanel'));
Expand All @@ -128,7 +122,7 @@ export function editToc(toc) {
}

export function removeFromToc(tocElement) {
return function (dispatch, getState) {
return (dispatch, getState) => {
const state = getState();
let toc = state.documentViewer.tocForm;

Expand All @@ -139,7 +133,7 @@ export function removeFromToc(tocElement) {
}

export function indentTocElement(tocElement, indentation) {
return function (dispatch, getState) {
return (dispatch, getState) => {
const state = getState();
const toc = state.documentViewer.tocForm.map((_entry) => {
const entry = Object.assign({}, _entry);
Expand All @@ -154,7 +148,7 @@ export function indentTocElement(tocElement, indentation) {
}

export function addToToc(textSelectedObject) {
return function (dispatch, getState) {
return (dispatch, getState) => {
const state = getState();
let toc = state.documentViewer.tocForm.concat();
if (!toc.length) {
Expand Down
Loading

0 comments on commit 1806169

Please sign in to comment.