|
@@ -3,9 +3,6 @@ import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
-import PageHistroyContainer from '~/client/services/PageHistoryContainer';
|
|
|
|
|
-import RevisionComparerContainer from '~/client/services/RevisionComparerContainer';
|
|
|
|
|
-
|
|
|
|
|
import Revision from './Revision';
|
|
import Revision from './Revision';
|
|
|
|
|
|
|
|
class PageRevisionTable extends React.Component {
|
|
class PageRevisionTable extends React.Component {
|
|
@@ -17,21 +14,20 @@ class PageRevisionTable extends React.Component {
|
|
|
* @param {boolean} hasDiff whether revision has difference to previousRevision
|
|
* @param {boolean} hasDiff whether revision has difference to previousRevision
|
|
|
* @param {boolean} isContiguousNodiff true if the current 'hasDiff' and one of previous row is both false
|
|
* @param {boolean} isContiguousNodiff true if the current 'hasDiff' and one of previous row is both false
|
|
|
*/
|
|
*/
|
|
|
- renderRow(revision, previousRevision, hasDiff, isContiguousNodiff) {
|
|
|
|
|
- const { revisionComparerContainer, t } = this.props;
|
|
|
|
|
- const { latestRevision, oldestRevision } = this.props.pageHistoryContainer.state;
|
|
|
|
|
|
|
+ renderRow(revision, previousRevision, latestRevision, isOldestRevision, hasDiff) {
|
|
|
|
|
+ const {
|
|
|
|
|
+ t, sourceRevision, targetRevision, onChangeSourceInvoked, onChangeTargetInvoked,
|
|
|
|
|
+ } = this.props;
|
|
|
const revisionId = revision._id;
|
|
const revisionId = revision._id;
|
|
|
- const revisionDiffOpened = this.props.diffOpened[revisionId] || false;
|
|
|
|
|
- const { sourceRevision, targetRevision } = revisionComparerContainer.state;
|
|
|
|
|
|
|
|
|
|
const handleCompareLatestRevisionButton = () => {
|
|
const handleCompareLatestRevisionButton = () => {
|
|
|
- revisionComparerContainer.setState({ sourceRevision: revision });
|
|
|
|
|
- revisionComparerContainer.setState({ targetRevision: latestRevision });
|
|
|
|
|
|
|
+ onChangeSourceInvoked(revision);
|
|
|
|
|
+ onChangeTargetInvoked(latestRevision);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleComparePreviousRevisionButton = () => {
|
|
const handleComparePreviousRevisionButton = () => {
|
|
|
- revisionComparerContainer.setState({ sourceRevision: previousRevision });
|
|
|
|
|
- revisionComparerContainer.setState({ targetRevision: revision });
|
|
|
|
|
|
|
+ onChangeSourceInvoked(previousRevision);
|
|
|
|
|
+ onChangeTargetInvoked(revision);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -42,7 +38,6 @@ class PageRevisionTable extends React.Component {
|
|
|
t={this.props.t}
|
|
t={this.props.t}
|
|
|
revision={revision}
|
|
revision={revision}
|
|
|
isLatestRevision={revision === latestRevision}
|
|
isLatestRevision={revision === latestRevision}
|
|
|
- revisionDiffOpened={revisionDiffOpened}
|
|
|
|
|
hasDiff={hasDiff}
|
|
hasDiff={hasDiff}
|
|
|
key={`revision-history-rev-${revisionId}`}
|
|
key={`revision-history-rev-${revisionId}`}
|
|
|
/>
|
|
/>
|
|
@@ -60,7 +55,7 @@ class PageRevisionTable extends React.Component {
|
|
|
type="button"
|
|
type="button"
|
|
|
className="btn btn-outline-secondary btn-sm"
|
|
className="btn btn-outline-secondary btn-sm"
|
|
|
onClick={handleComparePreviousRevisionButton}
|
|
onClick={handleComparePreviousRevisionButton}
|
|
|
- disabled={revision === oldestRevision}
|
|
|
|
|
|
|
+ disabled={isOldestRevision}
|
|
|
>
|
|
>
|
|
|
{t('page_history.compare_previous')}
|
|
{t('page_history.compare_previous')}
|
|
|
</button>
|
|
</button>
|
|
@@ -70,34 +65,34 @@ class PageRevisionTable extends React.Component {
|
|
|
</div>
|
|
</div>
|
|
|
</td>
|
|
</td>
|
|
|
<td className="col-1">
|
|
<td className="col-1">
|
|
|
- {(hasDiff || revision._id === sourceRevision?._id) && (
|
|
|
|
|
|
|
+ {(hasDiff || revisionId === sourceRevision?._id) && (
|
|
|
<div className="custom-control custom-radio custom-control-inline mr-0">
|
|
<div className="custom-control custom-radio custom-control-inline mr-0">
|
|
|
<input
|
|
<input
|
|
|
type="radio"
|
|
type="radio"
|
|
|
className="custom-control-input"
|
|
className="custom-control-input"
|
|
|
- id={`compareSource-${revision._id}`}
|
|
|
|
|
|
|
+ id={`compareSource-${revisionId}`}
|
|
|
name="compareSource"
|
|
name="compareSource"
|
|
|
- value={revision._id}
|
|
|
|
|
- checked={revision._id === sourceRevision?._id}
|
|
|
|
|
- onChange={() => revisionComparerContainer.setState({ sourceRevision: revision })}
|
|
|
|
|
|
|
+ value={revisionId}
|
|
|
|
|
+ checked={revisionId === sourceRevision?._id}
|
|
|
|
|
+ onChange={() => onChangeSourceInvoked(revision)}
|
|
|
/>
|
|
/>
|
|
|
- <label className="custom-control-label" htmlFor={`compareSource-${revision._id}`} />
|
|
|
|
|
|
|
+ <label className="custom-control-label" htmlFor={`compareSource-${revisionId}`} />
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
</td>
|
|
</td>
|
|
|
<td className="col-2">
|
|
<td className="col-2">
|
|
|
- {(hasDiff || revision._id === targetRevision?._id) && (
|
|
|
|
|
|
|
+ {(hasDiff || revisionId === targetRevision?._id) && (
|
|
|
<div className="custom-control custom-radio custom-control-inline mr-0">
|
|
<div className="custom-control custom-radio custom-control-inline mr-0">
|
|
|
<input
|
|
<input
|
|
|
type="radio"
|
|
type="radio"
|
|
|
className="custom-control-input"
|
|
className="custom-control-input"
|
|
|
- id={`compareTarget-${revision._id}`}
|
|
|
|
|
|
|
+ id={`compareTarget-${revisionId}`}
|
|
|
name="compareTarget"
|
|
name="compareTarget"
|
|
|
- value={revision._id}
|
|
|
|
|
- checked={revision._id === targetRevision?._id}
|
|
|
|
|
- onChange={() => revisionComparerContainer.setState({ targetRevision: revision })}
|
|
|
|
|
|
|
+ value={revisionId}
|
|
|
|
|
+ checked={revisionId === targetRevision?._id}
|
|
|
|
|
+ onChange={() => onChangeTargetInvoked(revision)}
|
|
|
/>
|
|
/>
|
|
|
- <label className="custom-control-label" htmlFor={`compareTarget-${revision._id}`} />
|
|
|
|
|
|
|
+ <label className="custom-control-label" htmlFor={`compareTarget-${revisionId}`} />
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
</td>
|
|
</td>
|
|
@@ -106,16 +101,18 @@ class PageRevisionTable extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { t, pageHistoryContainer } = this.props;
|
|
|
|
|
|
|
+ const { t, pagingLimit } = this.props;
|
|
|
|
|
|
|
|
const revisions = this.props.revisions;
|
|
const revisions = this.props.revisions;
|
|
|
const revisionCount = this.props.revisions.length;
|
|
const revisionCount = this.props.revisions.length;
|
|
|
|
|
+ const latestRevision = revisions[0];
|
|
|
|
|
+ const oldestRevision = revisions[revisions.length - 1];
|
|
|
|
|
|
|
|
let hasDiffPrev;
|
|
let hasDiffPrev;
|
|
|
|
|
|
|
|
const revisionList = this.props.revisions.map((revision, idx) => {
|
|
const revisionList = this.props.revisions.map((revision, idx) => {
|
|
|
// Returns null because the last revision is for the bottom diff display
|
|
// Returns null because the last revision is for the bottom diff display
|
|
|
- if (idx === pageHistoryContainer.state.pagingLimit) {
|
|
|
|
|
|
|
+ if (idx === pagingLimit) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -127,13 +124,13 @@ class PageRevisionTable extends React.Component {
|
|
|
previousRevision = revision; // if it is the first revision, show full text as diff text
|
|
previousRevision = revision; // if it is the first revision, show full text as diff text
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const isOldestRevision = revision === oldestRevision;
|
|
|
|
|
|
|
|
const hasDiff = revision.hasDiffToPrev !== false; // set 'true' if undefined for backward compatibility
|
|
const hasDiff = revision.hasDiffToPrev !== false; // set 'true' if undefined for backward compatibility
|
|
|
- const isContiguousNodiff = !hasDiff && !hasDiffPrev;
|
|
|
|
|
|
|
|
|
|
hasDiffPrev = hasDiff;
|
|
hasDiffPrev = hasDiff;
|
|
|
|
|
|
|
|
- return this.renderRow(revision, previousRevision, hasDiff, isContiguousNodiff);
|
|
|
|
|
|
|
+ return this.renderRow(revision, previousRevision, latestRevision, isOldestRevision, hasDiff);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -156,11 +153,13 @@ class PageRevisionTable extends React.Component {
|
|
|
|
|
|
|
|
PageRevisionTable.propTypes = {
|
|
PageRevisionTable.propTypes = {
|
|
|
t: PropTypes.func.isRequired, // i18next
|
|
t: PropTypes.func.isRequired, // i18next
|
|
|
- pageHistoryContainer: PropTypes.instanceOf(PageHistroyContainer).isRequired,
|
|
|
|
|
- revisionComparerContainer: PropTypes.instanceOf(RevisionComparerContainer).isRequired,
|
|
|
|
|
|
|
|
|
|
revisions: PropTypes.array,
|
|
revisions: PropTypes.array,
|
|
|
- diffOpened: PropTypes.object,
|
|
|
|
|
|
|
+ pagingLimit: PropTypes.number,
|
|
|
|
|
+ sourceRevision: PropTypes.instanceOf(Object),
|
|
|
|
|
+ targetRevision: PropTypes.instanceOf(Object),
|
|
|
|
|
+ onChangeSourceInvoked: PropTypes.func.isRequired,
|
|
|
|
|
+ onChangeTargetInvoked: PropTypes.func.isRequired,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const PageRevisionTableWrapperFC = (props) => {
|
|
const PageRevisionTableWrapperFC = (props) => {
|