Commit c64a7bc2 authored by Dhiraj Bodicherla's avatar Dhiraj Bodicherla

Update metrics dashboard favorite logic

Reduce the usage of getters in metrics
dashboard workflow of starring a dashboard
parent a1fc9259
......@@ -369,7 +369,7 @@ export const toggleStarredValue = ({ commit, state, getters }) => {
method,
})
.then(() => {
commit(types.RECEIVE_DASHBOARD_STARRING_SUCCESS, newStarredValue);
commit(types.RECEIVE_DASHBOARD_STARRING_SUCCESS, { selectedDashboard, newStarredValue });
})
.catch(() => {
commit(types.RECEIVE_DASHBOARD_STARRING_FAILURE);
......
import Vue from 'vue';
import { pick } from 'lodash';
import * as types from './mutation_types';
import { selectedDashboard } from './getters';
import { mapToDashboardViewModel, normalizeQueryResult } from './utils';
import { BACKOFF_TIMEOUT } from '../../lib/utils/common_utils';
import { endpointKeys, initialStateKeys, metricStates } from '../constants';
......@@ -82,15 +81,14 @@ export default {
[types.REQUEST_DASHBOARD_STARRING](state) {
state.isUpdatingStarredValue = true;
},
[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](state, newStarredValue) {
const dashboard = selectedDashboard(state);
const index = state.allDashboards.findIndex(d => d === dashboard);
[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](state, { selectedDashboard, newStarredValue }) {
const index = state.allDashboards.findIndex(d => d === selectedDashboard);
state.isUpdatingStarredValue = false;
// Trigger state updates in the reactivity system for this change
// https://vuejs.org/v2/guide/reactivity.html#For-Arrays
Vue.set(state.allDashboards, index, { ...dashboard, starred: newStarredValue });
Vue.set(state.allDashboards, index, { ...selectedDashboard, starred: newStarredValue });
},
[types.RECEIVE_DASHBOARD_STARRING_FAILURE](state) {
state.isUpdatingStarredValue = false;
......
......@@ -361,7 +361,13 @@ describe('Monitoring store actions', () => {
return testAction(toggleStarredValue, null, state, [
{ type: types.REQUEST_DASHBOARD_STARRING },
{ type: types.RECEIVE_DASHBOARD_STARRING_SUCCESS, payload: true },
{
type: types.RECEIVE_DASHBOARD_STARRING_SUCCESS,
payload: {
newStarredValue: true,
selectedDashboard: unstarredDashboard,
},
},
]);
});
......
......@@ -93,14 +93,20 @@ describe('Monitoring mutations', () => {
});
it('sets a dashboard as starred', () => {
mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, true);
mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, {
selectedDashboard: stateCopy.allDashboards[1],
newStarredValue: true,
});
expect(stateCopy.isUpdatingStarredValue).toBe(false);
expect(stateCopy.allDashboards[1].starred).toBe(true);
});
it('sets a dashboard as unstarred', () => {
mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, false);
mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, {
selectedDashboard: stateCopy.allDashboards[1],
newStarredValue: false,
});
expect(stateCopy.isUpdatingStarredValue).toBe(false);
expect(stateCopy.allDashboards[1].starred).toBe(false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment