Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Nov 11, 2020
2 parents ba7453d + fc8c7de commit a7d6e4e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 20 deletions.
34 changes: 24 additions & 10 deletions app/api/relationships/relationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,33 @@ export default {
return model.getById(id);
},

async getDocumentHubs(entity, file) {
const ownRelations = await model.get({
entity,
$or: [
{ $and: [{ file: { $exists: false } }] },
file ? { $and: [{ file: { $exists: true } }, { file }] } : {},
],
});
async getDocumentHubs(entity, file, onlyTextReferences) {
let ownRelations;
if (onlyTextReferences) {
ownRelations = await model.get(
{
entity,
$and: [{ file: { $exists: true } }, { file }],
},
{},
{ limit: 300 }
);
} else {
ownRelations = await model.get({
entity,
$or: [
{ $and: [{ file: { $exists: false } }] },
file ? { $and: [{ file: { $exists: true } }, { file }] } : {},
],
});
}

const hubsIds = ownRelations.map(relationship => relationship.hub);
return model.get({ hub: { $in: hubsIds } });
},

getByDocument(sharedId, language, unpublished = true, file) {
return this.getDocumentHubs(sharedId, file).then(_relationships => {
getByDocument(sharedId, language, unpublished = true, file, onlyTextReferences = false) {
return this.getDocumentHubs(sharedId, file, onlyTextReferences).then(_relationships => {
const connectedEntitiesSharedId = _relationships.map(relationship => relationship.entity);
return entities
.get({ sharedId: { $in: connectedEntitiesSharedId }, language }, [
Expand All @@ -192,6 +205,7 @@ export default {
res[doc.sharedId] = doc;
return res;
}, {});

let relationshipsCollection = new RelationshipCollection(..._relationships)
.removeOtherLanguageTextReferences(connectedDocuments)
.withConnectedData(connectedDocuments)
Expand Down
9 changes: 8 additions & 1 deletion app/api/relationships/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,21 @@ export default app => {
.keys({
sharedId: Joi.string().required(),
file: Joi.string(),
onlyTextReferences: Joi.string(),
})
.required(),
'query'
),
(req, res, next) => {
const unpublished = Boolean(req.user && ['admin', 'editor'].includes(req.user.role));
relationships
.getByDocument(req.query.sharedId, req.language, unpublished, req.query.file)
.getByDocument(
req.query.sharedId,
req.language,
unpublished,
req.query.file,
req.query.onlyTextReferences
)
.then(response => res.json(response))
.catch(next);
}
Expand Down
8 changes: 7 additions & 1 deletion app/api/relationships/specs/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ describe('relationships routes', () => {
spyOn(relationships, 'getByDocument').and.returnValue(Promise.resolve('byDocument'));

const response = await routes.get('/api/references/by_document/', req);
expect(relationships.getByDocument).toHaveBeenCalledWith('documentId', 'es', true, 'fileid');
expect(relationships.getByDocument).toHaveBeenCalledWith(
'documentId',
'es',
true,
'fileid',
undefined
);
expect(response).toBe('byDocument');
});
});
Expand Down
4 changes: 3 additions & 1 deletion app/react/Viewer/ViewerRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { setReferences } from './actions/referencesActions';
class ViewerRoute extends RouteHandler {
static async requestState(requestParams, globalResources) {
const { sharedId } = requestParams.data;
const [entity] = await EntitiesAPI.get(requestParams.set({ sharedId }));
const [entity] = await EntitiesAPI.get(
requestParams.set({ sharedId, omitRelationships: true })
);

return entity.documents.length
? PDFView.requestState(requestParams, globalResources)
Expand Down
4 changes: 3 additions & 1 deletion app/react/Viewer/actions/documentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ function getEntityDoc(entity, filename, defaultLanguage) {
}

export async function getDocument(requestParams, defaultLanguage, filename) {
const [entity] = (await api.get('entities', requestParams)).json.rows;
const [entity] = (
await api.get('entities', requestParams.add({ omitRelationships: true }))
).json.rows;

entity.defaultDoc = getEntityDoc(entity, filename, defaultLanguage);
if (!isClient) return entity;
Expand Down
2 changes: 1 addition & 1 deletion app/react/Viewer/actions/routeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function requestViewerState(requestParams, globalResources) {
: '';

const references = await referencesAPI.get(
requestParams.set({ sharedId, file: doc.defaultDoc._id })
requestParams.set({ sharedId, file: doc.defaultDoc._id, onlyTextReferences: true })
);

return [
Expand Down
8 changes: 4 additions & 4 deletions app/react/Viewer/actions/specs/documentActions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ describe('documentActions', () => {
.get(`${APIURL}documents/search?searchTerm=term&fields=%5B%22field%22%5D`, {
body: JSON.stringify('documents'),
})
.get(`${APIURL}entities?sharedId=targetId`, {
.get(`${APIURL}entities?sharedId=targetId&omitRelationships=true`, {
body: JSON.stringify({
rows: [{ documents: [{ pdfInfo: 'test' }] }],
}),
})
.get(`${APIURL}entities?sharedId=docCalledWithWrongPDFFilename`, {
.get(`${APIURL}entities?sharedId=docCalledWithWrongPDFFilename&omitRelationships=true`, {
body: JSON.stringify({
rows: [
{
Expand All @@ -206,12 +206,12 @@ describe('documentActions', () => {
],
}),
})
.get(`${APIURL}entities?sharedId=docWithPDFRdy`, {
.get(`${APIURL}entities?sharedId=docWithPDFRdy&omitRelationships=true`, {
body: JSON.stringify({
rows: [{ documents: [{ pdfInfo: 'processed pdf', _id: 'pdfReady' }] }],
}),
})
.get(`${APIURL}entities?sharedId=docWithPDFNotRdy`, {
.get(`${APIURL}entities?sharedId=docWithPDFNotRdy&omitRelationships=true`, {
body: JSON.stringify({
rows: [
{
Expand Down
8 changes: 7 additions & 1 deletion app/react/Viewer/components/ConnectionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { t } from 'app/I18N';
import { Icon } from 'UI';

import { Warning } from 'app/Layout';
import { closePanel, deactivateReference } from 'app/Viewer/actions/uiActions';
import Connection from './Connection';

Expand Down Expand Up @@ -47,6 +47,12 @@ export class ConnectionsList extends Component {

return (
<div className="item-group">
{references.length > 299 && (
<Warning inline>
Text references are temporarily limited to a maximum of 300. We are currently working on
a fix for this issue.
</Warning>
)}
{(() =>
references.map(reference => (
<Connection key={reference._id} readOnly={this.props.readOnly} reference={reference} />
Expand Down
1 change: 1 addition & 0 deletions app/react/Viewer/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const selectTargetDoc = createSelector(
s => documentViewer(s).targetDoc,
doc => doc
);

const selectTargetRefs = createSelector(
s => documentViewer(s).targetDocReferences,
references => references
Expand Down

0 comments on commit a7d6e4e

Please sign in to comment.