feat: add favorite star to dashboard and chart lists (#10510)
This commit is contained in:
parent
523c6b77bf
commit
e040bf7acf
|
|
@ -38,25 +38,27 @@ describe('Dashboard add to favorite', () => {
|
|||
|
||||
it('should allow favor/unfavor', () => {
|
||||
if (!isFavoriteDashboard) {
|
||||
cy.get('.favstar').find('i').should('have.class', 'fa-star-o');
|
||||
cy.get('.favstar').trigger('click');
|
||||
cy.get('.favstar')
|
||||
.find('i')
|
||||
.should('have.class', 'fa-star')
|
||||
.and('not.have.class', 'fa-star-o');
|
||||
cy.get('a.fave-unfave-icon')
|
||||
.find('svg')
|
||||
.should('have.attr', 'data-test', 'favorite-unselected');
|
||||
cy.get('a.fave-unfave-icon').trigger('click');
|
||||
cy.get('a.fave-unfave-icon')
|
||||
.find('svg')
|
||||
.should('have.attr', 'data-test', 'favorite-selected')
|
||||
.and('not.have.attr', 'data-test', 'favorite-unselected');
|
||||
} else {
|
||||
cy.get('.favstar')
|
||||
.find('i')
|
||||
.should('have.class', 'fa-star')
|
||||
.and('not.have.class', 'fa-star-o');
|
||||
cy.get('.favstar').trigger('click');
|
||||
cy.get('.fave-unfave-icon')
|
||||
.find('i')
|
||||
.should('have.class', 'fa-star-o')
|
||||
.and('not.have.class', 'fa-star');
|
||||
cy.get('a.fave-unfave-icon')
|
||||
.find('svg')
|
||||
.should('have.attr', 'data-test', 'favorite-unselected')
|
||||
.and('not.have.attr', 'data-test', 'favorite-selected');
|
||||
cy.get('a.fave-unfave-icon').trigger('click');
|
||||
cy.get('a.fave-unfave-icon')
|
||||
.find('svg')
|
||||
.should('have.attr', 'data-test', 'favorite-unselected')
|
||||
.and('not.have.attr', 'data-test', 'favorite-selected');
|
||||
}
|
||||
|
||||
// reset to original fav state
|
||||
cy.get('.favstar').trigger('click');
|
||||
cy.get('a.fave-unfave-icon').trigger('click');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<svg width="16" height="15" viewBox="0 0 16 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.9731 5.67407C15.8701 5.38097 15.6008 5.17499 15.2861 5.14856L10.7403 4.49755L8.70305 0.44246C8.56956 0.171867 8.29027 0 7.98403 0C7.67779 0 7.3985 0.171867 7.26501 0.44246L5.22779 4.48971L0.681994 5.14856C0.380344 5.19065 0.129343 5.39753 0.0348768 5.68192C-0.0514978 5.95951 0.0253348 6.26124 0.234604 6.46627L3.5341 9.60367L2.73519 14.0588C2.67696 14.359 2.80168 14.6651 3.05476 14.8431C3.30116 15.0161 3.626 15.0373 3.89361 14.898L7.98403 12.8038L12.0585 14.9059C12.1706 14.968 12.2972 15.0004 12.426 15C12.5952 15.0006 12.7603 14.9484 12.8973 14.851C13.1504 14.673 13.2751 14.3669 13.2169 14.0666L12.418 9.61151L15.7175 6.47411C15.9529 6.27828 16.0524 5.96685 15.9731 5.67407Z" fill="#FBC700"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
|
|
@ -0,0 +1,21 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<svg width="16" height="15" viewBox="0 0 16 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.9731 5.67407C15.8701 5.38097 15.6008 5.17499 15.2861 5.14856L10.7403 4.49755L8.70305 0.44246C8.56956 0.171867 8.29027 0 7.98403 0C7.67779 0 7.3985 0.171867 7.26501 0.44246L5.22779 4.48971L0.681994 5.14856C0.380344 5.19065 0.129343 5.39753 0.0348768 5.68192C-0.0514978 5.95951 0.0253348 6.26124 0.234604 6.46627L3.5341 9.60367L2.73519 14.0588C2.67696 14.359 2.80168 14.6651 3.05476 14.8431C3.30116 15.0161 3.626 15.0373 3.89361 14.898L7.98403 12.8038L12.0585 14.9059C12.1706 14.968 12.2972 15.0004 12.426 15C12.5952 15.0006 12.7603 14.9484 12.8973 14.851C13.1504 14.673 13.2751 14.3669 13.2169 14.0666L12.418 9.61151L15.7175 6.47411C15.9529 6.27828 16.0524 5.96685 15.9731 5.67407ZM10.2593 8.90435L10.8172 12.0154L8.90102 11.0264L7.98753 10.5551L5.13324 12.0165L5.5027 9.95669L5.69282 8.8965L3.454 6.76768L5.51467 6.46902L6.54579 6.31958L7.98301 3.46432L8.95313 5.39539L9.42226 6.3292L12.5034 6.77046L10.2593 8.90435Z" fill="#E0E0E0"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
File diff suppressed because it is too large
Load Diff
|
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import cx from 'classnames';
|
||||
import { t } from '@superset-ui/translation';
|
||||
import TooltipWrapper from './TooltipWrapper';
|
||||
|
||||
const propTypes = {
|
||||
itemId: PropTypes.number.isRequired,
|
||||
fetchFaveStar: PropTypes.func,
|
||||
saveFaveStar: PropTypes.func,
|
||||
isStarred: PropTypes.bool.isRequired,
|
||||
};
|
||||
|
||||
export default class FaveStar extends React.Component {
|
||||
componentDidMount() {
|
||||
this.props.fetchFaveStar(this.props.itemId);
|
||||
}
|
||||
|
||||
onClick(e) {
|
||||
e.preventDefault();
|
||||
this.props.saveFaveStar(this.props.itemId, this.props.isStarred);
|
||||
}
|
||||
|
||||
render() {
|
||||
const iconClassNames = cx('fa', {
|
||||
'fa-star': this.props.isStarred,
|
||||
'fa-star-o': !this.props.isStarred,
|
||||
});
|
||||
|
||||
return (
|
||||
<TooltipWrapper
|
||||
label="fave-unfave"
|
||||
tooltip={t('Click to favorite/unfavorite')}
|
||||
>
|
||||
<a
|
||||
href="#"
|
||||
onClick={this.onClick.bind(this)}
|
||||
className="fave-unfave-icon"
|
||||
>
|
||||
<i className={iconClassNames} />
|
||||
</a>
|
||||
</TooltipWrapper>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FaveStar.propTypes = propTypes;
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { t } from '@superset-ui/translation';
|
||||
import TooltipWrapper from './TooltipWrapper';
|
||||
import Icon from './Icon';
|
||||
|
||||
interface FaveStarProps {
|
||||
itemId: number;
|
||||
fetchFaveStar(id: number): any;
|
||||
saveFaveStar(id: number, isStarred: boolean): any;
|
||||
isStarred: boolean;
|
||||
width?: number;
|
||||
height?: number;
|
||||
showTooltip?: boolean;
|
||||
}
|
||||
|
||||
export default class FaveStar extends React.PureComponent<FaveStarProps> {
|
||||
componentDidMount() {
|
||||
this.props.fetchFaveStar(this.props.itemId);
|
||||
}
|
||||
|
||||
onClick(e: React.MouseEvent) {
|
||||
e.preventDefault();
|
||||
this.props.saveFaveStar(this.props.itemId, this.props.isStarred);
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.props.showTooltip) {
|
||||
return (
|
||||
<TooltipWrapper
|
||||
label="fave-unfave"
|
||||
tooltip={t('Click to favorite/unfavorite')}
|
||||
>
|
||||
<a
|
||||
href="#"
|
||||
onClick={this.onClick.bind(this)}
|
||||
className="fave-unfave-icon"
|
||||
>
|
||||
<Icon
|
||||
name={
|
||||
this.props.isStarred
|
||||
? 'favorite-selected'
|
||||
: 'favorite-unselected'
|
||||
}
|
||||
viewBox="0 0 16 15"
|
||||
width={this.props.width || 20}
|
||||
height="auto"
|
||||
/>
|
||||
</a>
|
||||
</TooltipWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
href="#"
|
||||
onClick={this.onClick.bind(this)}
|
||||
className="fave-unfave-icon"
|
||||
>
|
||||
<Icon
|
||||
name={
|
||||
this.props.isStarred ? 'favorite-selected' : 'favorite-unselected'
|
||||
}
|
||||
viewBox="0 0 16 15"
|
||||
width={this.props.width || 20}
|
||||
height={this.props.height || 'auto'}
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,8 @@ import { ReactComponent as CompassIcon } from 'images/icons/compass.svg';
|
|||
import { ReactComponent as DatasetPhysicalIcon } from 'images/icons/dataset_physical.svg';
|
||||
import { ReactComponent as DatasetVirtualIcon } from 'images/icons/dataset_virtual.svg';
|
||||
import { ReactComponent as ErrorIcon } from 'images/icons/error.svg';
|
||||
import { ReactComponent as FavoriteSelectedIcon } from 'images/icons/favorite-selected.svg';
|
||||
import { ReactComponent as FavoriteUnselectedIcon } from 'images/icons/favorite-unselected.svg';
|
||||
import { ReactComponent as PencilIcon } from 'images/icons/pencil.svg';
|
||||
import { ReactComponent as SearchIcon } from 'images/icons/search.svg';
|
||||
import { ReactComponent as SortAscIcon } from 'images/icons/sort-asc.svg';
|
||||
|
|
@ -51,6 +53,8 @@ type IconName =
|
|||
| 'dataset-physical'
|
||||
| 'dataset-virtual'
|
||||
| 'error'
|
||||
| 'favorite-selected'
|
||||
| 'favorite-unselected'
|
||||
| 'pencil'
|
||||
| 'search'
|
||||
| 'sort'
|
||||
|
|
@ -72,6 +76,8 @@ const iconsRegistry: Record<
|
|||
'circle-check-solid': CircleCheckSolidIcon,
|
||||
'dataset-physical': DatasetPhysicalIcon,
|
||||
'dataset-virtual': DatasetVirtualIcon,
|
||||
'favorite-selected': FavoriteSelectedIcon,
|
||||
'favorite-unselected': FavoriteUnselectedIcon,
|
||||
'sort-asc': SortAscIcon,
|
||||
'sort-desc': SortDescIcon,
|
||||
check: CheckIcon,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
import moment from 'moment';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import styled from '@superset-ui/style';
|
||||
import { CategoricalColorNamespace } from '@superset-ui/color';
|
||||
import { t } from '@superset-ui/translation';
|
||||
|
||||
|
|
@ -99,6 +100,14 @@ const defaultProps = {
|
|||
colorScheme: undefined,
|
||||
};
|
||||
|
||||
// Styled Components
|
||||
const StyledDashboardHeader = styled.div`
|
||||
button,
|
||||
.fave-unfave-icon {
|
||||
margin-left: 8px;
|
||||
}
|
||||
`;
|
||||
|
||||
class Header extends React.PureComponent {
|
||||
static discardChanges() {
|
||||
window.location.reload();
|
||||
|
|
@ -360,7 +369,7 @@ class Header extends React.PureComponent {
|
|||
const popButton = hasUnsavedChanges;
|
||||
|
||||
return (
|
||||
<div className="dashboard-header">
|
||||
<StyledDashboardHeader className="dashboard-header">
|
||||
<div className="dashboard-component-header header-large">
|
||||
<EditableTitle
|
||||
title={dashboardTitle}
|
||||
|
|
@ -368,24 +377,21 @@ class Header extends React.PureComponent {
|
|||
onSaveTitle={this.handleChangeText}
|
||||
showTooltip={false}
|
||||
/>
|
||||
<span className="publish">
|
||||
<PublishedStatus
|
||||
dashboardId={dashboardInfo.id}
|
||||
isPublished={isPublished}
|
||||
savePublished={this.props.savePublished}
|
||||
canEdit={userCanEdit}
|
||||
canSave={userCanSaveAs}
|
||||
/>
|
||||
</span>
|
||||
<PublishedStatus
|
||||
dashboardId={dashboardInfo.id}
|
||||
isPublished={isPublished}
|
||||
savePublished={this.props.savePublished}
|
||||
canEdit={userCanEdit}
|
||||
canSave={userCanSaveAs}
|
||||
/>
|
||||
{dashboardInfo.userId && (
|
||||
<span className="favstar">
|
||||
<FaveStar
|
||||
itemId={dashboardInfo.id}
|
||||
fetchFaveStar={this.props.fetchFaveStar}
|
||||
saveFaveStar={this.props.saveFaveStar}
|
||||
isStarred={this.props.isStarred}
|
||||
/>
|
||||
</span>
|
||||
<FaveStar
|
||||
itemId={dashboardInfo.id}
|
||||
fetchFaveStar={this.props.fetchFaveStar}
|
||||
saveFaveStar={this.props.saveFaveStar}
|
||||
isStarred={this.props.isStarred}
|
||||
showTooltip
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
|
@ -532,7 +538,7 @@ class Header extends React.PureComponent {
|
|||
refreshWarning={refreshWarning}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</StyledDashboardHeader>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import React from 'react';
|
|||
import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import styled from '@superset-ui/style';
|
||||
import { t } from '@superset-ui/translation';
|
||||
|
||||
import { chartPropShape } from '../../dashboard/util/propShapes';
|
||||
|
|
@ -55,6 +56,33 @@ const propTypes = {
|
|||
chart: chartPropShape,
|
||||
};
|
||||
|
||||
const StyledHeader = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
span[role='button'] {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.right-button-panel {
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
|
||||
.btn-group {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledButtons = styled.span`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
`;
|
||||
|
||||
export class ExploreChartHeader extends React.PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
@ -103,7 +131,7 @@ export class ExploreChartHeader extends React.PureComponent {
|
|||
this.props.chart.chartStatus,
|
||||
);
|
||||
return (
|
||||
<div id="slice-header" className="clearfix panel-title-large">
|
||||
<StyledHeader id="slice-header" className="clearfix panel-title-large">
|
||||
<EditableTitle
|
||||
title={this.getSliceName()}
|
||||
canEdit={!this.props.slice || this.props.can_overwrite}
|
||||
|
|
@ -111,12 +139,13 @@ export class ExploreChartHeader extends React.PureComponent {
|
|||
/>
|
||||
|
||||
{this.props.slice && (
|
||||
<span>
|
||||
<StyledButtons>
|
||||
<FaveStar
|
||||
itemId={this.props.slice.slice_id}
|
||||
fetchFaveStar={this.props.actions.fetchFaveStar}
|
||||
saveFaveStar={this.props.actions.saveFaveStar}
|
||||
isStarred={this.props.isStarred}
|
||||
showTooltip
|
||||
/>
|
||||
<PropertiesModal
|
||||
show={this.state.isPropertiesModalOpen}
|
||||
|
|
@ -137,15 +166,16 @@ export class ExploreChartHeader extends React.PureComponent {
|
|||
<i className="fa fa-edit" />
|
||||
</span>
|
||||
</TooltipWrapper>
|
||||
</span>
|
||||
</StyledButtons>
|
||||
)}
|
||||
{this.props.chart.sliceFormData && (
|
||||
<AlteredSliceTag
|
||||
className="altered"
|
||||
origFormData={this.props.chart.sliceFormData}
|
||||
currentFormData={formData}
|
||||
/>
|
||||
)}
|
||||
<div className="pull-right">
|
||||
<div className="right-button-panel">
|
||||
{chartFinished && queryResponse && (
|
||||
<RowCountLabel
|
||||
rowcount={Number(queryResponse.rowcount) || 0}
|
||||
|
|
@ -174,7 +204,7 @@ export class ExploreChartHeader extends React.PureComponent {
|
|||
queryResponse={queryResponse}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</StyledHeader>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,15 @@ import PropTypes from 'prop-types';
|
|||
import React from 'react';
|
||||
import rison from 'rison';
|
||||
import { uniqBy } from 'lodash';
|
||||
import { createFetchRelated, createErrorHandler } from 'src/views/CRUD/utils';
|
||||
import {
|
||||
createFetchRelated,
|
||||
createErrorHandler,
|
||||
createFaveStarHandlers,
|
||||
} from 'src/views/CRUD/utils';
|
||||
import ConfirmStatusChange from 'src/components/ConfirmStatusChange';
|
||||
import SubMenu from 'src/components/Menu/SubMenu';
|
||||
import Icon from 'src/components/Icon';
|
||||
import FaveStar from 'src/components/FaveStar';
|
||||
import ListView, { ListViewProps } from 'src/components/ListView/ListView';
|
||||
import {
|
||||
FetchDataConfig,
|
||||
|
|
@ -38,6 +43,7 @@ import PropertiesModal, { Slice } from 'src/explore/components/PropertiesModal';
|
|||
import Chart from 'src/types/Chart';
|
||||
|
||||
const PAGE_SIZE = 25;
|
||||
const FAVESTAR_BASE_URL = '/superset/favstar/slice';
|
||||
|
||||
interface Props {
|
||||
addDangerToast: (msg: string) => void;
|
||||
|
|
@ -48,6 +54,7 @@ interface State {
|
|||
bulkSelectEnabled: boolean;
|
||||
chartCount: number;
|
||||
charts: any[];
|
||||
favoriteStatus: object;
|
||||
lastFetchDataConfig: FetchDataConfig | null;
|
||||
loading: boolean;
|
||||
permissions: string[];
|
||||
|
|
@ -100,6 +107,7 @@ class ChartList extends React.PureComponent<Props, State> {
|
|||
bulkSelectEnabled: false,
|
||||
chartCount: 0,
|
||||
charts: [],
|
||||
favoriteStatus: {}, // Hash mapping dashboard id to 'isStarred' status
|
||||
lastFetchDataConfig: null,
|
||||
loading: true,
|
||||
permissions: [],
|
||||
|
|
@ -133,7 +141,31 @@ class ChartList extends React.PureComponent<Props, State> {
|
|||
|
||||
initialSort = [{ id: 'changed_on_delta_humanized', desc: true }];
|
||||
|
||||
fetchMethods = createFaveStarHandlers(
|
||||
FAVESTAR_BASE_URL,
|
||||
this,
|
||||
(message: string) => {
|
||||
this.props.addDangerToast(message);
|
||||
},
|
||||
);
|
||||
|
||||
columns = [
|
||||
{
|
||||
Cell: ({ row: { original } }: any) => {
|
||||
return (
|
||||
<FaveStar
|
||||
itemId={original.id}
|
||||
fetchFaveStar={this.fetchMethods.fetchFaveStar}
|
||||
saveFaveStar={this.fetchMethods.saveFaveStar}
|
||||
isStarred={!!this.state.favoriteStatus[original.id]}
|
||||
height={20}
|
||||
/>
|
||||
);
|
||||
},
|
||||
Header: '',
|
||||
id: 'favorite',
|
||||
disableSortBy: true,
|
||||
},
|
||||
{
|
||||
Cell: ({
|
||||
row: {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,11 @@ import { t } from '@superset-ui/translation';
|
|||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import rison from 'rison';
|
||||
import { createFetchRelated, createErrorHandler } from 'src/views/CRUD/utils';
|
||||
import {
|
||||
createFetchRelated,
|
||||
createErrorHandler,
|
||||
createFaveStarHandlers,
|
||||
} from 'src/views/CRUD/utils';
|
||||
import ConfirmStatusChange from 'src/components/ConfirmStatusChange';
|
||||
import SubMenu from 'src/components/Menu/SubMenu';
|
||||
import ListView, { ListViewProps } from 'src/components/ListView/ListView';
|
||||
|
|
@ -29,9 +33,11 @@ import ExpandableList from 'src/components/ExpandableList';
|
|||
import { FetchDataConfig, Filters } from 'src/components/ListView/types';
|
||||
import withToasts from 'src/messageToasts/enhancers/withToasts';
|
||||
import Icon from 'src/components/Icon';
|
||||
import FaveStar from 'src/components/FaveStar';
|
||||
import PropertiesModal from 'src/dashboard/components/PropertiesModal';
|
||||
|
||||
const PAGE_SIZE = 25;
|
||||
const FAVESTAR_BASE_URL = '/superset/favstar/Dashboard';
|
||||
|
||||
interface Props {
|
||||
addDangerToast: (msg: string) => void;
|
||||
|
|
@ -42,6 +48,7 @@ interface State {
|
|||
bulkSelectEnabled: boolean;
|
||||
dashboardCount: number;
|
||||
dashboards: any[];
|
||||
favoriteStatus: object;
|
||||
dashboardToEdit: Dashboard | null;
|
||||
lastFetchDataConfig: FetchDataConfig | null;
|
||||
loading: boolean;
|
||||
|
|
@ -68,6 +75,7 @@ class DashboardList extends React.PureComponent<Props, State> {
|
|||
bulkSelectEnabled: false,
|
||||
dashboardCount: 0,
|
||||
dashboards: [],
|
||||
favoriteStatus: {}, // Hash mapping dashboard id to 'isStarred' status
|
||||
dashboardToEdit: null,
|
||||
lastFetchDataConfig: null,
|
||||
loading: true,
|
||||
|
|
@ -105,7 +113,31 @@ class DashboardList extends React.PureComponent<Props, State> {
|
|||
|
||||
initialSort = [{ id: 'changed_on_delta_humanized', desc: true }];
|
||||
|
||||
fetchMethods = createFaveStarHandlers(
|
||||
FAVESTAR_BASE_URL,
|
||||
this,
|
||||
(message: string) => {
|
||||
this.props.addDangerToast(message);
|
||||
},
|
||||
);
|
||||
|
||||
columns = [
|
||||
{
|
||||
Cell: ({ row: { original } }: any) => {
|
||||
return (
|
||||
<FaveStar
|
||||
itemId={original.id}
|
||||
fetchFaveStar={this.fetchMethods.fetchFaveStar}
|
||||
saveFaveStar={this.fetchMethods.saveFaveStar}
|
||||
isStarred={!!this.state.favoriteStatus[original.id]}
|
||||
height={20}
|
||||
/>
|
||||
);
|
||||
},
|
||||
Header: '',
|
||||
id: 'favorite',
|
||||
disableSortBy: true,
|
||||
},
|
||||
{
|
||||
Cell: ({
|
||||
row: {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import {
|
|||
SupersetClient,
|
||||
SupersetClientResponse,
|
||||
} from '@superset-ui/connection';
|
||||
import { t } from '@superset-ui/translation';
|
||||
import rison from 'rison';
|
||||
import getClientErrorObject from 'src/utils/getClientErrorObject';
|
||||
|
||||
|
|
@ -59,3 +60,56 @@ export function createErrorHandler(handleErrorFunc: (errMsg?: string) => void) {
|
|||
handleErrorFunc(parsedError.message);
|
||||
};
|
||||
}
|
||||
|
||||
export function createFaveStarHandlers(
|
||||
baseURL: string,
|
||||
context: any,
|
||||
handleErrorFunc: (message: string) => void,
|
||||
) {
|
||||
const fetchFaveStar = (id: number) => {
|
||||
SupersetClient.get({
|
||||
endpoint: `${baseURL}/${id}/count/`,
|
||||
})
|
||||
.then(({ json }) => {
|
||||
const faves = {
|
||||
...context.state.favoriteStatus,
|
||||
};
|
||||
|
||||
faves[id] = json.count > 0;
|
||||
|
||||
context.setState({
|
||||
favoriteStatus: faves,
|
||||
});
|
||||
})
|
||||
.catch(() =>
|
||||
handleErrorFunc(t('There was an error fetching the favorite status')),
|
||||
);
|
||||
};
|
||||
|
||||
const saveFaveStar = (id: number, isStarred: boolean) => {
|
||||
const urlSuffix = isStarred ? 'unselect' : 'select';
|
||||
|
||||
SupersetClient.get({
|
||||
endpoint: `${baseURL}/${id}/${urlSuffix}/`,
|
||||
})
|
||||
.then(() => {
|
||||
const faves = {
|
||||
...context.state.favoriteStatus,
|
||||
};
|
||||
|
||||
faves[id] = !isStarred;
|
||||
|
||||
context.setState({
|
||||
favoriteStatus: faves,
|
||||
});
|
||||
})
|
||||
.catch(() =>
|
||||
handleErrorFunc(t('There was an error saving the favorite status')),
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
fetchFaveStar,
|
||||
saveFaveStar,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue