All files / app/assets/javascripts/feature_flags/components edit_feature_flag.vue

100% Statements 9/9
75% Branches 3/4
100% Functions 4/4
100% Lines 9/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  2x 2x 2x 2x 2x             4x                                 8x           8x                       68x                                                                          
<script>
import { GlAlert, GlLoadingIcon, GlToggle } from '@gitlab/ui';
import { mapState, mapActions } from 'vuex';
import { sprintf, __ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import FeatureFlagForm from './form.vue';
 
export default {
  components: {
    GlAlert,
    GlLoadingIcon,
    GlToggle,
    FeatureFlagActions: () => import('ee_component/feature_flags/components/actions.vue'),
    FeatureFlagForm,
  },
  mixins: [glFeatureFlagMixin()],
  computed: {
    ...mapState([
      'path',
      'error',
      'name',
      'description',
      'strategies',
      'isLoading',
      'hasError',
      'iid',
      'active',
    ]),
    title() {
      return this.iid
        ? `^${this.iid} ${this.name}`
        : sprintf(this.$options.i18n.editTitle, { name: this.name });
    },
  },
  created() {
    return this.fetchFeatureFlag();
  },
  methods: {
    ...mapActions(['updateFeatureFlag', 'fetchFeatureFlag', 'toggleActive']),
  },
  i18n: {
    editTitle: __('Edit %{name}'),
    toggleLabel: __('Feature flag status'),
    submit: __('Save changes'),
  },
};
</script>
<template>
  <div>
    <gl-loading-icon v-if="isLoading" size="xl" class="gl-mt-7" />
 
    <template v-else-if="!isLoading && !hasError">
      <div class="gl-display-flex gl-align-items-center gl-mb-4 gl-mt-4">
        <gl-toggle
          :value="active"
          data-testid="feature-flag-status-toggle"
          data-track-action="click_button"
          data-track-label="feature_flag_toggle"
          class="gl-mr-4"
          :label="$options.i18n.toggleLabel"
          label-position="hidden"
          @change="toggleActive"
        />
        <h3 class="page-title gl-m-0">{{ title }}</h3>
 
        <feature-flag-actions class="gl-ml-auto" />
      </div>
 
      <gl-alert v-if="error.length" variant="warning" class="gl-mb-5" :dismissible="false">
        <p v-for="(message, index) in error" :key="index" class="gl-mb-0">{{ message }}</p>
      </gl-alert>
 
      <feature-flag-form
        :name="name"
        :description="description"
        :strategies="strategies"
        :cancel-path="path"
        :submit-text="$options.i18n.submit"
        :active="active"
        @handleSubmit="(data) => updateFeatureFlag(data)"
      />
    </template>
  </div>
</template>