All files / ee/app/assets/javascripts/compliance_dashboard/components/merge_requests merge_commits_export_button.vue

88.89% Statements 8/9
100% Branches 2/2
80% Functions 4/5
88.89% Lines 8/9

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116  3x                   3x 3x 3x                                     40x             40x       40x                                       311x                                                                                                        
<script>
import {
  GlButton,
  GlDropdown,
  GlDropdownForm,
  GlForm,
  GlFormGroup,
  GlFormInput,
  GlTooltip,
} from '@gitlab/ui';
 
import { isValidSha1Hash } from '~/lib/utils/text_utility';
import { __ } from '~/locale';
import { INPUT_DEBOUNCE, CUSTODY_REPORT_PARAMETER } from '../../constants';
 
export default {
  components: {
    GlButton,
    GlDropdown,
    GlDropdownForm,
    GlForm,
    GlFormGroup,
    GlFormInput,
    GlTooltip,
  },
  props: {
    mergeCommitsCsvExportPath: {
      required: true,
      type: String,
    },
  },
  data() {
    return {
      validMergeCommitHash: null,
      listMergeCommitsButton: null,
    };
  },
  computed: {
    mergeCommitButtonDisabled() {
      return !this.validMergeCommitHash;
    },
  },
  mounted() {
    this.listMergeCommitsButton = this.$refs.listMergeCommitsButton;
  },
  methods: {
    onInput(value) {
      this.validMergeCommitHash = isValidSha1Hash(value);
    },
  },
  strings: {
    mergeCommitInputLabel: __('Merge commit SHA'),
    mergeCommitInvalidMessage: __('Invalid hash'),
    mergeCommitButtonText: __('Export commit custody report'),
    listMergeCommitsButtonText: __('List of all merge commits'),
    exportAsCsv: __('Export as CSV'),
    csvSizeLimit: __('(max size 15 MB)'),
  },
  inputDebounce: INPUT_DEBOUNCE,
  custodyReportParamater: CUSTODY_REPORT_PARAMETER,
};
</script>
 
<template>
  <div>
    <gl-dropdown split>
      <template #button-content>
        <gl-button
          ref="listMergeCommitsButton"
          class="gl-p-0!"
          category="tertiary"
          icon="export"
          :href="mergeCommitsCsvExportPath"
        >
          {{ $options.strings.listMergeCommitsButtonText }}
        </gl-button>
      </template>
      <gl-dropdown-form>
        <gl-form :action="mergeCommitsCsvExportPath" class="gl-px-3" method="GET">
          <gl-form-group
            :label="$options.strings.mergeCommitInputLabel"
            :invalid-feedback="$options.strings.mergeCommitInvalidMessage"
            :state="validMergeCommitHash"
            label-size="sm"
            label-for="merge-commits-export-custody-report"
          >
            <gl-form-input
              id="merge-commits-export-custody-report"
              :name="$options.custodyReportParamater"
              :debounce="$options.inputDebounce"
              @input="onInput"
            />
          </gl-form-group>
          <gl-button
            :disabled="mergeCommitButtonDisabled"
            type="submit"
            variant="confirm"
            data-test-id="merge-commit-submit-button"
            class="disable-hover"
            >{{ $options.strings.mergeCommitButtonText }}</gl-button
          >
        </gl-form>
      </gl-dropdown-form>
    </gl-dropdown>
    <gl-tooltip
      v-if="listMergeCommitsButton"
      :target="listMergeCommitsButton"
      boundary="viewport"
      placement="top"
    >
      <p class="gl-my-0">{{ $options.strings.exportAsCsv }}</p>
      <p class="gl-my-0">{{ $options.strings.csvSizeLimit }}</p>
    </gl-tooltip>
  </div>
</template>