Commit f25d75b6 authored by Miguel Rincon's avatar Miguel Rincon

Merge branch '262863-delete-oncall-rotation-graphql-frontend' into 'master'

Allow for deletion of a rotation in OncallSchedules

See merge request gitlab-org/gitlab!51905
parents 458c0d35 da1cae7e
...@@ -2,4 +2,3 @@ ...@@ -2,4 +2,3 @@
filenames: filenames:
- ee/app/assets/javascripts/on_demand_scans/graphql/dast_scan_create.mutation.graphql - ee/app/assets/javascripts/on_demand_scans/graphql/dast_scan_create.mutation.graphql
- ee/app/assets/javascripts/oncall_schedules/graphql/mutations/update_oncall_schedule_rotation.mutation.graphql - ee/app/assets/javascripts/oncall_schedules/graphql/mutations/update_oncall_schedule_rotation.mutation.graphql
- ee/app/assets/javascripts/oncall_schedules/graphql/mutations/destroy_oncall_rotation.mutation.graphql
...@@ -173,6 +173,7 @@ export default { ...@@ -173,6 +173,7 @@ export default {
:preset-type="presetType" :preset-type="presetType"
:rotations="rotations" :rotations="rotations"
:timeframe="timeframe" :timeframe="timeframe"
:schedule-iid="schedule.iid"
/> />
</div> </div>
</gl-card> </gl-card>
......
...@@ -29,6 +29,10 @@ export default { ...@@ -29,6 +29,10 @@ export default {
validator: (rotation) => validator: (rotation) =>
isEmpty(rotation) || [rotation.id, rotation.name, rotation.startsAt].every(Boolean), isEmpty(rotation) || [rotation.id, rotation.name, rotation.startsAt].every(Boolean),
}, },
scheduleIid: {
type: String,
required: true,
},
modalId: { modalId: {
type: String, type: String,
required: true, required: true,
...@@ -61,6 +65,7 @@ export default { ...@@ -61,6 +65,7 @@ export default {
const { const {
projectPath, projectPath,
rotation: { id }, rotation: { id },
scheduleIid,
} = this; } = this;
this.loading = true; this.loading = true;
...@@ -68,11 +73,19 @@ export default { ...@@ -68,11 +73,19 @@ export default {
.mutate({ .mutate({
mutation: destroyOncallRotationMutation, mutation: destroyOncallRotationMutation,
variables: { variables: {
iid: id, id,
scheduleIid,
projectPath, projectPath,
}, },
update(store, { data }) { update(store, { data }) {
updateStoreAfterRotationDelete(store, getOncallSchedulesQuery, data, { projectPath }); updateStoreAfterRotationDelete(
store,
getOncallSchedulesQuery,
{ ...data, scheduleIid },
{
projectPath,
},
);
}, },
}) })
.then(({ data: { oncallRotationDestroy } = {} } = {}) => { .then(({ data: { oncallRotationDestroy } = {} } = {}) => {
......
...@@ -44,6 +44,10 @@ export default { ...@@ -44,6 +44,10 @@ export default {
type: Array, type: Array,
required: true, required: true,
}, },
scheduleIid: {
type: String,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -131,6 +135,7 @@ export default { ...@@ -131,6 +135,7 @@ export default {
<delete-rotation-modal <delete-rotation-modal
:rotation="rotationToUpdate" :rotation="rotationToUpdate"
:modal-id="$options.deleteRotationModalId" :modal-id="$options.deleteRotationModalId"
:schedule-iid="scheduleIid"
@set-rotation-to-update="setRotationToUpdate" @set-rotation-to-update="setRotationToUpdate"
/> />
</div> </div>
......
#import "../fragments/oncall_schedule_rotation.fragment.graphql" #import "../fragments/oncall_schedule_rotation.fragment.graphql"
mutation oncallRotationDestroy($iid: String!, $projectPath: ID!) { mutation oncallRotationDestroy(
oncallRotationDestroy(input: { iid: $iid, projectPath: $projectPath }) { $id: IncidentManagementOncallRotationID!
$scheduleIid: String!
$projectPath: ID!
) {
oncallRotationDestroy(input: { id: $id, scheduleIid: $scheduleIid, projectPath: $projectPath }) {
errors errors
oncallRotation { oncallRotation {
...OnCallRotation ...OnCallRotation
......
...@@ -139,7 +139,12 @@ const updateRotationFromStore = (store, query, { oncallRotationUpdate }, schedul ...@@ -139,7 +139,12 @@ const updateRotationFromStore = (store, query, { oncallRotationUpdate }, schedul
}); });
}; };
const deleteRotationFromStore = (store, query, { oncallRotationDestroy }, variables) => { const deleteRotationFromStore = (
store,
query,
{ oncallRotationDestroy, scheduleIid },
variables,
) => {
const rotation = oncallRotationDestroy?.oncallRotation; const rotation = oncallRotationDestroy?.oncallRotation;
if (!rotation) { if (!rotation) {
return; return;
...@@ -150,12 +155,16 @@ const deleteRotationFromStore = (store, query, { oncallRotationDestroy }, variab ...@@ -150,12 +155,16 @@ const deleteRotationFromStore = (store, query, { oncallRotationDestroy }, variab
variables, variables,
}); });
// TODO: This needs the rotation backend to be fully integrated to work, for the moment we will place-hold it. https://gitlab.com/gitlab-org/gitlab/-/issues/262863
const data = produce(sourceData, (draftData) => { const data = produce(sourceData, (draftData) => {
// eslint-disable-next-line no-param-reassign const scheduleToUpdate = draftData.project.incidentManagementOncallSchedules.nodes.find(
draftData.project.incidentManagementOncallSchedules.nodes[0].rotations = [rotation].filter( ({ iid }) => iid === scheduleIid,
({ id }) => id !== rotation.id,
); );
const updatedRotations = scheduleToUpdate.rotations?.filter(({ id }) => id !== rotation.id);
// eslint-disable-next-line no-param-reassign
draftData.project.incidentManagementOncallSchedules.nodes.find(
({ iid }) => iid === scheduleIid,
).rotations = updatedRotations;
}); });
store.writeQuery({ store.writeQuery({
......
...@@ -14,7 +14,7 @@ exports[`AddEditScheduleForm renders modal layout 1`] = ` ...@@ -14,7 +14,7 @@ exports[`AddEditScheduleForm renders modal layout 1`] = `
> >
<gl-form-input-stub <gl-form-input-stub
id="schedule-name" id="schedule-name"
value="Test schedule" value="Test schedule from query"
/> />
</gl-form-group-stub> </gl-form-group-stub>
......
import mockRotations from './mock_rotation.json'; import mockRotations from './mock_rotation.json';
export const scheduleIid = '37';
export const participants = [ export const participants = [
{ {
id: '1', id: '1',
...@@ -16,6 +18,7 @@ export const participants = [ ...@@ -16,6 +18,7 @@ export const participants = [
avatarUrl: '', avatarUrl: '',
}, },
]; ];
export const errorMsg = 'Something went wrong'; export const errorMsg = 'Something went wrong';
export const getOncallSchedulesQueryResponse = { export const getOncallSchedulesQueryResponse = {
...@@ -26,11 +29,12 @@ export const getOncallSchedulesQueryResponse = { ...@@ -26,11 +29,12 @@ export const getOncallSchedulesQueryResponse = {
{ {
__typename: 'IncidentManagementOncallSchedule', __typename: 'IncidentManagementOncallSchedule',
iid: '37', iid: '37',
name: 'Test schedule', name: 'Test schedule from query',
description: 'Description 1 lives here', description: 'Description 1 lives here',
timezone: { timezone: {
identifier: 'Pacific/Honolulu', identifier: 'Pacific/Honolulu',
}, },
rotations: mockRotations,
}, },
], ],
}, },
......
...@@ -90,6 +90,7 @@ describe('On-call schedule', () => { ...@@ -90,6 +90,7 @@ describe('On-call schedule', () => {
presetType: PRESET_TYPES.WEEKS, presetType: PRESET_TYPES.WEEKS,
timeframe: mockWeeksTimeFrame, timeframe: mockWeeksTimeFrame,
rotations: expect.any(Array), rotations: expect.any(Array),
scheduleIid: mockSchedule.iid,
}); });
}); });
}); });
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
getOncallSchedulesQueryResponse, getOncallSchedulesQueryResponse,
destroyRotationResponse, destroyRotationResponse,
destroyRotationResponseWithErrors, destroyRotationResponseWithErrors,
scheduleIid,
} from '../../mocks/apollo_mock'; } from '../../mocks/apollo_mock';
import mockRotations from '../../mocks/mock_rotation.json'; import mockRotations from '../../mocks/mock_rotation.json';
...@@ -50,6 +51,7 @@ describe('DeleteRotationModal', () => { ...@@ -50,6 +51,7 @@ describe('DeleteRotationModal', () => {
}, },
propsData: { propsData: {
modalId: deleteRotationModalId, modalId: deleteRotationModalId,
scheduleIid,
rotation, rotation,
...props, ...props,
}, },
...@@ -93,6 +95,7 @@ describe('DeleteRotationModal', () => { ...@@ -93,6 +95,7 @@ describe('DeleteRotationModal', () => {
propsData: { propsData: {
rotation, rotation,
modalId: deleteRotationModalId, modalId: deleteRotationModalId,
scheduleIid,
}, },
provide: { provide: {
projectPath, projectPath,
...@@ -125,7 +128,7 @@ describe('DeleteRotationModal', () => { ...@@ -125,7 +128,7 @@ describe('DeleteRotationModal', () => {
expect(mutate).toHaveBeenCalledWith({ expect(mutate).toHaveBeenCalledWith({
mutation: expect.any(Object), mutation: expect.any(Object),
update: expect.anything(), update: expect.anything(),
variables: { iid: rotation.id, projectPath }, variables: { id: rotation.id, projectPath, scheduleIid },
}); });
}); });
......
...@@ -6,6 +6,7 @@ import CurrentDayIndicator from 'ee/oncall_schedules/components/schedule/compone ...@@ -6,6 +6,7 @@ import CurrentDayIndicator from 'ee/oncall_schedules/components/schedule/compone
import RotationsAssignee from 'ee/oncall_schedules/components/rotations/components/rotation_assignee.vue'; import RotationsAssignee from 'ee/oncall_schedules/components/rotations/components/rotation_assignee.vue';
import { getTimeframeForWeeksView } from 'ee/oncall_schedules/components/schedule/utils'; import { getTimeframeForWeeksView } from 'ee/oncall_schedules/components/schedule/utils';
import { PRESET_TYPES } from 'ee/oncall_schedules/constants'; import { PRESET_TYPES } from 'ee/oncall_schedules/constants';
import { scheduleIid } from '../../mocks/apollo_mock';
import mockRotations from '../../mocks/mock_rotation.json'; import mockRotations from '../../mocks/mock_rotation.json';
describe('RotationsListSectionComponent', () => { describe('RotationsListSectionComponent', () => {
...@@ -22,6 +23,7 @@ describe('RotationsListSectionComponent', () => { ...@@ -22,6 +23,7 @@ describe('RotationsListSectionComponent', () => {
propsData: { propsData: {
presetType, presetType,
timeframe, timeframe,
scheduleIid,
rotations: [mockRotations[0]], rotations: [mockRotations[0]],
}, },
provide: { provide: {
......
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