fork_groups_list_item.vue 4.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
<script>
import {
  GlLink,
  GlButton,
  GlIcon,
  GlAvatar,
  GlTooltipDirective,
  GlTooltip,
  GlBadge,
10
  GlSafeHtmlDirective as SafeHtml,
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
} from '@gitlab/ui';
import { VISIBILITY_TYPE_ICON, GROUP_VISIBILITY_TYPE } from '~/groups/constants';
import { __ } from '~/locale';
import csrf from '~/lib/utils/csrf';

export default {
  components: {
    GlIcon,
    GlAvatar,
    GlBadge,
    GlButton,
    GlTooltip,
    GlLink,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
27
    SafeHtml,
28 29 30 31 32 33 34 35 36 37 38 39
  },
  props: {
    group: {
      type: Object,
      required: true,
    },
    hasReachedProjectLimit: {
      type: Boolean,
      required: true,
    },
  },
  data() {
40
    return { namespaces: null, isForking: false };
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
  },

  computed: {
    rowClass() {
      return {
        'has-description': this.group.description,
        'being-removed': this.isGroupPendingRemoval,
      };
    },
    isGroupPendingRemoval() {
      return this.group.marked_for_deletion;
    },
    hasForkedProject() {
      return Boolean(this.group.forked_project_path);
    },
    visibilityIcon() {
      return VISIBILITY_TYPE_ICON[this.group.visibility];
    },
    visibilityTooltip() {
      return GROUP_VISIBILITY_TYPE[this.group.visibility];
    },
    isSelectButtonDisabled() {
      return this.hasReachedProjectLimit || !this.group.can_create_project;
    },
    selectButtonDisabledTooltip() {
      return this.hasReachedProjectLimit
        ? this.$options.i18n.hasReachedProjectLimitMessage
        : this.$options.i18n.insufficientPermissionsMessage;
    },
  },

72 73 74 75 76 77 78
  methods: {
    fork() {
      this.isForking = true;
      this.$refs.form.submit();
    },
  },

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 117 118 119 120 121 122 123
  i18n: {
    hasReachedProjectLimitMessage: __('You have reached your project limit'),
    insufficientPermissionsMessage: __(
      'You must have permission to create a project in a namespace before forking.',
    ),
  },

  csrf,
};
</script>
<template>
  <li :class="rowClass" class="group-row">
    <div class="group-row-contents gl-display-flex gl-align-items-center gl-py-3 gl-pr-5">
      <div class="folder-toggle-wrap gl-mr-2 gl-display-flex gl-align-items-center">
        <gl-icon name="folder-o" />
      </div>
      <gl-link
        :href="group.relative_path"
        class="gl-display-none gl-flex-shrink-0 gl-display-sm-flex gl-mr-3"
      >
        <gl-avatar :size="32" shape="rect" :entity-name="group.name" :src="group.avatarUrl" />
      </gl-link>
      <div class="gl-min-w-0 gl-display-flex gl-flex-grow-1 gl-flex-shrink-1 gl-align-items-center">
        <div class="gl-min-w-0 gl-flex-grow-1 flex-shrink-1">
          <div class="title gl-display-flex gl-align-items-center gl-flex-wrap gl-mr-3">
            <gl-link :href="group.relative_path" class="gl-mt-3 gl-mr-3 gl-text-gray-900!">{{
              group.full_name
            }}</gl-link>
            <gl-icon
              v-gl-tooltip.hover.bottom
              class="gl-mr-0 gl-inline-flex gl-mt-3 text-secondary"
              :name="visibilityIcon"
              :title="visibilityTooltip"
            />
            <gl-badge
              v-if="isGroupPendingRemoval"
              variant="warning"
              class="gl-display-none gl-display-sm-flex gl-mt-3 gl-mr-1"
              >{{ __('pending removal') }}</gl-badge
            >
            <span v-if="group.permission" class="user-access-role gl-mt-3">
              {{ group.permission }}
            </span>
          </div>
          <div v-if="group.description" class="description">
124
            <span v-safe-html="group.markdown_description"> </span>
125 126 127 128 129 130 131 132 133 134 135
          </div>
        </div>
        <div class="gl-display-flex gl-flex-shrink-0">
          <gl-button
            v-if="hasForkedProject"
            class="gl-h-7 gl-text-decoration-none!"
            :href="group.forked_project_path"
            >{{ __('Go to fork') }}</gl-button
          >
          <template v-else>
            <div ref="selectButtonWrapper">
136
              <form ref="form" method="POST" :action="group.fork_path">
137 138 139
                <input type="hidden" name="authenticity_token" :value="$options.csrf.token" />
                <gl-button
                  type="submit"
140
                  class="gl-h-7"
141
                  :data-qa-name="group.full_name"
142
                  category="secondary"
143 144
                  variant="success"
                  :disabled="isSelectButtonDisabled"
145 146
                  :loading="isForking"
                  @click="fork"
147 148 149 150 151 152 153 154 155 156 157 158 159
                  >{{ __('Select') }}</gl-button
                >
              </form>
            </div>
            <gl-tooltip v-if="isSelectButtonDisabled" :target="() => $refs.selectButtonWrapper">
              {{ selectButtonDisabledTooltip }}
            </gl-tooltip>
          </template>
        </div>
      </div>
    </div>
  </li>
</template>