[JENKINS-36968] fix a bug where multibranch pipelines that were favorited could not be unfavorited by toggling the "favorite" button in the favorites card to "off"
This commit is contained in:
parent
3227570ee9
commit
0624b7d416
|
@ -92,7 +92,7 @@ const extractPath = (path, begin, end) => {
|
|||
export class DashboardCards extends Component {
|
||||
|
||||
_onFavoriteToggle(isFavorite, favorite) {
|
||||
this.props.toggleFavorite(isFavorite, favorite.item);
|
||||
this.props.toggleFavorite(isFavorite, favorite.item, favorite);
|
||||
}
|
||||
|
||||
_renderCardStack() {
|
||||
|
|
|
@ -38,18 +38,21 @@ export class FavoritePipeline extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
_findMatchingFavorite(pipeline, favorites) {
|
||||
if (!pipeline || !favorites) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return favorites.find((fav) => {
|
||||
const favUrl = fav.item._links.self.href;
|
||||
const pipelineUrl = pipeline._links.self.href;
|
||||
return checkMatchingFavoriteUrls(favUrl, pipelineUrl);
|
||||
});
|
||||
}
|
||||
|
||||
_updateState(props) {
|
||||
const { pipeline } = props;
|
||||
let favorite = null;
|
||||
|
||||
if (props.favorites) {
|
||||
favorite = props.favorites.find((fav) => {
|
||||
const favUrl = fav.item._links.self.href;
|
||||
const pipelineUrl = pipeline._links.self.href;
|
||||
|
||||
return checkMatchingFavoriteUrls(favUrl, pipelineUrl);
|
||||
});
|
||||
}
|
||||
const favorite = this._findMatchingFavorite(pipeline, props.favorites);
|
||||
|
||||
this.setState({
|
||||
favorite: !!favorite,
|
||||
|
@ -62,8 +65,10 @@ export class FavoritePipeline extends Component {
|
|||
favorite: isFavorite,
|
||||
});
|
||||
|
||||
const favorite = this._findMatchingFavorite(this.props.pipeline, this.props.favorites);
|
||||
|
||||
if (this.props.toggleFavorite) {
|
||||
this.props.toggleFavorite(isFavorite, this.props.pipeline);
|
||||
this.props.toggleFavorite(isFavorite, this.props.pipeline, favorite);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,10 +78,14 @@ export const actions = {
|
|||
};
|
||||
},
|
||||
|
||||
toggleFavorite(addFavorite, branch) {
|
||||
toggleFavorite(addFavorite, branch, favoriteToRemove) {
|
||||
return (dispatch) => {
|
||||
const baseUrl = urlConfig.jenkinsRootURL;
|
||||
const url = `${baseUrl}${branch._links.self.href}/favorite`;
|
||||
|
||||
const url = addFavorite ?
|
||||
`${baseUrl}${branch._links.self.href}/favorite` :
|
||||
`${baseUrl}${favoriteToRemove._links.self.href}`;
|
||||
|
||||
const fetchOptions = {
|
||||
...defaultFetchOptions,
|
||||
method: 'PUT',
|
||||
|
|
Loading…
Reference in New Issue