Commit 0b3299f6 authored by Jose Vargas's avatar Jose Vargas

Change the name of utility functions

Also changed the way the variables array
is constructed, the format allows to use
`flat` without requiring any external
libraries
parent 1baf2f0c
...@@ -38,7 +38,7 @@ import { ...@@ -38,7 +38,7 @@ import {
timeRangeFromUrl, timeRangeFromUrl,
panelToUrl, panelToUrl,
expandedPanelPayloadFromUrl, expandedPanelPayloadFromUrl,
customVariablesFromUrl, promCustomVariablesFromUrl,
} from '../utils'; } from '../utils';
import { metricStates } from '../constants'; import { metricStates } from '../constants';
import { defaultTimeRange, timeRanges } from '~/vue_shared/constants'; import { defaultTimeRange, timeRanges } from '~/vue_shared/constants';
...@@ -283,7 +283,7 @@ export default { ...@@ -283,7 +283,7 @@ export default {
this.setGettingStartedEmptyState(); this.setGettingStartedEmptyState();
} else { } else {
this.setTimeRange(this.selectedTimeRange); this.setTimeRange(this.selectedTimeRange);
this.setVariables(customVariablesFromUrl()); this.setVariables(promCustomVariablesFromUrl());
this.fetchData(); this.fetchData();
} }
}, },
......
...@@ -81,7 +81,7 @@ export const setTimeRange = ({ commit }, timeRange) => { ...@@ -81,7 +81,7 @@ export const setTimeRange = ({ commit }, timeRange) => {
}; };
export const setVariables = ({ commit }, variables) => { export const setVariables = ({ commit }, variables) => {
commit(types.SET_QUERY_VARIABLES, variables); commit(types.SET_PROM_QUERY_VARIABLES, variables);
}; };
export const filterEnvironments = ({ commit, dispatch }, searchTerm) => { export const filterEnvironments = ({ commit, dispatch }, searchTerm) => {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
export const REQUEST_METRICS_DASHBOARD = 'REQUEST_METRICS_DASHBOARD'; export const REQUEST_METRICS_DASHBOARD = 'REQUEST_METRICS_DASHBOARD';
export const RECEIVE_METRICS_DASHBOARD_SUCCESS = 'RECEIVE_METRICS_DASHBOARD_SUCCESS'; export const RECEIVE_METRICS_DASHBOARD_SUCCESS = 'RECEIVE_METRICS_DASHBOARD_SUCCESS';
export const RECEIVE_METRICS_DASHBOARD_FAILURE = 'RECEIVE_METRICS_DASHBOARD_FAILURE'; export const RECEIVE_METRICS_DASHBOARD_FAILURE = 'RECEIVE_METRICS_DASHBOARD_FAILURE';
export const SET_QUERY_VARIABLES = 'SET_QUERY_VARIABLES'; export const SET_PROM_QUERY_VARIABLES = 'SET_PROM_QUERY_VARIABLES';
// Annotations // Annotations
export const RECEIVE_ANNOTATIONS_SUCCESS = 'RECEIVE_ANNOTATIONS_SUCCESS'; export const RECEIVE_ANNOTATIONS_SUCCESS = 'RECEIVE_ANNOTATIONS_SUCCESS';
......
...@@ -58,19 +58,10 @@ const emptyStateFromError = error => { ...@@ -58,19 +58,10 @@ const emptyStateFromError = error => {
* @param {Object} variables - Custom variables provided by the user * @param {Object} variables - Custom variables provided by the user
*/ */
const transformVariablesObjectArray = variables => { const transformVariablesObjectArray = variables =>
let variablesArr = []; Object.entries(variables)
const variablesKeys = Object.keys(variables); .flat()
.map(encodeURIComponent);
variablesArr = variablesKeys.reduce((acc, key) => {
acc.push(key);
acc.push(`${key}_${variables[key]}`);
return acc;
}, []);
return variablesArr;
};
export default { export default {
/** /**
...@@ -190,7 +181,7 @@ export default { ...@@ -190,7 +181,7 @@ export default {
state.expandedPanel.group = group; state.expandedPanel.group = group;
state.expandedPanel.panel = panel; state.expandedPanel.panel = panel;
}, },
[types.SET_QUERY_VARIABLES](state, variables) { [types.SET_PROM_QUERY_VARIABLES](state, variables) {
state.promVariables = transformVariablesObjectArray(variables); state.promVariables = transformVariablesObjectArray(variables);
}, },
}; };
...@@ -127,7 +127,7 @@ export const timeRangeFromUrl = (search = window.location.search) => { ...@@ -127,7 +127,7 @@ export const timeRangeFromUrl = (search = window.location.search) => {
* @param {String} New URL * @param {String} New URL
*/ */
export const customVariablesFromUrl = (search = window.location.search) => { export const promCustomVariablesFromUrl = (search = window.location.search) => {
const params = queryToObject(search); const params = queryToObject(search);
const paramsToRemove = timeRangeParamNames.concat(dashboardParams); const paramsToRemove = timeRangeParamNames.concat(dashboardParams);
......
...@@ -399,14 +399,14 @@ describe('Monitoring store actions', () => { ...@@ -399,14 +399,14 @@ describe('Monitoring store actions', () => {
beforeEach(() => { beforeEach(() => {
mockedState = storeState(); mockedState = storeState();
}); });
it('should commit SET_QUERY_VARIABLES mutation', done => { it('should commit SET_PROM_QUERY_VARIABLES mutation', done => {
testAction( testAction(
setVariables, setVariables,
{ pod: 'POD' }, { pod: 'POD' },
mockedState, mockedState,
[ [
{ {
type: types.SET_QUERY_VARIABLES, type: types.SET_PROM_QUERY_VARIABLES,
payload: { pod: 'POD' }, payload: { pod: 'POD' },
}, },
], ],
......
...@@ -365,17 +365,17 @@ describe('Monitoring mutations', () => { ...@@ -365,17 +365,17 @@ describe('Monitoring mutations', () => {
}); });
}); });
describe('SET_QUERY_VARIABLES', () => { describe('SET_PROM_QUERY_VARIABLES', () => {
it('stores an empty variables array when no custom variables are given', () => { it('stores an empty variables array when no custom variables are given', () => {
mutations[types.SET_QUERY_VARIABLES](stateCopy, {}); mutations[types.SET_PROM_QUERY_VARIABLES](stateCopy, {});
expect(stateCopy.promVariables).toEqual([]); expect(stateCopy.promVariables).toEqual([]);
}); });
it('stores variables in the key key_value format in the array', () => { it('stores variables in the key key_value format in the array', () => {
mutations[types.SET_QUERY_VARIABLES](stateCopy, { pod: 'POD' }); mutations[types.SET_PROM_QUERY_VARIABLES](stateCopy, { pod: 'POD' });
expect(stateCopy.promVariables).toEqual(['pod', 'pod_POD']); expect(stateCopy.promVariables).toEqual(['pod', 'POD']);
}); });
}); });
}); });
...@@ -169,8 +169,8 @@ describe('monitoring/utils', () => { ...@@ -169,8 +169,8 @@ describe('monitoring/utils', () => {
}); });
}); });
describe('customVariablesFromUrl', () => { describe('promCustomVariablesFromUrl', () => {
const { customVariablesFromUrl } = monitoringUtils; const { promCustomVariablesFromUrl } = monitoringUtils;
it('returns an object with only the custom variables', () => { it('returns an object with only the custom variables', () => {
queryToObject.mockReturnValueOnce({ queryToObject.mockReturnValueOnce({
...@@ -178,7 +178,7 @@ describe('monitoring/utils', () => { ...@@ -178,7 +178,7 @@ describe('monitoring/utils', () => {
pod: 'POD', pod: 'POD',
}); });
expect(customVariablesFromUrl()).toEqual(expect.objectContaining({ pod: 'POD' })); expect(promCustomVariablesFromUrl()).toEqual(expect.objectContaining({ pod: 'POD' }));
}); });
it('returns an empty object when no custom variables are present', () => { it('returns an empty object when no custom variables are present', () => {
...@@ -188,7 +188,7 @@ describe('monitoring/utils', () => { ...@@ -188,7 +188,7 @@ describe('monitoring/utils', () => {
param2: 'value2', param2: 'value2',
}; };
expect(customVariablesFromUrl(params, mockPath)).toStrictEqual({}); expect(promCustomVariablesFromUrl(params, mockPath)).toStrictEqual({});
}); });
}); });
......
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