All files / app/assets/javascripts/boards/components board_new_item.vue

0% Statements 0/8
0% Branches 0/2
0% Functions 0/6
0% Lines 0/8

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                                                                                                                                                                                               
<script>
import { GlForm, GlFormInput, GlButton } from '@gitlab/ui';
import { __ } from '~/locale';
 
export default {
  i18n: {
    cancel: __('Cancel'),
  },
  components: {
    GlForm,
    GlFormInput,
    GlButton,
  },
  props: {
    list: {
      type: Object,
      required: true,
    },
    disableSubmit: {
      type: Boolean,
      required: false,
      default: false,
    },
    submitButtonTitle: {
      type: String,
      required: false,
      default: __('Create issue'),
    },
  },
  data() {
    return {
      title: '',
    };
  },
  computed: {
    inputFieldId() {
      // eslint-disable-next-line @gitlab/require-i18n-strings
      return `${this.list.id}-title`;
    },
    isIssueTitleEmpty() {
      return this.title.trim() === '';
    },
    isCreatingIssueDisabled() {
      return this.isIssueTitleEmpty || this.disableSubmit;
    },
  },
  methods: {
    handleFormCancel() {
      this.title = '';
      this.$emit('form-cancel');
    },
    handleFormSubmit() {
      const { title, list } = this;
 
      this.$emit('form-submit', {
        title: title.trim(),
        list,
      });
    },
  },
};
</script>
 
<template>
  <div class="board-new-issue-form gl-z-index-3 gl-m-3">
    <div class="board-card position-relative gl-p-5 rounded">
      <gl-form @submit.prevent="handleFormSubmit" @reset="handleFormCancel">
        <label :for="inputFieldId" class="gl-font-weight-bold">{{ __('Title') }}</label>
        <gl-form-input
          :id="inputFieldId"
          v-model="title"
          :autofocus="true"
          autocomplete="off"
          type="text"
          name="issue_title"
        />
        <slot></slot>
        <div class="gl-clearfix gl-mt-4">
          <gl-button
            data-testid="create-button"
            :disabled="isCreatingIssueDisabled"
            class="gl-float-left js-no-auto-disable"
            variant="confirm"
            type="submit"
          >
            {{ submitButtonTitle }}
          </gl-button>
          <gl-button class="gl-float-right js-no-auto-disable" type="reset">
            {{ $options.i18n.cancel }}
          </gl-button>
        </div>
      </gl-form>
    </div>
  </div>
</template>