All files / app/assets/javascripts/user_lists/components edit_user_list.vue

100% Statements 6/6
100% Branches 0/0
100% Functions 5/5
100% Lines 6/6

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    1x                                     7x     24x     24x     10x       11x                                                                                  
<script>
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapActions, mapState } from 'vuex';
import { s__, sprintf } from '~/locale';
import statuses from '../constants/edit';
import UserListForm from './user_list_form.vue';
 
export default {
  components: {
    GlAlert,
    GlLoadingIcon,
    UserListForm,
  },
  inject: ['userListsDocsPath'],
  translations: {
    saveButtonLabel: s__('UserLists|Save'),
  },
  computed: {
    ...mapState(['userList', 'status', 'errorMessage']),
    title() {
      return sprintf(s__('UserLists|Edit %{name}'), { name: this.userList?.name });
    },
    isLoading() {
      return this.status === statuses.LOADING;
    },
    isError() {
      return this.status === statuses.ERROR;
    },
    hasUserList() {
      return Boolean(this.userList);
    },
  },
  mounted() {
    this.fetchUserList();
  },
  methods: {
    ...mapActions(['fetchUserList', 'updateUserList', 'dismissErrorAlert']),
  },
};
</script>
<template>
  <div>
    <gl-alert
      v-if="isError"
      :dismissible="hasUserList"
      variant="danger"
      @dismiss="dismissErrorAlert"
    >
      <ul class="gl-mb-0">
        <li v-for="(message, index) in errorMessage" :key="index">
          {{ message }}
        </li>
      </ul>
    </gl-alert>
 
    <gl-loading-icon v-if="isLoading" size="xl" />
 
    <template v-else-if="hasUserList">
      <h3
        data-testid="user-list-title"
        class="gl-font-weight-bold gl-pb-5 gl-border-b-solid gl-border-gray-100 gl-border-1"
      >
        {{ title }}
      </h3>
      <user-list-form
        :cancel-path="userList.path"
        :save-button-label="$options.translations.saveButtonLabel"
        :user-lists-docs-path="userListsDocsPath"
        :user-list="userList"
        @submit="updateUserList"
      />
    </template>
  </div>
</template>