Commit d6855a2e authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'aregnery/update-styling-of-date-range-indicator' into 'master'

Update styling of date range indicator

See merge request gitlab-org/gitlab!78108
parents 6904edb3 bce04586
<script> <script>
import { GlDaterangePicker, GlSprintf, GlIcon, GlTooltipDirective } from '@gitlab/ui'; import { GlDaterangePicker, GlSprintf } from '@gitlab/ui';
import { getDayDifference } from '~/lib/utils/datetime_utility'; import { getDayDifference } from '~/lib/utils/datetime_utility';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import { OFFSET_DATE_BY_ONE } from '../constants'; import { OFFSET_DATE_BY_ONE } from '../constants';
...@@ -8,10 +8,6 @@ export default { ...@@ -8,10 +8,6 @@ export default {
components: { components: {
GlDaterangePicker, GlDaterangePicker,
GlSprintf, GlSprintf,
GlIcon,
},
directives: {
GlTooltip: GlTooltipDirective,
}, },
props: { props: {
show: { show: {
...@@ -56,7 +52,7 @@ export default { ...@@ -56,7 +52,7 @@ export default {
return { return {
maxDateRangeTooltip: sprintf( maxDateRangeTooltip: sprintf(
__( __(
'Showing data for workflow items created in this date range. Date range cannot exceed %{maxDateRange} days.', 'Showing data for workflow items created in this date range. Date range limited to %{maxDateRange} days.',
), ),
{ {
maxDateRange: this.maxDateRange, maxDateRange: this.maxDateRange,
...@@ -94,28 +90,15 @@ export default { ...@@ -94,28 +90,15 @@ export default {
:max-date-range="maxDateRange" :max-date-range="maxDateRange"
:default-max-date="maxDate" :default-max-date="maxDate"
:same-day-selection="includeSelectedDate" :same-day-selection="includeSelectedDate"
:tooltip="maxDateRangeTooltip"
theme="animate-picker" theme="animate-picker"
start-picker-class="js-daterange-picker-from gl-display-flex gl-flex-direction-column gl-lg-flex-direction-row gl-lg-align-items-center gl-lg-mr-3 gl-mb-2 gl-lg-mb-0" start-picker-class="js-daterange-picker-from gl-display-flex gl-flex-direction-column gl-lg-flex-direction-row gl-lg-align-items-center gl-lg-mr-3 gl-mb-2 gl-lg-mb-0"
end-picker-class="js-daterange-picker-to d-flex flex-column flex-lg-row align-items-lg-center" end-picker-class="js-daterange-picker-to d-flex flex-column flex-lg-row align-items-lg-center gl-mb-2 gl-lg-mb-0"
label-class="gl-mb-2 gl-lg-mb-0" label-class="gl-mb-2 gl-lg-mb-0"
/>
<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="n__('1 day selected', '%d days selected', numberOfDays)">
<gl-sprintf :message="n__('1 day selected', '%d days selected', numberOfDays)"> <template #numberOfDays>{{ numberOfDays }}</template>
<template #numberOfDays>{{ numberOfDays }}</template> </gl-sprintf>
</gl-sprintf> </gl-daterange-picker>
</span>
<gl-icon
v-gl-tooltip
data-testid="helper-icon"
:title="maxDateRangeTooltip"
name="question"
:size="14"
class="text-secondary"
/>
</div>
</div> </div>
</template> </template>
...@@ -33115,7 +33115,7 @@ msgstr "" ...@@ -33115,7 +33115,7 @@ msgstr ""
msgid "Showing data for group '%{group_name}' from Nov 1, 2019 to Dec 31, 2019" msgid "Showing data for group '%{group_name}' from Nov 1, 2019 to Dec 31, 2019"
msgstr "" msgstr ""
msgid "Showing data for workflow items created in this date range. Date range cannot exceed %{maxDateRange} days." msgid "Showing data for workflow items created in this date range. Date range limited to %{maxDateRange} days."
msgstr "" msgstr ""
msgid "Showing graphs based on events of the last %{timerange} days." msgid "Showing graphs based on events of the last %{timerange} days."
......
import { GlDaterangePicker } from '@gitlab/ui'; import { GlDaterangePicker, GlSprintf } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { useFakeDate } from 'helpers/fake_date'; import { useFakeDate } from 'helpers/fake_date';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import Daterange from '~/analytics/shared/components/daterange.vue'; import Daterange from '~/analytics/shared/components/daterange.vue';
const defaultProps = { const defaultProps = {
...@@ -15,13 +13,13 @@ describe('Daterange component', () => { ...@@ -15,13 +13,13 @@ describe('Daterange component', () => {
let wrapper; let wrapper;
const factory = (props = defaultProps) => { const factory = (props = defaultProps, mountFn = shallowMount) => {
wrapper = mount(Daterange, { wrapper = mountFn(Daterange, {
propsData: { propsData: {
...defaultProps, ...defaultProps,
...props, ...props,
}, },
directives: { GlTooltip: createMockDirective() }, stubs: { GlSprintf },
}); });
}; };
...@@ -29,9 +27,8 @@ describe('Daterange component', () => { ...@@ -29,9 +27,8 @@ describe('Daterange component', () => {
wrapper.destroy(); wrapper.destroy();
}); });
const findDaterangePicker = () => wrapper.find(GlDaterangePicker); const findDaterangePicker = () => wrapper.findComponent(GlDaterangePicker);
const findDateRangeIndicator = () => wrapper.findComponent(GlSprintf);
const findDateRangeIndicator = () => wrapper.find('.daterange-indicator');
describe('template', () => { describe('template', () => {
describe('when show is false', () => { describe('when show is false', () => {
...@@ -44,6 +41,7 @@ describe('Daterange component', () => { ...@@ -44,6 +41,7 @@ describe('Daterange component', () => {
describe('when show is true', () => { describe('when show is true', () => {
it('renders the daterange picker', () => { it('renders the daterange picker', () => {
factory({ show: true }); factory({ show: true });
expect(findDaterangePicker().exists()).toBe(true); expect(findDaterangePicker().exists()).toBe(true);
}); });
}); });
...@@ -54,14 +52,12 @@ describe('Daterange component', () => { ...@@ -54,14 +52,12 @@ describe('Daterange component', () => {
const endDate = new Date('2019-09-30'); const endDate = new Date('2019-09-30');
const minDate = new Date('2019-06-01'); const minDate = new Date('2019-06-01');
factory({ show: true, startDate, endDate, minDate }); factory({ show: true, startDate, endDate, minDate }, mount);
const input = findDaterangePicker().find('input'); const input = findDaterangePicker().find('input');
input.setValue('2019-01-01'); input.setValue('2019-01-01');
input.trigger('change'); await input.trigger('change');
await nextTick();
expect(wrapper.emitted().change).toEqual([[{ startDate: minDate, endDate }]]); expect(wrapper.emitted().change).toEqual([[{ startDate: minDate, endDate }]]);
}); });
}); });
...@@ -76,16 +72,13 @@ describe('Daterange component', () => { ...@@ -76,16 +72,13 @@ describe('Daterange component', () => {
}); });
it('displays the correct number of selected days in the indicator', () => { it('displays the correct number of selected days in the indicator', () => {
expect(findDateRangeIndicator().find('span').text()).toBe('10 days selected'); expect(findDateRangeIndicator().text()).toMatchInterpolatedText('10 days selected');
}); });
it('displays a tooltip', () => { it('sets the tooltip', () => {
const icon = wrapper.find('[data-testid="helper-icon"]'); const tooltip = findDaterangePicker().props('tooltip');
const tooltip = getBinding(icon.element, 'gl-tooltip'); expect(tooltip).toBe(
'Showing data for workflow items created in this date range. Date range limited to 30 days.',
expect(tooltip).toBeDefined();
expect(icon.attributes('title')).toBe(
'Showing data for workflow items created in this date range. Date range cannot exceed 30 days.',
); );
}); });
}); });
......
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