Skip to content

Commit

Permalink
getDocument returns relations.
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Mar 30, 2021
1 parent 953b4c8 commit 213afc6
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 32 deletions.
13 changes: 5 additions & 8 deletions app/react/Documents/components/DocumentSidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ export class DocumentSidePanel extends Component {

const TocForm = this.props.tocFormComponent;

const { attachments, documents, language, defaultDoc } = doc.toJS();
const jsDoc = doc.delete('relations').toJS();
const { attachments, documents, language, defaultDoc } = jsDoc;

const isEntity = !documents || !documents.length;
const defaultDocumentToC =
Expand Down Expand Up @@ -404,16 +405,12 @@ export class DocumentSidePanel extends Component {
<div>
<ShowMetadata
relationships={relationships}
entity={this.props.doc.toJS()}
entity={jsDoc}
showTitle
showType
groupGeolocations
/>
<FileList
files={documents}
storeKey={this.props.storeKey}
entity={doc.toJS()}
/>
<FileList files={documents} storeKey={this.props.storeKey} entity={jsDoc} />
<AttachmentsList
attachments={attachments}
isTargetDoc={isTargetDoc}
Expand All @@ -437,7 +434,7 @@ export class DocumentSidePanel extends Component {
<ConnectionsGroups />
</TabContent>
<TabContent for="semantic-search-results">
<DocumentSemanticSearchResults doc={this.props.doc.toJS()} />
<DocumentSemanticSearchResults doc={jsDoc} />
</TabContent>
</Tabs>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/react/Layout/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Item extends Component {
buttons,
} = this.props;

const doc = this.props.doc.toJS();
const doc = this.props.doc.delete('relations').toJS();
const Snippet = additionalText ? (
<div className="item-snippet-wrapper">
<div className="item-snippet">{additionalText}</div>
Expand Down
2 changes: 1 addition & 1 deletion app/react/Library/components/Doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Doc extends Component {

render() {
const { className, additionalText, targetReference } = this.props;
const doc = this.props.doc.toJS();
const doc = this.props.doc.delete('relations').toJS();
const { sharedId, file, processed } = doc;

let itemConnections = null;
Expand Down
10 changes: 1 addition & 9 deletions app/react/Viewer/PDFView.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,7 @@ class PDFView extends Component {
const { ref } = this.props.location.query;
if (ref) {
const reference = doc.get('relations').find(r => r.get('_id') === ref);
this.context.store.dispatch(
activateReference(
reference.toJS(),
doc
.get('defaultDoc')
.get('pdfInfo')
.toJS()
)
);
this.context.store.dispatch(activateReference(reference.toJS()));
}
}

Expand Down
4 changes: 1 addition & 3 deletions app/react/Viewer/actions/documentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ function getEntityDoc(entity, filename, defaultLanguage) {
}

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

entity.defaultDoc = getEntityDoc(entity, filename, defaultLanguage);
return entity;
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 @@ -206,12 +206,12 @@ describe('documentActions', () => {
.get(`${APIURL}documents/search?searchTerm=term&fields=%5B%22field%22%5D`, {
body: JSON.stringify('documents'),
})
.get(`${APIURL}entities?sharedId=targetId&omitRelationships=true`, {
.get(`${APIURL}entities?sharedId=targetId`, {
body: JSON.stringify({
rows: [{ documents: [{ pdfInfo: 'test' }] }],
}),
})
.get(`${APIURL}entities?sharedId=docCalledWithWrongPDFFilename&omitRelationships=true`, {
.get(`${APIURL}entities?sharedId=docCalledWithWrongPDFFilename`, {
body: JSON.stringify({
rows: [
{
Expand All @@ -228,12 +228,12 @@ describe('documentActions', () => {
],
}),
})
.get(`${APIURL}entities?sharedId=docWithPDFRdy&omitRelationships=true`, {
.get(`${APIURL}entities?sharedId=docWithPDFRdy`, {
body: JSON.stringify({
rows: [{ documents: [{ pdfInfo: 'processed pdf', _id: 'pdfReady' }] }],
}),
})
.get(`${APIURL}entities?sharedId=docWithPDFNotRdy&omitRelationships=true`, {
.get(`${APIURL}entities?sharedId=docWithPDFNotRdy`, {
body: JSON.stringify({
rows: [
{
Expand Down
3 changes: 2 additions & 1 deletion app/react/Viewer/components/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { createSelector } from 'reselect';
const selectDoc = createSelector(
s => s.documentViewer.targetDoc,
s => s.documentViewer.doc,
(targetDoc, doc) => (targetDoc.get('_id') ? targetDoc.toJS() : doc.toJS())
(targetDoc, doc) =>
targetDoc.get('_id') ? targetDoc.delete('relations').toJS() : doc.delete('relations').toJS()
);

export class Connection extends Component {
Expand Down
7 changes: 5 additions & 2 deletions app/react/Viewer/components/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ export class Document extends Component {
}

render() {
const doc = this.props.doc.toJS();
const { file } = this.props;

const Header = this.props.header;
return (
<div>
<div className={`_${doc._id} document ${this.props.className} ${determineDirection(file)}`}>
<div
className={`_${this.props.doc.get('_id')} document ${
this.props.className
} ${determineDirection(file)}`}
>
<Header />
<div
className="pages"
Expand Down
5 changes: 2 additions & 3 deletions app/react/Viewer/specs/PDFView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,14 @@ describe('PDFView', () => {
it('should activate text reference if query parameters have reference id', () => {
spyOn(uiActions, 'activateReference');
props.location = { query: { raw: 'false', ref: 'refId' }, pathname: 'pathname' };
const pdfInfo = { 1: { chars: 100 } };
const reference = { _id: 'refId', range: { start: 200, end: 300 }, text: 'test' };
const doc = fromJS({
defaultDoc: { pdfInfo },
defaultDoc: {},
relations: [{ _id: 'otherRef' }, reference],
});
render();
instance.onDocumentReady(doc);
expect(uiActions.activateReference).toHaveBeenCalledWith(reference, pdfInfo);
expect(uiActions.activateReference).toHaveBeenCalledWith(reference);
});

it('should emit documentLoaded event', () => {
Expand Down

0 comments on commit 213afc6

Please sign in to comment.