Skip to content

Commit

Permalink
Merge pull request #3572 from huridocs/3499_error_ref_scroll
Browse files Browse the repository at this point in the history
getDocument returns relations.
  • Loading branch information
RafaPolit authored Apr 5, 2021
2 parents 953b4c8 + 238249b commit ac7220d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
14 changes: 6 additions & 8 deletions app/react/Documents/components/DocumentSidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { entityDefaultDocument } from 'shared/entityDefaultDocument';
import SearchText from './SearchText';
import ShowToc from './ShowToc';
import SnippetsTab from './SnippetsTab';
import helpers from '../helpers';

export class DocumentSidePanel extends Component {
constructor(props) {
Expand Down Expand Up @@ -271,7 +272,8 @@ export class DocumentSidePanel extends Component {

const TocForm = this.props.tocFormComponent;

const { attachments, documents, language, defaultDoc } = doc.toJS();
const jsDoc = helpers.performantDocToJSWithoutRelations(doc);
const { attachments, documents, language, defaultDoc } = jsDoc;

const isEntity = !documents || !documents.length;
const defaultDocumentToC =
Expand Down Expand Up @@ -404,16 +406,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 +435,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
4 changes: 4 additions & 0 deletions app/react/Documents/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import moment from 'moment';

export default {
performantDocToJSWithoutRelations(doc) {
return doc.delete('relations').toJS();
},

prepareMetadata(doc, templates, thesauris) {
const template = templates.find(t => t._id === doc.template);

Expand Down
3 changes: 2 additions & 1 deletion app/react/Layout/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import prioritySortingCriteria from 'app/utils/prioritySortingCriteria';

import { FeatureToggle } from 'app/components/Elements/FeatureToggle';
import { FavoriteBanner } from 'app/Favorites';
import helpers from 'app/Documents/helpers';

import { RowList, ItemFooter } from './Lists';
import DocumentLanguage from './DocumentLanguage';
Expand Down Expand Up @@ -36,7 +37,7 @@ export class Item extends Component {
buttons,
} = this.props;

const doc = this.props.doc.toJS();
const doc = helpers.performantDocToJSWithoutRelations(this.props.doc);
const Snippet = additionalText ? (
<div className="item-snippet-wrapper">
<div className="item-snippet">{additionalText}</div>
Expand Down
3 changes: 2 additions & 1 deletion app/react/Library/components/Doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Icon } from 'UI';

import { Item } from 'app/Layout';
import { is, Map } from 'immutable';
import helpers from 'app/Documents/helpers';

export class Doc extends Component {
shouldComponentUpdate(nextProps) {
Expand Down Expand Up @@ -67,7 +68,7 @@ export class Doc extends Component {

render() {
const { className, additionalText, targetReference } = this.props;
const doc = this.props.doc.toJS();
const doc = helpers.performantDocToJSWithoutRelations(this.props.doc);
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
5 changes: 4 additions & 1 deletion app/react/Viewer/actions/routeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export async function requestViewerState(requestParams, globalResources) {
return [
setViewerState({
documentViewer: {
doc,
doc: {
...doc,
relations: references,
},
references,
relationTypes,
rawText,
Expand Down
2 changes: 1 addition & 1 deletion app/react/Viewer/actions/specs/documentActions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe('documentActions', () => {
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
6 changes: 5 additions & 1 deletion app/react/Viewer/components/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ import {
} from 'app/Viewer/actions/uiActions';
import { Item } from 'app/Layout';
import { createSelector } from 'reselect';
import helpers from 'app/Documents/helpers';

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')
? helpers.performantDocToJSWithoutRelations(targetDoc)
: helpers.performantDocToJSWithoutRelations(doc)
);

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
4 changes: 1 addition & 3 deletions app/react/Viewer/specs/PDFView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,13 @@ 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 },
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 ac7220d

Please sign in to comment.