[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 {
|
export class DashboardCards extends Component {
|
||||||
|
|
||||||
_onFavoriteToggle(isFavorite, favorite) {
|
_onFavoriteToggle(isFavorite, favorite) {
|
||||||
this.props.toggleFavorite(isFavorite, favorite.item);
|
this.props.toggleFavorite(isFavorite, favorite.item, favorite);
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderCardStack() {
|
_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) {
|
_updateState(props) {
|
||||||
const { pipeline } = props;
|
const { pipeline } = props;
|
||||||
let favorite = null;
|
const favorite = this._findMatchingFavorite(pipeline, props.favorites);
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
favorite: !!favorite,
|
favorite: !!favorite,
|
||||||
|
@ -62,8 +65,10 @@ export class FavoritePipeline extends Component {
|
||||||
favorite: isFavorite,
|
favorite: isFavorite,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const favorite = this._findMatchingFavorite(this.props.pipeline, this.props.favorites);
|
||||||
|
|
||||||
if (this.props.toggleFavorite) {
|
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) => {
|
return (dispatch) => {
|
||||||
const baseUrl = urlConfig.jenkinsRootURL;
|
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 = {
|
const fetchOptions = {
|
||||||
...defaultFetchOptions,
|
...defaultFetchOptions,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
|
Loading…
Reference in New Issue