Commit bc6b04f1 authored by Mark Fletcher's avatar Mark Fletcher

Only display page config with valid values

- YAML anchors could interfere with the dropdown list
- Remove keys with values that don't have title and charts field
parent 537dd779
import _ from 'underscore';
import * as types from './mutation_types'; import * as types from './mutation_types';
export default { export default {
...@@ -6,7 +7,12 @@ export default { ...@@ -6,7 +7,12 @@ export default {
state.configLoading = true; state.configLoading = true;
}, },
[types.RECEIVE_CONFIG_SUCCESS](state, data) { [types.RECEIVE_CONFIG_SUCCESS](state, data) {
state.configData = data; const validConfig = _.pick(
data,
Object.keys(data).filter(key => data[key].title && data[key].charts),
);
state.configData = validConfig;
state.configLoading = false; state.configLoading = false;
}, },
[types.RECEIVE_CONFIG_ERROR](state) { [types.RECEIVE_CONFIG_ERROR](state) {
......
---
title: 'Insights: Only display page config with valid values'
merge_request:
author:
type: fixed
import createState from 'ee/insights/stores/modules/insights/state'; import createState from 'ee/insights/stores/modules/insights/state';
import mutations from 'ee/insights/stores/modules/insights/mutations'; import mutations from 'ee/insights/stores/modules/insights/mutations';
import * as types from 'ee/insights/stores/modules/insights/mutation_types'; import * as types from 'ee/insights/stores/modules/insights/mutation_types';
import { configData } from '../../../../javascripts/insights/mock_data';
describe('Insights mutations', () => { describe('Insights mutations', () => {
let state; let state;
...@@ -33,22 +34,19 @@ describe('Insights mutations', () => { ...@@ -33,22 +34,19 @@ describe('Insights mutations', () => {
}); });
describe(types.RECEIVE_CONFIG_SUCCESS, () => { describe(types.RECEIVE_CONFIG_SUCCESS, () => {
const data = [
{
key: 'chart',
},
];
it('sets configLoading state to false on success', () => { it('sets configLoading state to false on success', () => {
mutations[types.RECEIVE_CONFIG_SUCCESS](state, data); mutations[types.RECEIVE_CONFIG_SUCCESS](state, configData);
expect(state.configLoading).toBe(false); expect(state.configLoading).toBe(false);
}); });
it('sets configData state to incoming data on success', () => { it('sets configData state to incoming data on success', () => {
mutations[types.RECEIVE_CONFIG_SUCCESS](state, data); mutations[types.RECEIVE_CONFIG_SUCCESS](state, configData);
const expected = Object.assign({}, configData);
delete expected.invalid;
expect(state.configData).toBe(data); expect(state.configData).toEqual(expected);
}); });
}); });
......
...@@ -36,3 +36,10 @@ export const pageInfoNoCharts = { ...@@ -36,3 +36,10 @@ export const pageInfoNoCharts = {
title: 'Page No Charts', title: 'Page No Charts',
}, },
}; };
export const configData = {
example: pageInfo,
invalid: {
key: 'key',
},
};
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