Skip to content
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

feat(dashboard): Add metadata bar to the header #27857

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions superset-frontend/spec/fixtures/mockDashboardInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default {
},
],
},
changed_on_delta_humanized: '7 minutes ago',
changed_by_name: 'John Doe',
created_on_delta_humanized: '10 days ago',
created_by_name: 'Kay Mon',
owners: [{ first_name: 'John', last_name: 'Doe', id: 1 }],
userId: 'mock_user_id',
dash_edit_perm: true,
dash_save_perm: true,
Expand Down
16 changes: 16 additions & 0 deletions superset-frontend/src/dashboard/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const createProps = () => ({
],
},
},
changed_on_delta_humanized: '7 minutes ago',
changed_by_name: 'John Doe',
created_on_delta_humanized: '10 days ago',
created_by_name: 'Kay Mon',
owners: [{ first_name: 'John', last_name: 'Doe', id: 1 }],
},
user: {
createdOn: '2021-04-27T18:12:38.952304',
Expand Down Expand Up @@ -187,6 +192,17 @@ test('should publish', () => {
expect(mockedProps.savePublished).toHaveBeenCalledTimes(1);
});

test('should render metadata', () => {
const mockedProps = createProps();
setup(mockedProps);
expect(
screen.getByText(mockedProps.dashboardInfo.created_by_name),
).toBeInTheDocument();
expect(
screen.getByText(mockedProps.dashboardInfo.changed_on_delta_humanized),
).toBeInTheDocument();
});

test('should render the "Undo" action as disabled', () => {
setup(editableProps);
expect(screen.getByTestId('undo-action').parentElement).toBeDisabled();
Expand Down
28 changes: 28 additions & 0 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import PublishedStatus from 'src/dashboard/components/PublishedStatus';
import UndoRedoKeyListeners from 'src/dashboard/components/UndoRedoKeyListeners';
import PropertiesModal from 'src/dashboard/components/PropertiesModal';
import { chartPropShape } from 'src/dashboard/util/propShapes';
import getOwnerName from 'src/utils/getOwnerName';
import {
UNDO_LIMIT,
SAVE_TYPE_OVERWRITE,
Expand All @@ -55,6 +56,7 @@ import setPeriodicRunner, {
stopPeriodicRender,
} from 'src/dashboard/util/setPeriodicRunner';
import { PageHeaderWithActions } from 'src/components/PageHeaderWithActions';
import MetadataBar, { MetadataType } from 'src/components/MetadataBar';
import DashboardEmbedModal from '../EmbeddedModal';
import OverwriteConfirm from '../OverwriteConfirm';

Expand Down Expand Up @@ -435,6 +437,26 @@ class Header extends React.PureComponent {
this.setState({ showingEmbedModal: false });
};

getMetadataItems = () => {
const { dashboardInfo } = this.props;
return [
{
type: MetadataType.LastModified,
value: dashboardInfo.changed_on_delta_humanized,
modifiedBy: dashboardInfo.changed_by_name || t('Not available'),
},
{
type: MetadataType.Owner,
createdBy: dashboardInfo.created_by_name || t('Not available'),
owners:
dashboardInfo.owners.length > 0
? dashboardInfo.owners.map(getOwnerName)
: t('None'),
createdOn: dashboardInfo.created_on_delta_humanized,
},
];
};

render() {
const {
dashboardTitle,
Expand Down Expand Up @@ -535,6 +557,12 @@ class Header extends React.PureComponent {
visible={!editMode}
/>
),
!editMode && (
<MetadataBar
items={this.getMetadataItems()}
tooltipPlacement="bottom"
/>
),
]}
rightPanelAdditionalItems={
<div className="button-container">
Expand Down
1 change: 1 addition & 0 deletions superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]:
"created_by.first_name",
"created_by.id",
"created_by.last_name",
"created_by_name",
"dashboard_title",
"owners.id",
"owners.first_name",
Expand Down
2 changes: 2 additions & 0 deletions superset/dashboards/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ class DashboardGetResponseSchema(Schema):
certification_details = fields.String(
metadata={"description": certification_details_description}
)
created_by_name = fields.String()
changed_by_name = fields.String()
changed_by = fields.Nested(UserSchema(exclude=["username"]))
changed_on = fields.DateTime()
charts = fields.List(fields.String(metadata={"description": charts_description}))
owners = fields.List(fields.Nested(UserSchema(exclude=["username"])))
roles = fields.List(fields.Nested(RolesSchema))
tags = fields.Nested(TagSchema, many=True)
created_on_humanized = fields.String(data_key="created_on_delta_humanized")
changed_on_humanized = fields.String(data_key="changed_on_delta_humanized")
is_managed_externally = fields.Boolean(allow_none=True, dump_default=False)

Expand Down
6 changes: 6 additions & 0 deletions superset/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ def changed_by_name(self) -> str:
return ""
return str(self.changed_by)

@property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the same case as the owners and should be handled by the frontend.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

def created_by_name(self) -> str:
if not self.created_by:
return ""
return str(self.created_by)

@property
def data(self) -> dict[str, Any]:
positions = self.position_json
Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def test_get_dashboard(self):
"first_name": "admin",
"last_name": "user",
},
"created_by_name": "admin user",
"id": dashboard.id,
"css": "",
"dashboard_title": "title",
Expand All @@ -423,11 +424,13 @@ def test_get_dashboard(self):
data = json.loads(rv.data.decode("utf-8"))
self.assertIn("changed_on", data["result"])
self.assertIn("changed_on_delta_humanized", data["result"])
self.assertIn("created_on_delta_humanized", data["result"])
for key, value in data["result"].items():
# We can't assert timestamp values
if key not in (
"changed_on",
"changed_on_delta_humanized",
"created_on_delta_humanized",
):
self.assertEqual(value, expected_result[key])
# rollback changes
Expand Down
Loading