debian-mirror-gitlab/app/assets/javascripts/ref/components/ref_results_section.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
3.8 KiB
Vue
Raw Normal View History

2020-07-28 23:09:34 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { GlDropdownSectionHeader, GlDropdownItem, GlBadge, GlIcon } from '@gitlab/ui';
2020-07-28 23:09:34 +05:30
import { s__ } from '~/locale';
export default {
name: 'RefResultsSection',
components: {
2020-11-24 15:15:51 +05:30
GlDropdownSectionHeader,
GlDropdownItem,
2020-07-28 23:09:34 +05:30
GlBadge,
GlIcon,
},
props: {
2021-04-17 20:07:23 +05:30
showHeader: {
type: Boolean,
required: false,
default: true,
},
2020-07-28 23:09:34 +05:30
sectionTitle: {
type: String,
required: true,
},
totalCount: {
type: Number,
required: true,
},
/**
* An array of object that have the following properties:
*
* - name (String, required): The name of the ref that will be displayed
* - value (String, optional): The value that will be selected when the ref
* is selected. If not provided, `name` will be used as the value.
* For example, commits use the short SHA for `name`
* and long SHA for `value`.
* - subtitle (String, optional): Text to render underneath the name.
* For example, used to render the commit's title underneath its SHA.
* - default (Boolean, optional): Whether or not to render a "default"
* indicator next to the item. Used to indicate
* the project's default branch.
*
*/
items: {
type: Array,
required: true,
2021-03-08 18:12:59 +05:30
validator: (items) => Array.isArray(items) && items.every((item) => item.name),
2020-07-28 23:09:34 +05:30
},
/**
* The currently selected ref.
* Used to render a check mark by the selected item.
* */
selectedRef: {
type: String,
required: false,
default: '',
},
/**
* An error object that indicates that an error
* occurred while fetching items for this section
*/
error: {
type: Error,
required: false,
default: null,
},
/** The message to display if an error occurs */
errorMessage: {
type: String,
required: false,
default: '',
},
2023-03-17 16:20:25 +05:30
shouldShowCheck: {
type: Boolean,
required: false,
default: true,
},
2020-07-28 23:09:34 +05:30
},
computed: {
totalCountText() {
return this.totalCount > 999 ? s__('TotalRefCountIndicator|1000+') : `${this.totalCount}`;
},
},
methods: {
showCheck(item) {
2023-03-17 16:20:25 +05:30
if (!this.shouldShowCheck) {
return false;
}
2020-07-28 23:09:34 +05:30
return item.name === this.selectedRef || item.value === this.selectedRef;
},
},
};
</script>
<template>
<div>
2021-04-17 20:07:23 +05:30
<gl-dropdown-section-header v-if="showHeader">
2020-07-28 23:09:34 +05:30
<div class="gl-display-flex align-items-center" data-testid="section-header">
<span class="gl-mr-2 gl-mb-1">{{ sectionTitle }}</span>
<gl-badge variant="neutral">{{ totalCountText }}</gl-badge>
</div>
2020-11-24 15:15:51 +05:30
</gl-dropdown-section-header>
2020-07-28 23:09:34 +05:30
<template v-if="error">
<div class="gl-display-flex align-items-start text-danger gl-ml-4 gl-mr-4 gl-mb-3">
<gl-icon name="error" class="gl-mr-2 gl-mt-2 gl-flex-shrink-0" />
<span>{{ errorMessage }}</span>
</div>
</template>
<template v-else>
2020-11-24 15:15:51 +05:30
<gl-dropdown-item
2020-07-28 23:09:34 +05:30
v-for="item in items"
:key="item.name"
@click="$emit('selected', item.value || item.name)"
>
<div class="gl-display-flex align-items-start">
<gl-icon
name="mobile-issue-close"
class="gl-mr-2 gl-flex-shrink-0"
:class="{ 'gl-visibility-hidden': !showCheck(item) }"
/>
<div class="gl-flex-grow-1 gl-display-flex gl-flex-direction-column">
<span class="gl-font-monospace">{{ item.name }}</span>
2020-10-24 23:57:45 +05:30
<span class="gl-text-gray-400">{{ item.subtitle }}</span>
2020-07-28 23:09:34 +05:30
</div>
<gl-badge v-if="item.default" size="sm" variant="info">{{
s__('DefaultBranchLabel|default')
}}</gl-badge>
</div>
2020-11-24 15:15:51 +05:30
</gl-dropdown-item>
2020-07-28 23:09:34 +05:30
</template>
</div>
</template>