Skip to content

Commit

Permalink
fix(translations): fix localisation of relative time strings (apache#…
Browse files Browse the repository at this point in the history
…28331)

 Fixes: table views, dashboard card and chart editor header
  • Loading branch information
lscheibel committed May 10, 2024
1 parent 7da6147 commit b125f37
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 56 deletions.
9 changes: 7 additions & 2 deletions superset-frontend/src/components/AuditInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Owner from 'src/types/Owner';
import { Tooltip } from 'src/components/Tooltip';
import getOwnerName from 'src/utils/getOwnerName';
import { t } from '@superset-ui/core';
import moment from 'moment';

export type ModifiedInfoProps = {
user?: Owner;
Expand All @@ -30,8 +31,12 @@ export type ModifiedInfoProps = {

export const ModifiedInfo = ({ user, date }: ModifiedInfoProps) => {
const dateSpan = (
<span className="no-wrap" data-test="audit-info-date">
{date}
<span
className="no-wrap"
data-test="audit-info-date"
title={moment.utc(date).local().format('LLL')}
>
{moment.utc(date).fromNow()}
</span>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import React from 'react';
import { ensureIsArray, styled, t } from '@superset-ui/core';
import Icons from 'src/components/Icons';
import moment from 'moment';
import { ContentType, MetadataType } from '.';

const Header = styled.div`
Expand Down Expand Up @@ -74,10 +75,13 @@ const config = (contentType: ContentType) => {
case MetadataType.LastModified:
return {
icon: Icons.EditOutlined,
title: contentType.value,
title: moment.utc(contentType.value).fromNow(),
tooltip: (
<div>
<Info header={t('Last modified')} text={contentType.value} />
<Info
header={t('Last modified')}
text={moment.utc(contentType.value).local().format('LLL')}
/>
<Info header={t('Modified by')} text={contentType.modifiedBy} />
</div>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const ExploreChartHeader = ({
});
items.push({
type: MetadataType.LastModified,
value: metadata.changed_on_humanized,
value: metadata.changed_on_utc,
modifiedBy: metadata.changed_by || t('Not available'),
});
items.push({
Expand Down
6 changes: 5 additions & 1 deletion superset-frontend/src/features/dashboards/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Label from 'src/components/Label';
import FacePile from 'src/components/FacePile';
import FaveStar from 'src/components/FaveStar';
import { Dashboard } from 'src/views/CRUD/types';
import moment from 'moment';

interface DashboardCardProps {
isChart?: boolean;
Expand Down Expand Up @@ -130,7 +131,10 @@ function DashboardCard({
linkComponent={Link}
imgURL={dashboard.thumbnail_url}
imgFallbackURL="/static/assets/images/dashboard-card-fallback.svg"
description={t('Modified %s', dashboard.changed_on_delta_humanized)}
description={t(
'Modified %s',
moment.utc(dashboard.changed_on_utc).fromNow(),
)}
coverLeft={<FacePile users={dashboard.owners || []} />}
actions={
<ListViewCard.Actions
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/AlertReportList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,11 @@ function AlertList({
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/AnnotationLayerList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,11 @@ function AnnotationLayersList({
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/ChartList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,11 @@ function ChartList(props: ChartListProps) {
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'last_saved_at',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/CssTemplateList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,11 @@ function CssTemplatesList({
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
disableSortBy: true,
},
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/DashboardList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,11 @@ function DashboardList(props: DashboardListProps) {
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/DatabaseList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,11 @@ function DatabaseList({
{
Cell: ({
row: {
original: {
changed_by: changedBy,
changed_on_delta_humanized: changedOn,
},
original: { changed_by: changedBy, changed_on_utc: changedOn },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/DatasetList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,11 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/RowLevelSecurityList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,11 @@ function RowLevelSecurityList(props: RLSProps) {
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/SavedQueryList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,11 @@ function SavedQueryList({
{
Cell: ({
row: {
original: {
changed_by: changedBy,
changed_on_delta_humanized: changedOn,
},
original: { changed_by: changedBy, changed_on_utc: changedOn },
},
}: any) => <ModifiedInfo user={changedBy} date={changedOn} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/pages/Tags/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,11 @@ function TagList(props: TagListProps) {
{
Cell: ({
row: {
original: {
changed_on_delta_humanized: changedOn,
changed_by: changedBy,
},
original: { changed_on_utc: changedOn, changed_by: changedBy },
},
}: any) => <ModifiedInfo date={changedOn} user={changedBy} />,
Header: t('Last modified'),
accessor: 'changed_on_delta_humanized',
accessor: 'changed_on_utc',
size: 'xl',
},
{
Expand Down
2 changes: 2 additions & 0 deletions superset/annotation_layers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class AnnotationLayerRestApi(BaseSupersetModelRestApi):
"changed_by.first_name",
"changed_by.last_name",
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"created_on",
]
Expand All @@ -94,6 +95,7 @@ class AnnotationLayerRestApi(BaseSupersetModelRestApi):
"created_by.first_name",
"changed_by.first_name",
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"created_on",
]
Expand Down
1 change: 1 addition & 0 deletions superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]:
list_select_columns = list_columns + ["changed_by_fk", "changed_on"]
order_columns = [
"changed_by.first_name",
"changed_on_utc",
"changed_on_delta_humanized",
"datasource_id",
"datasource_name",
Expand Down
2 changes: 2 additions & 0 deletions superset/commands/explore/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def run(self) -> Optional[dict[str, Any]]:

if slc:
metadata = {
"created_on_utc": slc.created_on_utc(),
"changed_on_utc": slc.changed_on_utc(),
"created_on_humanized": slc.created_on_humanized,
"changed_on_humanized": slc.changed_on_humanized,
"owners": [owner.get_full_name() for owner in slc.owners],
Expand Down
2 changes: 2 additions & 0 deletions superset/css_templates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CssTemplateRestApi(BaseSupersetModelRestApi):
allow_browser_login = True

show_columns = [
"changed_on_utc",
"changed_on_delta_humanized",
"changed_by.first_name",
"changed_by.id",
Expand All @@ -66,6 +67,7 @@ class CssTemplateRestApi(BaseSupersetModelRestApi):
"template_name",
]
list_columns = [
"changed_on_utc",
"changed_on_delta_humanized",
"changed_by.first_name",
"changed_by.id",
Expand Down
1 change: 1 addition & 0 deletions superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]:
list_select_columns = list_columns + ["changed_on", "created_on", "changed_by_fk"]
order_columns = [
"changed_by.first_name",
"changed_on_utc",
"changed_on_delta_humanized",
"created_by.first_name",
"dashboard_title",
Expand Down
2 changes: 2 additions & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"allows_virtual_table_explore",
"backend",
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"changed_by.first_name",
"changed_by.last_name",
Expand Down Expand Up @@ -259,6 +260,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"allow_dml",
"allow_run_async",
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"created_by.first_name",
"database_name",
Expand Down
1 change: 1 addition & 0 deletions superset/datasets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class DatasetRestApi(BaseSupersetModelRestApi):
"catalog",
"schema",
"changed_by.first_name",
"changed_on_utc",
"changed_on_delta_humanized",
"database.database_name",
]
Expand Down
5 changes: 5 additions & 0 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ def changed_on_dttm(self) -> float:
def created_on_delta_humanized(self) -> str:
return self.created_on_humanized

@renders("created_on")
def created_on_utc(self) -> str:
# Convert naive datetime to UTC
return self.created_on.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%z")

@renders("changed_on")
def changed_on_utc(self) -> str:
# Convert naive datetime to UTC
Expand Down
3 changes: 3 additions & 0 deletions superset/queries/saved_queries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class SavedQueryRestApi(BaseSupersetModelRestApi):

show_columns = [
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"changed_by.first_name",
"changed_by.id",
Expand All @@ -103,6 +104,7 @@ class SavedQueryRestApi(BaseSupersetModelRestApi):
]
list_columns = [
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"changed_by.first_name",
"changed_by.id",
Expand Down Expand Up @@ -148,6 +150,7 @@ class SavedQueryRestApi(BaseSupersetModelRestApi):
"created_by.first_name",
"database.database_name",
"created_on",
"changed_on_utc",
"changed_on_delta_humanized",
"last_run_delta_humanized",
]
Expand Down
2 changes: 2 additions & 0 deletions superset/reports/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def ensure_alert_reports_enabled(self) -> Optional[Response]:
"changed_by.first_name",
"changed_by.last_name",
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"chart_id",
"created_by.first_name",
Expand Down Expand Up @@ -187,6 +188,7 @@ def ensure_alert_reports_enabled(self) -> Optional[Response]:
"created_by.first_name",
"changed_by.first_name",
"changed_on",
"changed_on_utc",
"changed_on_delta_humanized",
"created_on",
"crontab",
Expand Down
1 change: 1 addition & 0 deletions superset/row_level_security/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class RLSRestApi(BaseSupersetModelRestApi):
"roles.id",
"roles.name",
"clause",
"changed_on_utc",
"changed_on_delta_humanized",
"changed_by.first_name",
"changed_by.last_name",
Expand Down

0 comments on commit b125f37

Please sign in to comment.