Commit 16ac8dd6 authored by Clement Ho's avatar Clement Ho

Merge branch 'tr-upgrade-line-chart' into 'master'

Use gitlab-ui line chart for group security dashboard

See merge request gitlab-org/gitlab-ee!10479
parents 7901c08f 568f435a
<script> <script>
import _ from 'underscore';
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import { GlChart } from '@gitlab/ui/dist/charts'; import GlLineChart from '@gitlab/ui/dist/components/charts/line/line';
import { __ } from '~/locale'; import { __ } from '~/locale';
import ChartTooltip from './vulnerability_chart_tooltip.vue'; import ChartTooltip from './vulnerability_chart_tooltip.vue';
import ChartButtons from './vulnerability_chart_buttons.vue'; import ChartButtons from './vulnerability_chart_buttons.vue';
...@@ -12,7 +13,7 @@ import ResizableChartContainer from '~/vue_shared/components/resizable_chart/res ...@@ -12,7 +13,7 @@ import ResizableChartContainer from '~/vue_shared/components/resizable_chart/res
export default { export default {
name: 'VulnerabilityChart', name: 'VulnerabilityChart',
components: { components: {
GlChart, GlLineChart,
ChartTooltip, ChartTooltip,
ChartButtons, ChartButtons,
ResizableChartContainer, ResizableChartContainer,
...@@ -48,7 +49,6 @@ export default { ...@@ -48,7 +49,6 @@ export default {
...mapState('vulnerabilities', [ ...mapState('vulnerabilities', [
'vulnerabilitiesHistory', 'vulnerabilitiesHistory',
'vulnerabilitiesHistoryDayRange', 'vulnerabilitiesHistoryDayRange',
'vulnerabilitiesHistoryShowSplitLine',
'vulnerabilitiesHistoryMaxDayInterval', 'vulnerabilitiesHistoryMaxDayInterval',
]), ]),
...mapGetters('vulnerabilities', ['getFilteredVulnerabilitiesHistory']), ...mapGetters('vulnerabilities', ['getFilteredVulnerabilitiesHistory']),
...@@ -58,34 +58,26 @@ export default { ...@@ -58,34 +58,26 @@ export default {
const data = this.getFilteredVulnerabilitiesHistory(name); const data = this.getFilteredVulnerabilitiesHistory(name);
return { return {
borderWidth: 2,
color, color,
lineStyle: {
color,
},
data, data,
name, name,
symbol: 'circle',
symbolSize: 6,
type: 'line',
}; };
}); });
}, },
options() { options() {
return { return {
grid: { grid: {
bottom: 85, bottom: 70,
left: 75, left: 75,
right: 15, right: 15,
top: 10, top: 10,
}, },
tooltip: { tooltip: {
backgroundColor: '#fff',
borderColor: 'rgba(0, 0, 0, 0.1)',
borderWidth: 1,
confine: true,
formatter: this.renderTooltip, formatter: this.renderTooltip,
padding: 0, padding: 0,
textStyle: {
color: '#4F4F4F',
},
trigger: 'axis', trigger: 'axis',
}, },
xAxis: { xAxis: {
...@@ -93,45 +85,22 @@ export default { ...@@ -93,45 +85,22 @@ export default {
color: '#707070', color: '#707070',
formatter: date => dateFormat(date, 'd mmm'), formatter: date => dateFormat(date, 'd mmm'),
margin: 8, margin: 8,
rotate: 45,
},
axisLine: {
lineStyle: {
color: '#dedede',
width: 2,
},
},
splitLine: {
show: this.vulnerabilitiesHistoryShowSplitLine,
},
axisTick: {
show: false,
}, },
maxInterval: DAY_IN_MS * this.vulnerabilitiesHistoryMaxDayInterval, maxInterval: DAY_IN_MS * this.vulnerabilitiesHistoryMaxDayInterval,
min: Date.now() - DAY_IN_MS * this.vulnerabilitiesHistoryDayRange, min: Date.now() - DAY_IN_MS * this.vulnerabilitiesHistoryDayRange,
name: 'Date', name: 'Date',
nameGap: 50, nameGap: 35,
nameLocation: 'center', nameLocation: 'center',
nameTextStyle: { nameTextStyle: {
color: '#2e2e2e', color: '#2e2e2e',
fontWeight: 'bold', fontWeight: 'bold',
}, },
splitNumber: 12,
type: 'time', type: 'time',
}, },
yAxis: { yAxis: {
axisLabel: { axisLabel: {
color: '#707070', color: '#707070',
}, },
axisLine: {
lineStyle: {
color: '#dedede',
width: 2,
},
},
axisTick: {
show: false,
},
boundaryGap: [0, '5%'], boundaryGap: [0, '5%'],
name: 'Vulnerabilities', name: 'Vulnerabilities',
nameGap: 42, nameGap: 42,
...@@ -144,18 +113,6 @@ export default { ...@@ -144,18 +113,6 @@ export default {
minInterval: 1, minInterval: 1,
type: 'value', type: 'value',
}, },
legend: {
bottom: 0,
icon: 'path://M0,0H120V40H0Z',
itemGap: 15,
left: 70,
textStyle: {
color: '#4F4F4F',
fontWeight: 'bold',
},
type: 'scroll',
},
series: this.series,
}; };
}, },
days() { days() {
...@@ -165,10 +122,10 @@ export default { ...@@ -165,10 +122,10 @@ export default {
}, },
methods: { methods: {
...mapActions('vulnerabilities', ['setVulnerabilitiesHistoryDayRange']), ...mapActions('vulnerabilities', ['setVulnerabilitiesHistoryDayRange']),
renderTooltip(params, ticket, callback) { noop: _.noop, // Used to tell line-chart to render external tooltip
renderTooltip(params) {
this.tooltipTitle = dateFormat(params[0].axisValue, 'd mmmm'); this.tooltipTitle = dateFormat(params[0].axisValue, 'd mmmm');
this.tooltipEntries = params; this.tooltipEntries = params;
this.$nextTick(() => callback(ticket, this.$refs.tooltip.$el.innerHTML));
return ' '; return ' ';
}, },
}, },
...@@ -192,20 +149,18 @@ export default { ...@@ -192,20 +149,18 @@ export default {
<div class="vulnerabilities-chart"> <div class="vulnerabilities-chart">
<div class="vulnerabilities-chart-wrapper"> <div class="vulnerabilities-chart-wrapper">
<resizable-chart-container> <resizable-chart-container>
<gl-chart <gl-line-chart
slot-scope="{ width, height }" slot-scope="{ width }"
:options="options"
:width="width" :width="width"
:height="height" :option="options"
:disable-theme="true" :data="series"
/> :format-tooltip-text="noop"
:include-legend-avg-max="false"
>
<span slot="tooltipTitle">{{ tooltipTitle }}</span>
<chart-tooltip slot="tooltipContent" :entries="tooltipEntries" />
</gl-line-chart>
</resizable-chart-container> </resizable-chart-container>
<chart-tooltip
v-show="false"
ref="tooltip"
:title="tooltipTitle"
:entries="tooltipEntries"
/>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -7,11 +7,6 @@ export default { ...@@ -7,11 +7,6 @@ export default {
VulnerabilityChartLabel, VulnerabilityChartLabel,
}, },
props: { props: {
title: {
type: String,
required: false,
default: '',
},
entries: { entries: {
type: Array, type: Array,
required: true, required: true,
...@@ -21,11 +16,7 @@ export default { ...@@ -21,11 +16,7 @@ export default {
</script> </script>
<template> <template>
<div class="card"> <div>
<div class="card-header">
<strong> {{ title }} </strong>
</div>
<div class="card-body">
<vulnerability-chart-label <vulnerability-chart-label
v-for="entry in entries" v-for="entry in entries"
:key="entry.seriesId + entry.dataIndex" :key="entry.seriesId + entry.dataIndex"
...@@ -34,5 +25,4 @@ export default { ...@@ -34,5 +25,4 @@ export default {
:color="entry.color" :color="entry.color"
/> />
</div> </div>
</div>
</template> </template>
...@@ -44,11 +44,8 @@ export default { ...@@ -44,11 +44,8 @@ export default {
}, },
[types.SET_VULNERABILITIES_HISTORY_DAY_RANGE](state, days) { [types.SET_VULNERABILITIES_HISTORY_DAY_RANGE](state, days) {
state.vulnerabilitiesHistoryDayRange = days; state.vulnerabilitiesHistoryDayRange = days;
state.vulnerabilitiesHistoryShowSplitLine = days <= DAYS.THIRTY;
if (days <= DAYS.THIRTY) { if (days <= DAYS.THIRTY) {
state.vulnerabilitiesHistoryMaxDayInterval = 1;
} else if (days > DAYS.THIRTY && days <= DAYS.SIXTY) {
state.vulnerabilitiesHistoryMaxDayInterval = 7; state.vulnerabilitiesHistoryMaxDayInterval = 7;
} else if (days > DAYS.SIXTY) { } else if (days > DAYS.SIXTY) {
state.vulnerabilitiesHistoryMaxDayInterval = 14; state.vulnerabilitiesHistoryMaxDayInterval = 14;
......
...@@ -11,7 +11,6 @@ export default () => ({ ...@@ -11,7 +11,6 @@ export default () => ({
errorLoadingVulnerabilitiesHistory: false, errorLoadingVulnerabilitiesHistory: false,
vulnerabilitiesHistory: {}, vulnerabilitiesHistory: {},
vulnerabilitiesHistoryDayRange: 90, vulnerabilitiesHistoryDayRange: 90,
vulnerabilitiesHistoryShowSplitLine: false,
vulnerabilitiesHistoryMaxDayInterval: 7, vulnerabilitiesHistoryMaxDayInterval: 7,
pageInfo: {}, pageInfo: {},
vulnerabilitiesCountEndpoint: null, vulnerabilitiesCountEndpoint: null,
......
...@@ -3,4 +3,3 @@ $trans-white: rgba(255, 255, 255, 0); ...@@ -3,4 +3,3 @@ $trans-white: rgba(255, 255, 255, 0);
.vulnerabilities-chart-wrapper { .vulnerabilities-chart-wrapper {
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
} }
---
title: Upgrade group security dashboard to use gitlab-ui line chart
merge_request: 10479
author:
type: changed
...@@ -5,7 +5,6 @@ import mountComponent from 'spec/helpers/vue_mount_component_helper'; ...@@ -5,7 +5,6 @@ import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('Vulnerability Chart Tooltip component', () => { describe('Vulnerability Chart Tooltip component', () => {
const Component = Vue.extend(component); const Component = Vue.extend(component);
const props = { const props = {
title: 'Tooltip Title',
entries: [ entries: [
{ {
dataIndex: 1, dataIndex: 1,
...@@ -40,12 +39,6 @@ describe('Vulnerability Chart Tooltip component', () => { ...@@ -40,12 +39,6 @@ describe('Vulnerability Chart Tooltip component', () => {
vm.$destroy(); vm.$destroy();
}); });
it('should render the title', () => {
const header = vm.$el.querySelector('.card-header');
expect(header.textContent).toContain(props.title);
});
it('should render three legends', () => { it('should render three legends', () => {
const legends = vm.$el.querySelectorAll('.js-chart-label'); const legends = vm.$el.querySelectorAll('.js-chart-label');
......
...@@ -216,29 +216,9 @@ describe('vulnerabilities module mutations', () => { ...@@ -216,29 +216,9 @@ describe('vulnerabilities module mutations', () => {
expect(state.vulnerabilitiesHistoryDayRange).toEqual(DAYS.THIRTY); expect(state.vulnerabilitiesHistoryDayRange).toEqual(DAYS.THIRTY);
}); });
it('should set the vulnerabilitiesHistoryShowSplitLine to true if 30 days or under', () => { it('should set the vulnerabilitiesHistoryMaxDayInterval to 7 if days are 60 and under', () => {
mutations[types.SET_VULNERABILITIES_HISTORY_DAY_RANGE](state, DAYS.THIRTY); mutations[types.SET_VULNERABILITIES_HISTORY_DAY_RANGE](state, DAYS.THIRTY);
expect(state.vulnerabilitiesHistoryShowSplitLine).toEqual(true);
});
it('should set the vulnerabilitiesHistoryShowSplitLine to false if 30 days or over', () => {
mutations[types.SET_VULNERABILITIES_HISTORY_DAY_RANGE](state, DAYS.SIXTY);
expect(state.vulnerabilitiesHistoryShowSplitLine).toEqual(false);
});
it('should set the vulnerabilitiesHistoryMaxDayInterval to 1 if days are 30 and under', () => {
mutations[types.SET_VULNERABILITIES_HISTORY_DAY_RANGE](state, DAYS.THIRTY);
expect(state.vulnerabilitiesHistoryMaxDayInterval).toEqual(1);
});
it('should set the vulnerabilitiesHistoryMaxDayInterval to 7 if between 30 and 60', () => {
const days = 45;
mutations[types.SET_VULNERABILITIES_HISTORY_DAY_RANGE](state, days);
expect(state.vulnerabilitiesHistoryMaxDayInterval).toEqual(7); expect(state.vulnerabilitiesHistoryMaxDayInterval).toEqual(7);
}); });
......
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