Commit 91fab7c4 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '285476-add-icons-to-trends-chart' into 'master'

Include toolbox for the trends chart

See merge request gitlab-org/gitlab!56316
parents 8b396589 9b4f5801
...@@ -3,6 +3,7 @@ import { GlLoadingIcon } from '@gitlab/ui'; ...@@ -3,6 +3,7 @@ import { GlLoadingIcon } from '@gitlab/ui';
import { GlLineChart } from '@gitlab/ui/dist/charts'; import { GlLineChart } from '@gitlab/ui/dist/charts';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { formatDate, getDateInPast } from '~/lib/utils/datetime_utility'; import { formatDate, getDateInPast } from '~/lib/utils/datetime_utility';
import { getSvgIconPathContent } from '~/lib/utils/icon_utils';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import projectsHistoryQuery from '../graphql/queries/project_vulnerabilities_by_day_and_count.query.graphql'; import projectsHistoryQuery from '../graphql/queries/project_vulnerabilities_by_day_and_count.query.graphql';
import { createProjectLoadingError } from '../helpers'; import { createProjectLoadingError } from '../helpers';
...@@ -68,6 +69,7 @@ export default { ...@@ -68,6 +69,7 @@ export default {
return { return {
chartWidth: 0, chartWidth: 0,
trendsByDay: [], trendsByDay: [],
svgs: {},
}; };
}, },
computed: { computed: {
...@@ -109,11 +111,8 @@ export default { ...@@ -109,11 +111,8 @@ export default {
shouldShowEmptyState() { shouldShowEmptyState() {
return !this.hasVulnerabilities; return !this.hasVulnerabilities;
}, },
}, chartOptions() {
mounted() { return {
this.chartWidth = this.$refs.layout.$el.clientWidth;
},
chartOptions: {
xAxis: { xAxis: {
name: __('Time'), name: __('Time'),
key: 'time', key: 'time',
...@@ -125,6 +124,37 @@ export default { ...@@ -125,6 +124,37 @@ export default {
type: 'value', type: 'value',
minInterval: 1, minInterval: 1,
}, },
toolbox: {
feature: {
dataZoom: {
icon: { zoom: this.svgs['marquee-selection'], back: this.svgs.redo },
},
restore: {
icon: this.svgs.repeat,
},
saveAsImage: {
icon: this.svgs.download,
},
},
},
};
},
},
mounted() {
this.chartWidth = this.$refs.layout.$el.clientWidth;
},
created() {
['marquee-selection', 'redo', 'repeat', 'download'].forEach(this.setSvg);
},
methods: {
async setSvg(name) {
try {
this.$set(this.svgs, name, `path://${await getSvgIconPathContent(name)}`);
} catch (e) {
// eslint-disable-next-line no-console, @gitlab/require-i18n-strings
console.error('SVG could not be rendered correctly: ', e);
}
},
}, },
}; };
</script> </script>
...@@ -139,7 +169,7 @@ export default { ...@@ -139,7 +169,7 @@ export default {
class="gl-mt-6" class="gl-mt-6"
:width="chartWidth" :width="chartWidth"
:data="dataSeries" :data="dataSeries"
:option="$options.chartOptions" :option="chartOptions"
:include-legend-avg-max="false" :include-legend-avg-max="false"
/> />
</template> </template>
......
---
title: Add toolbox for the trends chart in project security dashboard
merge_request: 56316
author:
type: added
...@@ -15,6 +15,10 @@ import { ...@@ -15,6 +15,10 @@ import {
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(VueApollo); localVue.use(VueApollo);
jest.mock('~/lib/utils/icon_utils', () => ({
getSvgIconPathContent: jest.fn().mockResolvedValue('mockSvgPathContent'),
}));
describe('Project Security Charts component', () => { describe('Project Security Charts component', () => {
let wrapper; let wrapper;
...@@ -87,13 +91,24 @@ describe('Project Security Charts component', () => { ...@@ -87,13 +91,24 @@ describe('Project Security Charts component', () => {
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
it('should display the chart with data', async () => { it('should display the chart with data', () => {
expect(findLineChart().props('data')).toMatchSnapshot(); expect(findLineChart().props('data')).toMatchSnapshot();
}); });
it('should not display the loading icon', () => { it('should not display the loading icon', () => {
expect(findLoadingIcon().exists()).toBe(false); expect(findLoadingIcon().exists()).toBe(false);
}); });
it.each([['restore'], ['saveAsImage']])('should contain %i icon', (icon) => {
const option = findLineChart().props('option').toolbox.feature;
expect(option[icon].icon).toBe('path://mockSvgPathContent');
});
it('contains dataZoom config', () => {
const option = findLineChart().props('option').toolbox.feature;
expect(option.dataZoom.icon.zoom).toBe('path://mockSvgPathContent');
expect(option.dataZoom.icon.back).toBe('path://mockSvgPathContent');
});
}); });
describe('when there is no history data', () => { describe('when there is no history data', () => {
......
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