Commit 11cfc033 authored by Martin Wortschack's avatar Martin Wortschack Committed by Filipa Lacerda

Add minDate for daterange picker

- This prevents users cannot from selecting
a start before the given minDate
parent 7f1b4ddf
...@@ -20,6 +20,7 @@ export default () => { ...@@ -20,6 +20,7 @@ export default () => {
const appContainer = container.querySelector('.js-productivity-analytics-app-container'); const appContainer = container.querySelector('.js-productivity-analytics-app-container');
const { endpoint, emptyStateSvgPath, noAccessSvgPath } = appContainer.dataset; const { endpoint, emptyStateSvgPath, noAccessSvgPath } = appContainer.dataset;
const { startDate: minDate } = timeframeContainer.dataset;
const now = new Date(Date.now()); const now = new Date(Date.now());
const defaultStartDate = getDateInPast(now, defaultDaysInPast); const defaultStartDate = getDateInPast(now, defaultDaysInPast);
...@@ -97,6 +98,7 @@ export default () => { ...@@ -97,6 +98,7 @@ export default () => {
show: this.groupNamespace !== null, show: this.groupNamespace !== null,
startDate: defaultStartDate, startDate: defaultStartDate,
endDate: defaultEndDate, endDate: defaultEndDate,
minDate: minDate ? new Date(minDate) : null,
}, },
on: { on: {
change: this.onDateRangeChange, change: this.onDateRangeChange,
......
...@@ -21,6 +21,11 @@ export default { ...@@ -21,6 +21,11 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
minDate: {
type: Date,
rerquired: false,
default: null,
},
}, },
computed: { computed: {
dateRange: { dateRange: {
...@@ -44,6 +49,7 @@ export default { ...@@ -44,6 +49,7 @@ export default {
class="d-flex flex-column flex-lg-row" class="d-flex flex-column flex-lg-row"
:default-start-date="startDate" :default-start-date="startDate"
:default-end-date="endDate" :default-end-date="endDate"
:default-min-date="minDate"
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"
......
import { shallowMount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Daterange from 'ee/analytics/shared/components/daterange.vue'; import Daterange from 'ee/analytics/shared/components/daterange.vue';
import { GlDaterangePicker } from '@gitlab/ui'; import { GlDaterangePicker } from '@gitlab/ui';
...@@ -11,7 +11,7 @@ describe('Daterange component', () => { ...@@ -11,7 +11,7 @@ describe('Daterange component', () => {
let wrapper; let wrapper;
const factory = (props = defaultProps) => { const factory = (props = defaultProps) => {
wrapper = shallowMount(Daterange, { wrapper = mount(Daterange, {
propsData: { propsData: {
...defaultProps, ...defaultProps,
...props, ...props,
...@@ -43,6 +43,28 @@ describe('Daterange component', () => { ...@@ -43,6 +43,28 @@ describe('Daterange component', () => {
expect(findDaterangePicker().exists()).toBe(true); expect(findDaterangePicker().exists()).toBe(true);
}); });
}); });
describe('with a minDate being set', () => {
it('emits the change event with the minDate when the user enters a start date before the minDate', () => {
const startDate = new Date('2019-09-01');
const endDate = new Date('2019-09-30');
const minDate = new Date('2019-06-01');
factory({ show: true, startDate, endDate, minDate });
const input = findDaterangePicker().find('input');
input.setValue('2019-01-01');
input.trigger('change');
expect(wrapper.emittedByOrder()).toEqual([
{
name: 'change',
args: [{ startDate: minDate, endDate }],
},
]);
});
});
}); });
describe('computed', () => { describe('computed', () => {
......
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