Commit b5adc096 authored by Florie Guibert's avatar Florie Guibert

Delete description change history - Frontend

- Delete button icon on description diff
parent adee3d99
...@@ -8,5 +8,7 @@ export default { ...@@ -8,5 +8,7 @@ export default {
}, },
methods: { methods: {
toggleDescriptionVersion() {}, toggleDescriptionVersion() {},
canDeleteDescriptionVersion() {},
deleteDescriptionVersion() {},
}, },
}; };
...@@ -509,5 +509,24 @@ export const fetchDescriptionVersion = (_, { endpoint, startingVersion }) => { ...@@ -509,5 +509,24 @@ export const fetchDescriptionVersion = (_, { endpoint, startingVersion }) => {
export const setCurrentDiscussionId = ({ commit }, discussionId) => export const setCurrentDiscussionId = ({ commit }, discussionId) =>
commit(types.SET_CURRENT_DISCUSSION_ID, discussionId); commit(types.SET_CURRENT_DISCUSSION_ID, discussionId);
export const softDeleteDescriptionVersion = ({ commit }, { endpoint, startingVersion }) => {
let requestUrl = endpoint;
if (startingVersion) {
requestUrl = mergeUrlParams({ start_version_id: startingVersion }, requestUrl);
}
return axios
.delete(requestUrl)
.then(res => {
// Invalidate lastFatechedAt to trigger refetch on next page refresh
commit(types.SET_LAST_FETCHED_AT, null);
return res.data;
})
.catch(() => {
Flash(__('Something went wrong while deleting description changes. Please try again.'));
});
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
import $ from 'jquery'; import $ from 'jquery';
import { mapGetters, mapActions } from 'vuex'; import { mapGetters, mapActions } from 'vuex';
import { GlSkeletonLoading } from '@gitlab/ui'; import { GlSkeletonLoading, GlTooltipDirective } from '@gitlab/ui';
import descriptionVersionHistoryMixin from 'ee_else_ce/notes/mixins/description_version_history'; import descriptionVersionHistoryMixin from 'ee_else_ce/notes/mixins/description_version_history';
import noteHeader from '~/notes/components/note_header.vue'; import noteHeader from '~/notes/components/note_header.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
...@@ -36,6 +36,9 @@ export default { ...@@ -36,6 +36,9 @@ export default {
TimelineEntryItem, TimelineEntryItem,
GlSkeletonLoading, GlSkeletonLoading,
}, },
directives: {
GlTooltip: GlTooltipDirective,
},
mixins: [descriptionVersionHistoryMixin], mixins: [descriptionVersionHistoryMixin],
props: { props: {
note: { note: {
...@@ -80,7 +83,7 @@ export default { ...@@ -80,7 +83,7 @@ export default {
initMRPopovers(this.$el.querySelectorAll('.gfm-merge_request')); initMRPopovers(this.$el.querySelectorAll('.gfm-merge_request'));
}, },
methods: { methods: {
...mapActions(['fetchDescriptionVersion']), ...mapActions(['fetchDescriptionVersion', 'softDeleteDescriptionVersion']),
}, },
}; };
</script> </script>
...@@ -122,6 +125,16 @@ export default { ...@@ -122,6 +125,16 @@ export default {
<gl-skeleton-loading /> <gl-skeleton-loading />
</pre> </pre>
<pre v-else class="wrapper mt-2" v-html="descriptionVersion"></pre> <pre v-else class="wrapper mt-2" v-html="descriptionVersion"></pre>
<button
v-if="canDeleteDescriptionVersion"
v-gl-tooltip
type="button"
title="Remove description history"
class="btn btn-transparent delete-description-history"
@click="deleteDescriptionVersion"
>
<icon name="remove" />
</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -311,6 +311,14 @@ $note-form-margin-left: 72px; ...@@ -311,6 +311,14 @@ $note-form-margin-left: 72px;
overflow: hidden; overflow: hidden;
.description-version { .description-version {
position: relative;
.btn.delete-description-history {
position: absolute;
top: 18px;
right: 0;
}
pre { pre {
max-height: $dropdown-max-height-lg; max-height: $dropdown-max-height-lg;
white-space: pre-wrap; white-space: pre-wrap;
......
import { s__ } from '~/locale';
export default { export default {
data() { data() {
return { return {
...@@ -8,7 +10,14 @@ export default { ...@@ -8,7 +10,14 @@ export default {
}, },
computed: { computed: {
canSeeDescriptionVersion() { canSeeDescriptionVersion() {
return Boolean(this.note.description_diff_path && this.note.description_version_id); return Boolean(
this.note.description_diff_path &&
this.note.description_version_id &&
!this.note.description_version_deleted,
);
},
canDeleteDescriptionVersion() {
return this.note.can_delete_description_version;
}, },
shouldShowDescriptionVersion() { shouldShowDescriptionVersion() {
return this.canSeeDescriptionVersion && this.isDescriptionVersionExpanded; return this.canSeeDescriptionVersion && this.isDescriptionVersionExpanded;
...@@ -34,5 +43,13 @@ export default { ...@@ -34,5 +43,13 @@ export default {
this.descriptionVersion = diff; this.descriptionVersion = diff;
}); });
}, },
deleteDescriptionVersion() {
const endpoint = this.note.delete_description_version_path;
const startingVersion = this.note.start_description_version_id;
return this.softDeleteDescriptionVersion({ endpoint, startingVersion }).then(() => {
this.descriptionVersion = s__('Deleted');
});
},
}, },
}; };
---
title: Delete description change history - Frontend
merge_request: 23568
author:
type: changed
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