-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
[explore-v2] add fave star and edit button to chart header #1623
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { PropTypes } from 'react'; | ||
import cx from 'classnames'; | ||
import TooltipWrapper from './TooltipWrapper'; | ||
|
||
const propTypes = { | ||
sliceId: PropTypes.string.isRequired, | ||
actions: PropTypes.object.isRequired, | ||
isStarred: PropTypes.bool.isRequired, | ||
}; | ||
|
||
export default class FaveStar extends React.Component { | ||
componentDidMount() { | ||
this.props.actions.fetchFaveStar(this.props.sliceId); | ||
} | ||
|
||
onClick(e) { | ||
e.preventDefault(); | ||
this.props.actions.saveFaveStar(this.props.sliceId, 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="Click to favorite/unfavorite" | ||
> | ||
<a | ||
href="#" | ||
onClick={this.onClick.bind(this)} | ||
className="fave-unfave-icon" | ||
> | ||
<i className={iconClassNames} /> | ||
</a> | ||
</TooltipWrapper> | ||
); | ||
} | ||
} | ||
|
||
FaveStar.propTypes = propTypes; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { Tooltip, OverlayTrigger } from 'react-bootstrap'; | ||
import { slugify } from '../modules/utils'; | ||
|
||
const propTypes = { | ||
label: PropTypes.string.isRequired, | ||
tooltip: PropTypes.string.isRequired, | ||
children: PropTypes.node.isRequired, | ||
placement: PropTypes.string, | ||
}; | ||
|
||
const defaultProps = { | ||
placement: 'top', | ||
}; | ||
|
||
export default function TooltipWrapper({ label, tooltip, children, placement }) { | ||
return ( | ||
<OverlayTrigger | ||
placement={placement} | ||
overlay={<Tooltip id={`${slugify(label)}-tooltip`}>{tooltip}</Tooltip>} | ||
> | ||
{children} | ||
</OverlayTrigger> | ||
); | ||
} | ||
|
||
TooltipWrapper.propTypes = propTypes; | ||
TooltipWrapper.defaultProps = defaultProps; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
/* eslint camelcase: 0 */ | ||
const $ = window.$ = require('jquery'); | ||
|
||
const FAVESTAR_BASE_URL = '/superset/favstar/slice'; | ||
|
||
export const SET_FIELD_OPTIONS = 'SET_FIELD_OPTIONS'; | ||
export function setFieldOptions(options) { | ||
return { type: SET_FIELD_OPTIONS, options }; | ||
|
@@ -48,6 +51,33 @@ export function fetchFieldOptions(datasourceId, datasourceType) { | |
}; | ||
} | ||
|
||
export const TOGGLE_FAVE_STAR = 'TOGGLE_FAVE_STAR'; | ||
export function toggleFaveStar(isStarred) { | ||
return { type: TOGGLE_FAVE_STAR, isStarred }; | ||
} | ||
|
||
export const FETCH_FAVE_STAR = 'FETCH_FAVE_STAR'; | ||
export function fetchFaveStar(sliceId) { | ||
return function (dispatch) { | ||
const url = `${FAVESTAR_BASE_URL}/${sliceId}/count`; | ||
$.get(url, (data) => { | ||
if (data.count > 0) { | ||
dispatch(toggleFaveStar(true)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. codeclimate says: "toggleFaveStar" was used before it was defined |
||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. codeclimate says: Missing semicolon. |
||
}; | ||
} | ||
|
||
export const SAVE_FAVE_STAR = 'SAVE_FAVE_STAR'; | ||
export function saveFaveStar(sliceId, isStarred) { | ||
return function (dispatch) { | ||
const urlSuffix = isStarred ? 'unselect' : 'select'; | ||
const url = `${FAVESTAR_BASE_URL}/${sliceId}/${urlSuffix}/`; | ||
$.get(url); | ||
dispatch(toggleFaveStar(!isStarred)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. codeclimate says: "toggleFaveStar" was used before it was defined |
||
}; | ||
} | ||
|
||
export const ADD_FILTER = 'ADD_FILTER'; | ||
export function addFilter(filter) { | ||
return { type: ADD_FILTER, filter }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious, what is default behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we are using an
<a href="#">
here, we want to stop the default behaviour of the browser following the href path, in this case just adding#
to the url.https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault