All files / app/assets/javascripts/groups/components group_item.vue

90.9% Statements 20/22
75% Branches 15/20
100% Functions 17/17
90.47% Lines 19/21

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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292                                              4x                                                                                         65x     65x     65x               65x     2x     65x     65x     65x     1x     65x     65x             63x     63x         2x 2x 2x   2x 2x                                                                                                                                                                                                                                                                                                                                                
<script>
import {
  GlLoadingIcon,
  GlBadge,
  GlButton,
  GlPopover,
  GlLink,
  GlTooltipDirective,
} from '@gitlab/ui';
import SafeHtml from '~/vue_shared/directives/safe_html';
import { visitUrl } from '~/lib/utils/url_utility';
import ProjectAvatar from '~/vue_shared/components/project_avatar.vue';
import UserAccessRoleBadge from '~/vue_shared/components/user_access_role_badge.vue';
import VisibilityIcon from '~/vue_shared/components/visibility_icon.vue';
import { helpPagePath } from '~/helpers/help_page_helper';
import { __ } from '~/locale';
import { VISIBILITY_LEVELS_STRING_TO_INTEGER } from '~/visibility_level/constants';
import { ITEM_TYPE, ACTIVE_TAB_SHARED } from '../constants';
 
import eventHub from '../event_hub';
 
import ItemActions from './item_actions.vue';
import ItemStats from './item_stats.vue';
import ItemTypeIcon from './item_type_icon.vue';
 
export default {
  directives: {
    GlTooltip: GlTooltipDirective,
    SafeHtml,
  },
  components: {
    GlBadge,
    GlButton,
    GlLoadingIcon,
    GlPopover,
    GlLink,
    UserAccessRoleBadge,
    ItemTypeIcon,
    ItemActions,
    ItemStats,
    ProjectAvatar,
    VisibilityIcon,
    FrameworkBadge: () =>
      import('ee_component/compliance_dashboard/components/shared/framework_badge.vue'),
  },
  inject: {
    currentGroupVisibility: {
      default: '',
    },
  },
  props: {
    parentGroup: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    group: {
      type: Object,
      required: true,
    },
    action: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    groupDomId() {
      return `group-${this.group.id}`;
    },
    itemTestId() {
      return `group-overview-item-${this.group.id}`;
    },
    rowClass() {
      return {
        'is-open': this.group.isOpen,
        'has-children': this.hasChildren,
        'has-description': this.group.description,
        'being-removed': this.group.isBeingRemoved,
      };
    },
    hasChildren() {
      return this.group.childrenCount > 0;
    },
    hasAvatar() {
      return this.group.avatarUrl !== null;
    },
    hasComplianceFramework() {
      return Boolean(this.group.complianceFramework?.name);
    },
    isGroup() {
      return this.group.type === ITEM_TYPE.GROUP;
    },
    microdata() {
      return this.group.microdata || {};
    },
    complianceFramework() {
      return this.group.complianceFramework;
    },
    showActionsMenu() {
      return this.isGroup && (this.group.canEdit || this.group.canRemove || this.group.canLeave);
    },
    shouldShowVisibilityWarning() {
      return (
        this.action === ACTIVE_TAB_SHARED &&
        VISIBILITY_LEVELS_STRING_TO_INTEGER[this.group.visibility] >
          VISIBILITY_LEVELS_STRING_TO_INTEGER[this.currentGroupVisibility]
      );
    },
    toggleAriaLabel() {
      return this.group.isOpen ? this.$options.i18n.collapse : this.$options.i18n.expand;
    },
    toggleIconName() {
      return this.group.isOpen ? 'chevron-down' : 'chevron-right';
    },
  },
  methods: {
    onClickRowGroup(e) {
      const NO_EXPAND_CLS = 'no-expand';
      const targetClasses = e.target.classList;
      const parentElClasses = e.target.parentElement.classList;
 
      if (!(targetClasses.contains(NO_EXPAND_CLS) || parentElClasses.contains(NO_EXPAND_CLS))) {
        if (this.hasChildren) {
          eventHub.$emit(`${this.action}toggleChildren`, this.group);
        } else {
          visitUrl(this.group.relativePath);
        }
      }
    },
  },
  i18n: {
    expand: __('Expand'),
    collapse: __('Collapse'),
    popoverTitle: __('Less restrictive visibility'),
    popoverBody: __('Project visibility level is less restrictive than the group settings.'),
    learnMore: __('Learn more'),
  },
  shareProjectsWithGroupsHelpPagePath: helpPagePath(
    'user/project/members/share_project_with_groups',
    {
      anchor: 'sharing-projects-with-groups-of-a-higher-restrictive-visibility-level',
    },
  ),
  safeHtmlConfig: { ADD_TAGS: ['gl-emoji'] },
};
</script>
 
