Commit 0aff1987 authored by Brandon Labuschagne's avatar Brandon Labuschagne Committed by Fatih Acet

Add limit to daterange component

This commit adds a range limit to the shared analytics
daterange component.

It also adds a date range indicator which displays the
number of days in the currently selected range.
parent 4d2f9137
...@@ -8,7 +8,7 @@ import { PROJECTS_PER_PAGE, DEFAULT_DAYS_IN_PAST } from '../constants'; ...@@ -8,7 +8,7 @@ import { PROJECTS_PER_PAGE, DEFAULT_DAYS_IN_PAST } from '../constants';
import GroupsDropdownFilter from '../../shared/components/groups_dropdown_filter.vue'; import GroupsDropdownFilter from '../../shared/components/groups_dropdown_filter.vue';
import ProjectsDropdownFilter from '../../shared/components/projects_dropdown_filter.vue'; import ProjectsDropdownFilter from '../../shared/components/projects_dropdown_filter.vue';
import Scatterplot from '../../shared/components/scatterplot.vue'; import Scatterplot from '../../shared/components/scatterplot.vue';
import { LAST_ACTIVITY_AT, dateFormats } from '../../shared/constants'; import { LAST_ACTIVITY_AT, dateFormats, DATE_RANGE_LIMIT } from '../../shared/constants';
import DateRange from '../../shared/components/daterange.vue'; import DateRange from '../../shared/components/daterange.vue';
import StageDropdownFilter from './stage_dropdown_filter.vue'; import StageDropdownFilter from './stage_dropdown_filter.vue';
import SummaryTable from './summary_table.vue'; import SummaryTable from './summary_table.vue';
...@@ -195,6 +195,7 @@ export default { ...@@ -195,6 +195,7 @@ export default {
order_by: LAST_ACTIVITY_AT, order_by: LAST_ACTIVITY_AT,
}, },
durationChartTooltipDateFormat: dateFormats.defaultDate, durationChartTooltipDateFormat: dateFormats.defaultDate,
maxDateRange: DATE_RANGE_LIMIT,
}; };
</script> </script>
...@@ -228,6 +229,7 @@ export default { ...@@ -228,6 +229,7 @@ export default {
<date-range <date-range
:start-date="startDate" :start-date="startDate"
:end-date="endDate" :end-date="endDate"
:max-date-range="$options.maxDateRange"
class="js-daterange-picker" class="js-daterange-picker"
@change="setDateRange" @change="setDateRange"
/> />
......
<script> <script>
import { GlDaterangePicker } from '@gitlab/ui'; import { GlDaterangePicker, GlSprintf, GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { getDayDifference } from '~/lib/utils/datetime_utility';
import { __, sprintf } from '~/locale';
export default { export default {
components: { components: {
GlDaterangePicker, GlDaterangePicker,
GlSprintf,
GlIcon,
},
directives: {
GlTooltip: GlTooltipDirective,
}, },
props: { props: {
show: { show: {
...@@ -26,6 +33,18 @@ export default { ...@@ -26,6 +33,18 @@ export default {
rerquired: false, rerquired: false,
default: null, default: null,
}, },
maxDateRange: {
type: Number,
required: false,
default: 0,
},
},
data() {
return {
maxDateRangeTooltip: sprintf(__('Date range cannot exceed %{maxDateRange} days.'), {
maxDateRange: this.maxDateRange,
}),
};
}, },
computed: { computed: {
dateRange: { dateRange: {
...@@ -36,6 +55,9 @@ export default { ...@@ -36,6 +55,9 @@ export default {
this.$emit('change', { startDate, endDate }); this.$emit('change', { startDate, endDate });
}, },
}, },
numberOfDays() {
return getDayDifference(this.startDate, this.endDate);
},
}, },
}; };
</script> </script>
...@@ -50,9 +72,27 @@ export default { ...@@ -50,9 +72,27 @@ export default {
:default-start-date="startDate" :default-start-date="startDate"
:default-end-date="endDate" :default-end-date="endDate"
:default-min-date="minDate" :default-min-date="minDate"
:max-date-range="maxDateRange"
theme="animate-picker" theme="animate-picker"
start-picker-class="d-flex flex-column flex-lg-row align-items-lg-center mr-lg-2 mb-2 mb-md-0" start-picker-class="d-flex flex-column flex-lg-row align-items-lg-center mr-lg-2 mb-2 mb-md-0"
end-picker-class="d-flex flex-column flex-lg-row align-items-lg-center" end-picker-class="d-flex flex-column flex-lg-row align-items-lg-center"
/> />
<div
v-if="maxDateRange"
class="daterange-indicator d-flex flex-row flex-lg-row align-items-flex-start align-items-lg-center"
>
<span class="number-of-days pl-2 pr-1">
<gl-sprintf message="%{numberOfDays} days">
<template #numberOfDays>{{ numberOfDays }}</template>
</gl-sprintf>
</span>
<gl-icon
v-gl-tooltip
:title="maxDateRangeTooltip"
name="question"
:size="14"
class="text-secondary"
/>
</div>
</div> </div>
</template> </template>
...@@ -15,3 +15,5 @@ export const scatterChartLineProps = { ...@@ -15,3 +15,5 @@ export const scatterChartLineProps = {
}; };
export const LAST_ACTIVITY_AT = 'last_activity_at'; export const LAST_ACTIVITY_AT = 'last_activity_at';
export const DATE_RANGE_LIMIT = 180;
...@@ -14,3 +14,16 @@ ...@@ -14,3 +14,16 @@
} }
} }
} }
.daterange-indicator {
@include media-breakpoint-down(md) {
.number-of-days {
padding-left: 0.25rem !important;
margin-top: 0.25rem;
}
svg {
margin-top: 0.45rem;
}
}
}
...@@ -29,6 +29,8 @@ describe('Daterange component', () => { ...@@ -29,6 +29,8 @@ describe('Daterange component', () => {
const findDaterangePicker = () => wrapper.find(GlDaterangePicker); const findDaterangePicker = () => wrapper.find(GlDaterangePicker);
const findDateRangeIndicator = () => wrapper.find('.daterange-indicator');
describe('template', () => { describe('template', () => {
describe('when show is false', () => { describe('when show is false', () => {
it('does not render the daterange picker', () => { it('does not render the daterange picker', () => {
...@@ -67,6 +69,24 @@ describe('Daterange component', () => { ...@@ -67,6 +69,24 @@ describe('Daterange component', () => {
}); });
}); });
}); });
describe('with a maxDateRange being set', () => {
beforeEach(() => {
factory({ maxDateRange: 30 });
});
it('displays the max date range indicator', () => {
expect(findDateRangeIndicator().exists()).toBe(true);
});
it('displays the correct number of selected days in the indicator', () => {
expect(
findDateRangeIndicator()
.find('span')
.text(),
).toBe('10 days');
});
});
}); });
describe('computed', () => { describe('computed', () => {
......
...@@ -5963,6 +5963,9 @@ msgstr "" ...@@ -5963,6 +5963,9 @@ msgstr ""
msgid "Date picker" msgid "Date picker"
msgstr "" msgstr ""
msgid "Date range cannot exceed %{maxDateRange} days."
msgstr ""
msgid "DayTitle|F" msgid "DayTitle|F"
msgstr "" msgstr ""
......
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