Commit edaad05e authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '268356-handle-empty-schedule-dropdown' into 'master'

Handle no schedules case for escalaltion rule

See merge request gitlab-org/gitlab!62698
parents 2646cf0c f9dd5507
...@@ -68,6 +68,11 @@ export default { ...@@ -68,6 +68,11 @@ export default {
}, },
}, },
}, },
computed: {
schedulesLoading() {
return this.$apollo.queries.schedules.loading;
},
},
mounted() { mounted() {
this.rules.push({ ...cloneDeep(defaultEscalationRule), key: this.getUid() }); this.rules.push({ ...cloneDeep(defaultEscalationRule), key: this.getUid() });
}, },
...@@ -141,6 +146,7 @@ export default { ...@@ -141,6 +146,7 @@ export default {
:rule="rule" :rule="rule"
:index="index" :index="index"
:schedules="schedules" :schedules="schedules"
:schedules-loading="schedulesLoading"
:is-valid="validationState.rules[index]" :is-valid="validationState.rules[index]"
@update-escalation-rule="updateEscalationRules" @update-escalation-rule="updateEscalationRules"
@remove-escalation-rule="removeEscalationRule" @remove-escalation-rule="removeEscalationRule"
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
GlCard, GlCard,
GlIcon, GlIcon,
GlSprintf, GlSprintf,
GlTooltipDirective as GlTooltip,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { ACTIONS, ALERT_STATUSES } from '../constants'; import { ACTIONS, ALERT_STATUSES } from '../constants';
...@@ -20,6 +21,9 @@ export const i18n = { ...@@ -20,6 +21,9 @@ export const i18n = {
validationMsg: s__( validationMsg: s__(
'EscalationPolicies|A schedule is required for adding an escalation policy.', 'EscalationPolicies|A schedule is required for adding an escalation policy.',
), ),
noSchedules: s__(
'EscalationPolicies|A schedule is required for adding an escalation policy. Please create an on-call schedule first.',
),
}, },
}, },
}; };
...@@ -37,6 +41,9 @@ export default { ...@@ -37,6 +41,9 @@ export default {
GlIcon, GlIcon,
GlSprintf, GlSprintf,
}, },
directives: {
GlTooltip,
},
props: { props: {
rule: { rule: {
type: Object, type: Object,
...@@ -47,6 +54,11 @@ export default { ...@@ -47,6 +54,11 @@ export default {
required: false, required: false,
default: () => [], default: () => [],
}, },
schedulesLoading: {
type: Boolean,
required: true,
default: true,
},
index: { index: {
type: Number, type: Number,
required: true, required: true,
...@@ -72,6 +84,9 @@ export default { ...@@ -72,6 +84,9 @@ export default {
? this.schedules.find(({ iid }) => iid === this.oncallScheduleIid)?.name ? this.schedules.find(({ iid }) => iid === this.oncallScheduleIid)?.name
: i18n.fields.rules.selectSchedule; : i18n.fields.rules.selectSchedule;
}, },
noSchedules() {
return !this.schedulesLoading && !this.schedules.length;
},
}, },
methods: { methods: {
setOncallSchedule({ iid }) { setOncallSchedule({ iid }) {
...@@ -157,6 +172,7 @@ export default { ...@@ -157,6 +172,7 @@ export default {
</template> </template>
<template #schedule> <template #schedule>
<gl-dropdown <gl-dropdown
:disabled="noSchedules"
class="rule-control" class="rule-control"
:text="scheduleDropdownTitle" :text="scheduleDropdownTitle"
data-testid="schedules-dropdown" data-testid="schedules-dropdown"
...@@ -176,6 +192,14 @@ export default { ...@@ -176,6 +192,14 @@ export default {
{{ schedule.name }} {{ schedule.name }}
</gl-dropdown-item> </gl-dropdown-item>
</gl-dropdown> </gl-dropdown>
<gl-icon
v-if="noSchedules"
v-gl-tooltip
:title="$options.i18n.fields.rules.noSchedules"
name="information-o"
class="gl-text-gray-500 gl-ml-3"
data-testid="no-schedules-info-icon"
/>
</template> </template>
</gl-sprintf> </gl-sprintf>
</div> </div>
......
...@@ -29,6 +29,11 @@ describe('AddEscalationPolicyForm', () => { ...@@ -29,6 +29,11 @@ describe('AddEscalationPolicyForm', () => {
provide: { provide: {
projectPath, projectPath,
}, },
mocks: {
$apollo: {
queries: { schedules: { loading: false } },
},
},
}), }),
); );
}; };
......
...@@ -19,6 +19,7 @@ describe('EscalationRule', () => { ...@@ -19,6 +19,7 @@ describe('EscalationRule', () => {
propsData: { propsData: {
rule: cloneDeep(defaultEscalationRule), rule: cloneDeep(defaultEscalationRule),
schedules: mockSchedules, schedules: mockSchedules,
schedulesLoading: false,
index: 0, index: 0,
isValid: false, isValid: false,
...props, ...props,
...@@ -49,6 +50,8 @@ describe('EscalationRule', () => { ...@@ -49,6 +50,8 @@ describe('EscalationRule', () => {
const findFormGroup = () => wrapper.findComponent(GlFormGroup); const findFormGroup = () => wrapper.findComponent(GlFormGroup);
const findNoSchedulesInfoIcon = () => wrapper.findByTestId('no-schedules-info-icon');
describe('Status dropdown', () => { describe('Status dropdown', () => {
it('should have correct alert status options', () => { it('should have correct alert status options', () => {
expect(findStatusDropdownOptions().wrappers.map((w) => w.text())).toStrictEqual( expect(findStatusDropdownOptions().wrappers.map((w) => w.text())).toStrictEqual(
...@@ -79,6 +82,17 @@ describe('EscalationRule', () => { ...@@ -79,6 +82,17 @@ describe('EscalationRule', () => {
mockSchedules.map(({ name }) => name), mockSchedules.map(({ name }) => name),
); );
}); });
it('should NOT disable the dropdown OR show the info icon when schedules are loaded and provided', () => {
expect(findSchedulesDropdown().attributes('disabled')).toBeUndefined();
expect(findNoSchedulesInfoIcon().exists()).toBe(false);
});
it('should disable the dropdown and show the info icon when no schedules provided', () => {
createComponent({ props: { schedules: [], schedulesLoading: false } });
expect(findSchedulesDropdown().attributes('disabled')).toBe('true');
expect(findNoSchedulesInfoIcon().exists()).toBe(true);
});
}); });
describe('Validation', () => { describe('Validation', () => {
......
...@@ -13087,6 +13087,9 @@ msgstr "" ...@@ -13087,6 +13087,9 @@ msgstr ""
msgid "EscalationPolicies|A schedule is required for adding an escalation policy." msgid "EscalationPolicies|A schedule is required for adding an escalation policy."
msgstr "" msgstr ""
msgid "EscalationPolicies|A schedule is required for adding an escalation policy. Please create an on-call schedule first."
msgstr ""
msgid "EscalationPolicies|Add an escalation policy" msgid "EscalationPolicies|Add an escalation policy"
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