Skip to content

Commit

Permalink
Show the correct review time in tooltip (#3270)
Browse files Browse the repository at this point in the history
Also: unify datetime formats between tooltips.
  • Loading branch information
harmitgoswami committed Jul 3, 2024
1 parent 4fd99f4 commit 86041d9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pontoon/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,11 @@ def get_translation_history(request):
"uid": u.id,
"username": u.username,
"user_gravatar_url_small": u.gravatar_url(88),
"date": t.date.strftime("%b %d, %Y %H:%M"),
"date_iso": t.date.isoformat(),
"date": t.date,
"approved_user": User.display_name_or_blank(t.approved_user),
"approved_date": t.approved_date,
"rejected_user": User.display_name_or_blank(t.rejected_user),
"rejected_date": t.rejected_date,
"comments": [c.serialize() for c in t.comments.order_by("timestamp")],
"machinery_sources": t.machinery_sources_values,
}
Expand Down
3 changes: 2 additions & 1 deletion translate/src/api/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export type EntityTranslation = {
export type HistoryTranslation = {
readonly approved: boolean;
readonly approvedUser: string;
readonly approvedDate: string | null;
readonly pretranslated: boolean;
readonly date: string;
readonly dateIso: string;
readonly fuzzy: boolean;
readonly pk: number;
readonly rejected: boolean;
readonly rejectedDate: string | null;
readonly string: string;
readonly uid: number | null | undefined;
readonly rejectedUser: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('<HistoryTranslationComponent>', () => {
approvedUser: '',
pretranslated: false,
date: '',
dateIso: '',
fuzzy: false,
pk: 1,
rejected: false,
Expand Down
19 changes: 16 additions & 3 deletions translate/src/modules/history/components/HistoryTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,23 @@ export function HistoryTranslationBase({

const review = {
id: 'history-translation--unreviewed',
vars: { user: '', reviewedDate: new Date(translation.dateIso) },
vars: { user: '', reviewedDate: new Date() },
attrs: { title: true },
};
if (translation.approved) {
if (translation.approvedDate) {
review.vars.reviewedDate = new Date(translation.approvedDate);
}
if (translation.approvedUser) {
review.vars.user = translation.approvedUser;
review.id = 'history-translation--approved';
} else {
review.id = 'history-translation--approved-anonymous';
}
} else if (translation.rejected) {
if (translation.rejectedDate) {
review.vars.reviewedDate = new Date(translation.rejectedDate);
}
if (translation.rejectedUser) {
review.vars.user = translation.rejectedUser;
review.id = 'history-translation--rejected';
Expand All @@ -227,6 +233,13 @@ export function HistoryTranslationBase({
!isReadOnlyEditor;
let canComment = user.isAuthenticated;

const customDateFormat = (date: Date) => {
return new Intl.DateTimeFormat('en', {
dateStyle: 'long',
timeStyle: 'medium',
}).format(date);
};

const className = classNames(
'translation',
translation.approved
Expand Down Expand Up @@ -282,8 +295,8 @@ export function HistoryTranslationBase({
</Localized>
<ReactTimeAgo
dir='ltr'
date={new Date(translation.dateIso)}
title={`${translation.date} UTC`}
date={new Date(translation.date)}
formatVerboseDate={customDateFormat}
/>
</div>
<menu className='toolbar'>
Expand Down

0 comments on commit 86041d9

Please sign in to comment.