<template>
  <li
    :id="groupDomId"
    :data-testid="itemTestId"
    :class="rowClass"
    class="group-row"
    :itemprop="microdata.itemprop"
    :itemtype="microdata.itemtype"
    :itemscope="microdata.itemscope"
    @click.stop="onClickRowGroup"
  >
    <div
      :class="{ 'project-row-contents': !isGroup }"
      class="group-row-contents d-flex gl-align-items-center py-2 pr-3"
    >
      <div class="folder-toggle-wrap gl-mr-2 d-flex gl-align-items-center">
        <gl-button
          v-if="hasChildren"
          :aria-label="toggleAriaLabel"
          :aria-expanded="String(group.isOpen)"
          category="tertiary"
          data-testid="group-item-toggle-button"
          :icon="toggleIconName"
          @click.stop="onClickRowGroup"
        />
        <div v-else class="gl-h-7 gl-w-7"></div>
        <item-type-icon :item-type="group.type" />
      </div>
      <gl-loading-icon
        v-if="group.isChildrenLoading"
        size="lg"
        class="d-none d-sm-inline-flex flex-shrink-0 gl-mr-3"
      />
      <a
        :class="{ 'gl-sm-display-flex': !group.isChildrenLoading }"
        class="gl-display-none gl-text-decoration-none! gl-mr-3"
        :href="group.relativePath"
        :aria-label="group.name"
      >
        <project-avatar
          :alt="group.name"
          :itemprop="microdata.imageItemprop"
          :project-avatar-url="group.avatarUrl"
          :project-id="group.id"
          :project-name="group.name"
        />
      </a>
      <div class="group-text-container d-flex flex-fill gl-align-items-center">
        <div class="group-text flex-grow-1 flex-shrink-1">
          <div
            class="gl-display-flex gl-align-items-center gl-flex-wrap title namespace-title gl-font-weight-bold gl-mr-3"
          >
            <a
              v-gl-tooltip.bottom
              data-testid="group-name"
              :href="group.relativePath"
              :title="group.fullName"
              class="no-expand gl-mr-3 gl-text-gray-900! gl-word-break-word"
              :itemprop="microdata.nameItemprop"
            >
              <!-- ending bracket must be by closing tag to prevent -->
              <!-- link hover text-decoration from over-extending -->
              {{ group.name }}
            </a>
            <visibility-icon
              :is-group="isGroup"
              :visibility-level="group.visibility"
              class="gl-mr-3"
              data-testid="group-visibility-icon"
              tooltip-placement="bottom"
            />
            <template v-if="shouldShowVisibilityWarning">
              <gl-button
                ref="visibilityWarningButton"
                class="gl-p-1! gl-bg-transparent! gl-mr-3"
                category="tertiary"
                icon="warning"
                :aria-label="$options.i18n.popoverTitle"
                @click.stop
              />
              <gl-popover
                :target="() => $refs.visibilityWarningButton.$el"
                :title="$options.i18n.popoverTitle"
                triggers="hover focus"
              >
                {{ $options.i18n.popoverBody }}
                <div class="gl-mt-3">
                  <gl-link
                    class="gl-font-sm"
                    :href="$options.shareProjectsWithGroupsHelpPagePath"
                    >{{ $options.i18n.learnMore }}</gl-link
                  >
                </div>
              </gl-popover>
            </template>
            <user-access-role-badge v-if="group.permission" size="sm" class="gl-mr-2">
              {{ group.permission }}
            </user-access-role-badge>
            <framework-badge
              v-if="hasComplianceFramework"
              :framework="complianceFramework"
              :show-edit="false"
            />
          </div>
          <div v-if="group.description" class="description gl-font-sm gl-mt-1">
            <span
              v-safe-html:[$options.safeHtmlConfig]="group.description"
              :itemprop="microdata.descriptionItemprop"
              data-testid="group-description"
            >
            </span>
          </div>
        </div>
        <div v-if="group.pendingRemoval">
          <gl-badge variant="warning">{{ __('Pending deletion') }}</gl-badge>
        </div>
        <div v-else-if="group.archived">
          <gl-badge variant="info">{{ __('Archived') }}</gl-badge>
        </div>
        <div
          class="metadata gl-display-flex gl-flex-grow-1 gl-flex-shrink-0 gl-flex-wrap justify-content-md-between"
        >
          <item-stats
            :item="group"
            class="group-stats gl-display-none gl-md-display-flex gl-align-items-center"
          />
          <item-actions
            v-if="showActionsMenu"
            :group="group"
            :parent-group="parentGroup"
            :action="action"
          />
        </div>
      </div>
    </div>
    <group-folder
      v-if="group.isOpen && hasChildren"
      :parent-group="group"
      :groups="group.children"
      :action="action"
    />
  </li>
</template>