* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
import * as React from 'react';
import { translate, translateWithParameters } from '../../../helpers/l10n';
import { formatMeasure } from '../../../helpers/measures';
diff: TypeIssueChangelogDiff;
}
-export default function IssueChangelogDiff({ diff }: IssueChangelogDiffProps) {
+export default function IssueChangelogDiff(props: IssueChangelogDiffProps) {
+ const { diff } = props;
+
+ const diffComputedValues = {
+ newValue: diff.newValue ?? '',
+ oldValue: diff.oldValue ?? '',
+ };
+
if (diff.key === 'file') {
return (
<p>
{translateWithParameters(
'issue.change.file_move',
- diff.oldValue ?? '',
- diff.newValue ?? '',
+ diffComputedValues.oldValue,
+ diffComputedValues.newValue,
)}
</p>
);
- } else if (['from_long_branch', 'from_branch'].includes(diff.key)) {
+ }
+
+ if (['from_long_branch', 'from_branch'].includes(diff.key)) {
return (
<p>
{translateWithParameters(
'issue.change.from_branch',
- diff.oldValue ?? '',
- diff.newValue ?? '',
+ diffComputedValues.oldValue,
+ diffComputedValues.newValue,
)}
</p>
);
- } else if (diff.key === 'from_short_branch') {
+ }
+
+ if (diff.key === 'from_short_branch') {
// Applies to both legacy short lived branch and pull request
return (
<p>
{translateWithParameters(
'issue.change.from_non_branch',
- diff.oldValue ?? '',
- diff.newValue ?? '',
+ diffComputedValues.oldValue,
+ diffComputedValues.newValue,
)}
</p>
);
- } else if (diff.key === 'line') {
- return <p>{translateWithParameters('issue.changelog.line_removed_X', diff.oldValue ?? '')}</p>;
}
- let message;
- if (diff.newValue != null) {
- let { newValue } = diff;
- if (diff.key === 'effort') {
- newValue = formatMeasure(diff.newValue, 'WORK_DUR');
- }
- message = translateWithParameters(
- 'issue.changelog.changed_to',
- translate('issue.changelog.field', diff.key),
- newValue,
- );
- } else {
- message = translateWithParameters(
- 'issue.changelog.removed',
- translate('issue.changelog.field', diff.key),
+ if (diff.key === 'line') {
+ return (
+ <p>
+ {translateWithParameters('issue.changelog.line_removed_X', diffComputedValues.oldValue)}
+ </p>
);
}
- if (diff.oldValue != null) {
- let { oldValue } = diff;
- if (diff.key === 'effort') {
- oldValue = formatMeasure(diff.oldValue, 'WORK_DUR');
- }
- message += ` (${translateWithParameters('issue.changelog.was', oldValue)})`;
+ if (diff.key === 'effort') {
+ diffComputedValues.newValue = formatMeasure(diff.newValue, 'WORK_DUR');
+ diffComputedValues.oldValue = formatMeasure(diff.oldValue, 'WORK_DUR');
}
+
+ let message =
+ diff.newValue !== undefined
+ ? translateWithParameters(
+ 'issue.changelog.changed_to',
+ translate('issue.changelog.field', diff.key),
+ diffComputedValues.newValue,
+ )
+ : translateWithParameters(
+ 'issue.changelog.removed',
+ translate('issue.changelog.field', diff.key),
+ );
+
+ if (diff.oldValue !== undefined) {
+ message += ` (${translateWithParameters('issue.changelog.was', diffComputedValues.oldValue)})`;
+ }
+
return <p>{message}</p>;
}