Fix inconsistent display of word 'ago' on rules page (#8566)

* Fix inconsistent display of word 'ago' in last evaluation column on rules page

Signed-off-by: Alex Petrov <alex.petrov.vt@gmail.com>

* Extract adding word 'ago' to relativeDuration util function

Signed-off-by: Alex Petrov <alex.petrov.vt@gmail.com>
This commit is contained in:
alex-petrov-vt 2021-03-08 13:10:09 -05:00 committed by GitHub
parent 8d2a8f4939
commit 4f03df8c55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View file

@ -65,7 +65,7 @@ export const RulesContent: FC<RouteComponentProps & RulesContentProps> = ({ resp
</a>
</td>
<td>
<h2>{formatRelative(g.lastEvaluation, now())} ago</h2>
<h2>{formatRelative(g.lastEvaluation, now())}</h2>
</td>
<td>
<h2>{humanizeDuration(parseFloat(g.evaluationTime) * 1000)}</h2>
@ -120,7 +120,7 @@ export const RulesContent: FC<RouteComponentProps & RulesContentProps> = ({ resp
<Badge color={getBadgeColor(r.health)}>{r.health.toUpperCase()}</Badge>
</td>
<td>{r.lastError ? <Alert color="danger">{r.lastError}</Alert> : null}</td>
<td>{formatRelative(r.lastEvaluation, now())} ago</td>
<td>{formatRelative(r.lastEvaluation, now())}</td>
<td>{humanizeDuration(parseFloat(r.evaluationTime) * 1000)}</td>
</tr>
);

View file

@ -155,7 +155,7 @@ export const formatRelative = (startStr: string, end: number): string => {
if (start < 0) {
return 'Never';
}
return humanizeDuration(end - start);
return humanizeDuration(end - start) + ' ago';
};
const paramFormat = /^g\d+\..+=.+$/;

View file

@ -192,10 +192,10 @@ describe('Utils', () => {
});
it('renders a humanized duration for sane durations', () => {
expect(formatRelative('2019-11-04T09:15:29.578701-07:00', parseTime('2019-11-04T09:15:35.8701-07:00'))).toEqual(
'6.292s'
'6.292s ago'
);
expect(formatRelative('2019-11-04T09:15:35.8701-07:00', parseTime('2019-11-04T09:15:29.578701-07:00'))).toEqual(
'-6.292s'
'-6.292s ago'
);
});
});