mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
feat: deprecate old API on core superset fave_dashboards (#19754)
* feat: deprecate old API on core superset fave_dashboards * fix js lint * remove unused type
This commit is contained in:
parent
aff10a7fad
commit
85b0ef8526
@ -17,12 +17,13 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import rison from 'rison';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { t } from '@superset-ui/core';
|
import { t } from '@superset-ui/core';
|
||||||
|
|
||||||
import TableLoader from '../../components/TableLoader';
|
import TableLoader from '../../components/TableLoader';
|
||||||
import { Slice } from '../types';
|
import { Slice } from '../types';
|
||||||
import { User, Dashboard } from '../../types/bootstrapTypes';
|
import { User, DashboardResponse } from '../../types/bootstrapTypes';
|
||||||
|
|
||||||
interface FavoritesProps {
|
interface FavoritesProps {
|
||||||
user: User;
|
user: User;
|
||||||
@ -50,19 +51,29 @@ export default class Favorites extends React.PureComponent<FavoritesProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderDashboardTable() {
|
renderDashboardTable() {
|
||||||
const mutator = (data: Dashboard[]) =>
|
const search = [{ col: 'id', opr: 'dashboard_is_favorite', value: true }];
|
||||||
data.map(dash => ({
|
const query = rison.encode({
|
||||||
dashboard: <a href={dash.url}>{dash.title}</a>,
|
keys: ['none'],
|
||||||
creator: <a href={dash.creator_url}>{dash.creator}</a>,
|
columns: ['created_on_delta_humanized', 'dashboard_title', 'url'],
|
||||||
favorited: moment.utc(dash.dttm).fromNow(),
|
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 (
|
return (
|
||||||
<TableLoader
|
<TableLoader
|
||||||
className="table-condensed"
|
className="table-condensed"
|
||||||
mutator={mutator}
|
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!')}
|
noDataText={t('No favorite dashboards yet, go click on stars!')}
|
||||||
columns={['dashboard', 'creator', 'favorited']}
|
columns={['dashboard', 'creator', 'created']}
|
||||||
sortable
|
sortable
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -40,15 +40,6 @@ export interface UserWithPermissionsAndRoles extends User {
|
|||||||
|
|
||||||
export type UndefinedUser = {};
|
export type UndefinedUser = {};
|
||||||
|
|
||||||
export type Dashboard = {
|
|
||||||
dttm: number;
|
|
||||||
id: number;
|
|
||||||
url: string;
|
|
||||||
title: string;
|
|
||||||
creator?: string;
|
|
||||||
creator_url?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type DashboardData = {
|
export type DashboardData = {
|
||||||
dashboard_title?: string;
|
dashboard_title?: string;
|
||||||
created_on_delta_humanized?: string;
|
created_on_delta_humanized?: string;
|
||||||
|
@ -1543,6 +1543,11 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
|||||||
@expose("/fave_dashboards_by_username/<username>/", methods=["GET"])
|
@expose("/fave_dashboards_by_username/<username>/", methods=["GET"])
|
||||||
def fave_dashboards_by_username(self, username: str) -> FlaskResponse:
|
def fave_dashboards_by_username(self, username: str) -> FlaskResponse:
|
||||||
"""This lets us use a user's username to pull favourite dashboards"""
|
"""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)
|
user = security_manager.find_user(username=username)
|
||||||
return self.fave_dashboards(user.id)
|
return self.fave_dashboards(user.id)
|
||||||
|
|
||||||
@ -1551,6 +1556,11 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
|||||||
@event_logger.log_this
|
@event_logger.log_this
|
||||||
@expose("/fave_dashboards/<int:user_id>/", methods=["GET"])
|
@expose("/fave_dashboards/<int:user_id>/", methods=["GET"])
|
||||||
def fave_dashboards(self, user_id: int) -> FlaskResponse:
|
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)
|
error_obj = self.get_user_activity_access_error(user_id)
|
||||||
if error_obj:
|
if error_obj:
|
||||||
return error_obj
|
return error_obj
|
||||||
|
Loading…
Reference in New Issue
Block a user