[JENKINS-36582] add store logic to update the favorite cards' job status in real time
This commit is contained in:
parent
93a0968449
commit
de36bfab87
|
@ -21,8 +21,13 @@ export const ACTION_TYPES = keymirror({
|
|||
SET_USER: null,
|
||||
SET_FAVORITES: null,
|
||||
TOGGLE_FAVORITE: null,
|
||||
UPDATE_RUN: null,
|
||||
});
|
||||
|
||||
function clone(json) {
|
||||
return JSON.parse(JSON.stringify(json));
|
||||
}
|
||||
|
||||
const actionHandlers = {
|
||||
[ACTION_TYPES.SET_USER](state, { payload }) {
|
||||
const user = new User(payload);
|
||||
|
@ -52,6 +57,26 @@ const actionHandlers = {
|
|||
|
||||
return state.set('favorites', prunedList);
|
||||
},
|
||||
[ACTION_TYPES.UPDATE_RUN](state, { jobRun }) {
|
||||
const favorites = state.get('favorites');
|
||||
|
||||
for (const fav of favorites) {
|
||||
const runsBaseUrl = `${fav.item._links.self.href}runs`;
|
||||
const runUrl = jobRun._links.self.href;
|
||||
|
||||
// TODO; this might be broken for non-multibranch as the URL structures are different
|
||||
if (runUrl.indexOf(runsBaseUrl) === 0) {
|
||||
const index = favorites.indexOf(fav);
|
||||
const updatedFavorite = clone(fav);
|
||||
updatedFavorite.item.latestRun = jobRun;
|
||||
const updatedFavorites = favorites.set(index, updatedFavorite);
|
||||
return state.set('favorites', updatedFavorites);
|
||||
}
|
||||
}
|
||||
|
||||
console.warn('run was not updated; likely an error?');
|
||||
return state;
|
||||
},
|
||||
};
|
||||
|
||||
const favoritesStore = state => state.favoritesStore;
|
||||
|
|
Loading…
Reference in New Issue