Commit b6a5ccc4 authored by Mark Fletcher's avatar Mark Fletcher

Allow chart descriptions for Insights

- A `description` field can now be added to the configuration to
  describe the chart in question
- This field is not required so previous configuration without a
  `description` will work as normal
parent 9d17fe16
---
title: Allow chart descriptions for Insights
merge_request: 25686
author:
type: added
...@@ -61,6 +61,7 @@ bugsCharts: ...@@ -61,6 +61,7 @@ bugsCharts:
title: "Charts for bugs" title: "Charts for bugs"
charts: charts:
- title: "Monthly bugs created" - title: "Monthly bugs created"
description: "Open bugs created per month"
type: bar type: bar
query: query:
issuable_type: issue issuable_type: issue
...@@ -77,6 +78,7 @@ For example, here's single chart definition: ...@@ -77,6 +78,7 @@ For example, here's single chart definition:
```yaml ```yaml
- title: "Monthly bugs created" - title: "Monthly bugs created"
description: "Open bugs created per month"
type: bar type: bar
query: query:
issuable_type: issue issuable_type: issue
...@@ -96,6 +98,7 @@ The following table lists available parameters for charts: ...@@ -96,6 +98,7 @@ The following table lists available parameters for charts:
| Keyword | Description | | Keyword | Description |
|:---------------------------------------------------|:------------| |:---------------------------------------------------|:------------|
| [`title`](#title) | The title of the chart. This will displayed on the Insights page. | | [`title`](#title) | The title of the chart. This will displayed on the Insights page. |
| [`description`](#description) | A description for the individual chart. This will be displayed above the relevant chart. |
| [`type`](#type) | The type of chart: `bar`, `line` or `stacked-bar`. | | [`type`](#type) | The type of chart: `bar`, `line` or `stacked-bar`. |
| [`query`](#query) | A hash that defines the conditions for issues / merge requests to be part of the chart. | | [`query`](#query) | A hash that defines the conditions for issues / merge requests to be part of the chart. |
...@@ -114,6 +117,17 @@ monthlyBugsCreated: ...@@ -114,6 +117,17 @@ monthlyBugsCreated:
title: "Monthly bugs created" title: "Monthly bugs created"
``` ```
### `description`
The `description` text is displayed above the chart, but below the title. It's used
to give extra details regarding the chart, for example:
```yaml
monthlyBugsCreated:
title: "Monthly bugs created"
description: "Open bugs created per month"
```
### `type` ### `type`
`type` is the chart type. `type` is the chart type.
...@@ -145,6 +159,7 @@ Example: ...@@ -145,6 +159,7 @@ Example:
```yaml ```yaml
monthlyBugsCreated: monthlyBugsCreated:
title: "Monthly bugs created" title: "Monthly bugs created"
description: "Open bugs created per month"
type: bar type: bar
query: query:
issuable_type: issue issuable_type: issue
...@@ -283,6 +298,7 @@ a group's insights: ...@@ -283,6 +298,7 @@ a group's insights:
```yaml ```yaml
monthlyBugsCreated: monthlyBugsCreated:
title: "Monthly bugs created" title: "Monthly bugs created"
description: "Open bugs created per month"
type: bar type: bar
query: query:
issuable_type: issue issuable_type: issue
...@@ -311,6 +327,7 @@ bugsCharts: ...@@ -311,6 +327,7 @@ bugsCharts:
title: "Charts for bugs" title: "Charts for bugs"
charts: charts:
- title: "Monthly bugs created" - title: "Monthly bugs created"
description: "Open bugs created per month"
type: bar type: bar
<<: *projectsOnly <<: *projectsOnly
query: query:
......
...@@ -31,6 +31,11 @@ export default { ...@@ -31,6 +31,11 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
description: {
type: String,
required: false,
default: '',
},
data: { data: {
type: Object, type: Object,
required: true, required: true,
...@@ -111,6 +116,7 @@ export default { ...@@ -111,6 +116,7 @@ export default {
<template> <template>
<resizable-chart-container v-if="loaded" class="insights-chart"> <resizable-chart-container v-if="loaded" class="insights-chart">
<h5 class="text-center">{{ title }}</h5> <h5 class="text-center">{{ title }}</h5>
<p v-if="description" class="text-center">{{ description }}</p>
<gl-column-chart <gl-column-chart
v-if="isColumnChart" v-if="isColumnChart"
v-bind="$attrs" v-bind="$attrs"
......
...@@ -76,11 +76,12 @@ export default { ...@@ -76,11 +76,12 @@ export default {
<h4 class="text-center">{{ pageConfig.title }}</h4> <h4 class="text-center">{{ pageConfig.title }}</h4>
<div v-if="!pageLoading" class="insights-charts" data-qa-selector="insights_charts"> <div v-if="!pageLoading" class="insights-charts" data-qa-selector="insights_charts">
<insights-chart <insights-chart
v-for="({ loaded, type, data, error }, key, index) in chartData" v-for="({ loaded, type, description, data, error }, key, index) in chartData"
:key="index" :key="index"
:loaded="loaded" :loaded="loaded"
:type="type" :type="type"
:title="key" :title="key"
:description="description"
:data="data" :data="data"
:error="error" :error="error"
/> />
......
...@@ -21,10 +21,11 @@ export default { ...@@ -21,10 +21,11 @@ export default {
}, },
[types.RECEIVE_CHART_SUCCESS](state, { chart, data }) { [types.RECEIVE_CHART_SUCCESS](state, { chart, data }) {
const { type } = chart; const { type, description } = chart;
state.chartData[chart.title] = { state.chartData[chart.title] = {
type, type,
description,
data: transformChartDataForGlCharts(chart, data), data: transformChartDataForGlCharts(chart, data),
loaded: true, loaded: true,
}; };
......
...@@ -10,6 +10,7 @@ describe('Insights mutations', () => { ...@@ -10,6 +10,7 @@ describe('Insights mutations', () => {
const chart = { const chart = {
title: 'Bugs Per Team', title: 'Bugs Per Team',
type: CHART_TYPES.STACKED_BAR, type: CHART_TYPES.STACKED_BAR,
description: 'Chart Description',
query: { query: {
name: 'filter_issues_by_label_category', name: 'filter_issues_by_label_category',
filter_label: 'bug', filter_label: 'bug',
...@@ -136,6 +137,14 @@ describe('Insights mutations', () => { ...@@ -136,6 +137,14 @@ describe('Insights mutations', () => {
expect(chartData[chart.title].type).toBe(chart.type); expect(chartData[chart.title].type).toBe(chart.type);
}); });
it('sets charts description to incoming type on success', () => {
mutations[types.RECEIVE_CHART_SUCCESS](state, { chart, data: incomingData });
const { chartData } = state;
expect(chartData[chart.title].description).toBe(chart.description);
});
}); });
describe(types.RECEIVE_CHART_ERROR, () => { describe(types.RECEIVE_CHART_ERROR, () => {
......
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