All files / ee/app/assets/javascripts/notes/mixins description_version_history.js

94.44% Statements 17/18
91.67% Branches 11/12
100% Functions 8/8
94.44% Lines 17/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57    11x             11x             6x             14x     7x         3x 3x   3x       3x 3x   3x     2x 2x 2x 2x 2x   1x            
export default {
  data() {
    return {
      isDescriptionVersionExpanded: false,
      deleteInProgress: false,
    };
  },
  computed: {
    canSeeDescriptionVersion() {
      return Boolean(
        this.note.description_diff_path &&
          this.note.description_version_id &&
          !this.note.description_version_deleted,
      );
    },
    displayDeleteButton() {
      return (
        this.note.can_delete_description_version &&
        !this.deleteInProgress &&
        !this.note.description_version_deleted
      );
    },
    shouldShowDescriptionVersion() {
      return this.canSeeDescriptionVersion && this.isDescriptionVersionExpanded;
    },
    descriptionVersionToggleIcon() {
      return this.isDescriptionVersionExpanded ? 'chevron-up' : 'chevron-down';
    },
  },
  methods: {
    toggleDescriptionVersion() {
      this.isDescriptionVersionExpanded = !this.isDescriptionVersionExpanded;
      const versionId = this.note.description_version_id;
 
      Iif (this.descriptionVersions?.[versionId]) {
        return false;
      }
 
      const endpoint = this.note.description_diff_path;
      const startingVersion = this.note.start_description_version_id;
 
      return this.fetchDescriptionVersion({ endpoint, startingVersion, versionId });
    },
    deleteDescriptionVersion() {
      const endpoint = this.note.delete_description_version_path;
      const startingVersion = this.note.start_description_version_id;
      const versionId = this.note.description_version_id;
      this.deleteInProgress = true;
      return this.softDeleteDescriptionVersion({ endpoint, startingVersion, versionId }).catch(
        () => {
          this.deleteInProgress = false;
        },
      );
    },
  },
};