Skip to content

fix: translate-changed_on_delta_humanized #20082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion superset-frontend/src/dashboard/components/SliceAdder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
} from 'src/dashboard/util/constants';
import { slicePropShape } from 'src/dashboard/util/propShapes';
import { FILTER_BOX_MIGRATION_STATES } from 'src/explore/constants';
import moment from 'moment';
import _ from 'lodash';
import AddSliceCard from './AddSliceCard';
import AddSliceDragPreview from './dnd/AddSliceDragPreview';
Expand Down Expand Up @@ -269,7 +270,7 @@ class SliceAdder extends React.Component {
innerRef={dragSourceRef}
style={style}
sliceName={cellData.slice_name}
lastModified={cellData.changed_on_humanized}
lastModified={moment.utc(cellData.changed_on).fromNow()}
visType={cellData.viz_type}
datasourceUrl={cellData.datasource_url}
datasourceName={cellData.datasource_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { DragLayer } from 'react-dnd';

import moment from 'moment';
import AddSliceCard from '../AddSliceCard';
import { slicePropShape } from '../../util/propShapes';
import {
Expand Down Expand Up @@ -72,7 +73,7 @@ function AddSliceDragPreview({ dragItem, slices, isDragging, currentOffset }) {
transform: `translate(${currentOffset.x}px, ${currentOffset.y}px)`,
}}
sliceName={slice.slice_name}
lastModified={slice.changed_on_humanized}
lastModified={moment.utc(slice.changed_on).fromNow()}
visType={slice.viz_type}
datasourceUrl={slice.datasource_url}
datasourceName={slice.datasource_name}
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/pages/ChartList/ChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { Menu } from 'src/components/Menu';
import FaveStar from 'src/components/FaveStar';
import FacePile from 'src/components/FacePile';
import { handleChartDelete, CardStyles } from 'src/views/CRUD/utils';
import moment from 'moment';
import { handleChartDelete, CardStyles } from '../utils';

interface ChartCardProps {
chart: Chart;
Expand Down Expand Up @@ -155,7 +157,7 @@ export default function ChartCard({
url={bulkSelectEnabled ? undefined : chart.url}
imgURL={chart.thumbnail_url || ''}
imgFallbackURL="/static/assets/images/chart-card-fallback.svg"
description={t('Modified %s', chart.changed_on_delta_humanized)}
description={t('Modified %s', moment(chart.changed_on_utc).fromNow())}
coverLeft={<FacePile users={chart.owners || []} />}
coverRight={
<Label type="secondary">{chart.datasource_name_text}</Label>
Expand Down
6 changes: 5 additions & 1 deletion superset-frontend/src/views/CRUD/dashboard/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 @@ -160,7 +161,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(dashboard.changed_on_utc).fromNow(),
)}
coverLeft={<FacePile users={dashboard.owners || []} />}
actions={
<ListViewCard.Actions
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/views/CRUD/welcome/SavedQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ListViewCard from 'src/components/ListViewCard';
import DeleteModal from 'src/components/DeleteModal';
import Icons from 'src/components/Icons';
import SubMenu from 'src/views/components/SubMenu';
import moment from 'moment';
import { User } from 'src/types/bootstrapTypes';
import EmptyState from './EmptyState';
import {
Expand All @@ -55,6 +56,7 @@ interface Query {
end_time?: string;
label?: string;
changed_on_delta_humanized?: string;
last_run?: string;
sql?: string | null;
}

Expand Down Expand Up @@ -289,7 +291,7 @@ const SavedQueries = ({
url={`/superset/sqllab?savedQueryId=${q.id}`}
title={q.label}
imgFallbackURL="/static/assets/images/empty-query.svg"
description={t('Ran %s', q.changed_on_delta_humanized)}
description={t('Ran %s', moment(q.last_run).fromNow())}
cover={
q?.sql?.length && showThumbnails && featureFlag ? (
<QueryContainer>
Expand Down
5 changes: 5 additions & 0 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import inspect
import logging
import re
import pytz
from datetime import datetime
from typing import Any, Dict, List, Optional, Type, TYPE_CHECKING

Expand Down Expand Up @@ -397,6 +398,10 @@ def pop_tab_link(self) -> Markup:
def user_email(self) -> str:
return self.user.email

@property
def last_run(self) -> str:
return self.changed_on.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%z")

@property
def sqlalchemy_uri(self) -> URL:
return self.database.sqlalchemy_uri
Expand Down
1 change: 1 addition & 0 deletions superset/queries/saved_queries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class SavedQueryRestApi(BaseSupersetModelRestApi):
"sql_tables",
"rows",
"last_run_delta_humanized",
"last_run",
"extra",
]
add_columns = [
Expand Down