Skip to content

Commit

Permalink
feat: deprecate old API on core superset fave_dashboards (#19754)
Browse files Browse the repository at this point in the history
* feat: deprecate old API on core superset fave_dashboards

* fix js lint

* remove unused type
  • Loading branch information
dpgaspar committed May 2, 2022
1 parent aff10a7 commit 85b0ef8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
27 changes: 19 additions & 8 deletions superset-frontend/src/profile/components/Favorites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
* under the License.
*/
import React from 'react';
import rison from 'rison';
import moment from 'moment';
import { t } from '@superset-ui/core';

import TableLoader from '../../components/TableLoader';
import { Slice } from '../types';
import { User, Dashboard } from '../../types/bootstrapTypes';
import { User, DashboardResponse } from '../../types/bootstrapTypes';

interface FavoritesProps {
user: User;
Expand Down Expand Up @@ -50,19 +51,29 @@ export default class Favorites extends React.PureComponent<FavoritesProps> {
}

renderDashboardTable() {
const mutator = (data: Dashboard[]) =>
data.map(dash => ({
dashboard: <a href={dash.url}>{dash.title}</a>,
creator: <a href={dash.creator_url}>{dash.creator}</a>,
favorited: moment.utc(dash.dttm).fromNow(),
const search = [{ col: 'id', opr: 'dashboard_is_favorite', value: true }];
const query = rison.encode({
keys: ['none'],
columns: ['created_on_delta_humanized', 'dashboard_title', 'url'],
filters: search,
order_column: 'changed_on',
order_direction: 'desc',
page: 0,
page_size: 100,
});
const mutator = (data: DashboardResponse) =>
data.result.map(dash => ({
dashboard: <a href={dash.url}>{dash.dashboard_title}</a>,
created: dash.created_on_delta_humanized,
_created: dash.created_on_delta_humanized,
}));
return (
<TableLoader
className="table-condensed"
mutator={mutator}
dataEndpoint={`/superset/fave_dashboards/${this.props.user.userId}/`}
dataEndpoint={`/api/v1/dashboard/?q=${query}`}
noDataText={t('No favorite dashboards yet, go click on stars!')}
columns={['dashboard', 'creator', 'favorited']}
columns={['dashboard', 'creator', 'created']}
sortable
/>
);
Expand Down
9 changes: 0 additions & 9 deletions superset-frontend/src/types/bootstrapTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ export interface UserWithPermissionsAndRoles extends User {

export type UndefinedUser = {};

export type Dashboard = {
dttm: number;
id: number;
url: string;
title: string;
creator?: string;
creator_url?: string;
};

export type DashboardData = {
dashboard_title?: string;
created_on_delta_humanized?: string;
Expand Down
10 changes: 10 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,11 @@ def available_domains(self) -> FlaskResponse: # pylint: disable=no-self-use
@expose("/fave_dashboards_by_username/<username>/", methods=["GET"])
def fave_dashboards_by_username(self, username: str) -> FlaskResponse:
"""This lets us use a user's username to pull favourite dashboards"""
logger.warning(
"%s.fave_dashboards_by_username "
"This API endpoint is deprecated and will be removed in version 3.0.0",
self.__class__.__name__,
)
user = security_manager.find_user(username=username)
return self.fave_dashboards(user.id)

Expand All @@ -1551,6 +1556,11 @@ def fave_dashboards_by_username(self, username: str) -> FlaskResponse:
@event_logger.log_this
@expose("/fave_dashboards/<int:user_id>/", methods=["GET"])
def fave_dashboards(self, user_id: int) -> FlaskResponse:
logger.warning(
"%s.fave_dashboards "
"This API endpoint is deprecated and will be removed in version 3.0.0",
self.__class__.__name__,
)
error_obj = self.get_user_activity_access_error(user_id)
if error_obj:
return error_obj
Expand Down

0 comments on commit 85b0ef8

Please sign in to comment.