2018-02-19 14:06:16 -05:00
|
|
|
<script>
|
2020-12-23 04:10:13 -05:00
|
|
|
import {
|
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownText,
|
|
|
|
GlSearchBoxByType,
|
2021-01-14 04:10:22 -05:00
|
|
|
GlIntersectionObserver,
|
2020-12-23 04:10:13 -05:00
|
|
|
GlLoadingIcon,
|
|
|
|
} from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { mapActions, mapState } from 'vuex';
|
2020-12-23 04:10:13 -05:00
|
|
|
import { s__ } from '~/locale';
|
2019-09-04 12:33:02 -04:00
|
|
|
import { featureAccessLevel } from '~/pages/projects/shared/permissions/constants';
|
2020-12-14 16:09:47 -05:00
|
|
|
import { ListType } from '../constants';
|
2018-03-09 15:18:59 -05:00
|
|
|
|
2018-05-28 05:47:59 -04:00
|
|
|
export default {
|
2020-12-23 04:10:13 -05:00
|
|
|
name: 'ProjectSelect',
|
|
|
|
i18n: {
|
|
|
|
headerTitle: s__(`BoardNewIssue|Projects`),
|
|
|
|
dropdownText: s__(`BoardNewIssue|Select a project`),
|
|
|
|
searchPlaceholder: s__(`BoardNewIssue|Search projects`),
|
|
|
|
emptySearchResult: s__(`BoardNewIssue|No matching results`),
|
|
|
|
},
|
|
|
|
defaultFetchOptions: {
|
|
|
|
with_issues_enabled: true,
|
|
|
|
with_shared: false,
|
|
|
|
include_subgroups: true,
|
|
|
|
order_by: 'similarity',
|
|
|
|
},
|
2018-10-15 14:35:00 -04:00
|
|
|
components: {
|
2021-01-14 04:10:22 -05:00
|
|
|
GlIntersectionObserver,
|
2018-11-07 05:06:15 -05:00
|
|
|
GlLoadingIcon,
|
2020-12-23 04:10:13 -05:00
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownText,
|
|
|
|
GlSearchBoxByType,
|
2018-10-15 14:35:00 -04:00
|
|
|
},
|
2021-01-12 07:10:49 -05:00
|
|
|
inject: ['groupId'],
|
2018-05-28 05:47:59 -04:00
|
|
|
props: {
|
2019-09-04 12:33:02 -04:00
|
|
|
list: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-05-28 05:47:59 -04:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2020-12-23 04:10:13 -05:00
|
|
|
initialLoading: true,
|
2018-05-28 05:47:59 -04:00
|
|
|
selectedProject: {},
|
2020-12-23 04:10:13 -05:00
|
|
|
searchTerm: '',
|
2018-05-28 05:47:59 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2021-01-14 04:10:22 -05:00
|
|
|
...mapState(['groupProjects', 'groupProjectsFlags']),
|
2018-05-28 05:47:59 -04:00
|
|
|
selectedProjectName() {
|
2020-12-23 04:10:13 -05:00
|
|
|
return this.selectedProject.name || this.$options.i18n.dropdownText;
|
|
|
|
},
|
|
|
|
fetchOptions() {
|
|
|
|
const additionalAttrs = {};
|
|
|
|
if (this.list.type && this.list.type !== ListType.backlog) {
|
|
|
|
additionalAttrs.min_access_level = featureAccessLevel.EVERYONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...this.$options.defaultFetchOptions,
|
|
|
|
...additionalAttrs,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
isFetchResultEmpty() {
|
2021-01-14 04:10:22 -05:00
|
|
|
return this.groupProjects.length === 0;
|
|
|
|
},
|
|
|
|
hasNextPage() {
|
|
|
|
return this.groupProjectsFlags.pageInfo?.hasNextPage;
|
2018-02-19 14:06:16 -05:00
|
|
|
},
|
2018-05-28 05:47:59 -04:00
|
|
|
},
|
2020-12-23 04:10:13 -05:00
|
|
|
watch: {
|
|
|
|
searchTerm() {
|
2021-01-14 04:10:22 -05:00
|
|
|
this.fetchGroupProjects({ search: this.searchTerm });
|
2020-12-23 04:10:13 -05:00
|
|
|
},
|
|
|
|
},
|
2021-01-14 04:10:22 -05:00
|
|
|
mounted() {
|
|
|
|
this.fetchGroupProjects({});
|
2019-09-04 12:33:02 -04:00
|
|
|
|
2020-12-23 04:10:13 -05:00
|
|
|
this.initialLoading = false;
|
|
|
|
},
|
|
|
|
methods: {
|
2021-01-14 04:10:22 -05:00
|
|
|
...mapActions(['fetchGroupProjects', 'setSelectedProject']),
|
2020-12-23 04:10:13 -05:00
|
|
|
selectProject(projectId) {
|
2021-01-14 04:10:22 -05:00
|
|
|
this.selectedProject = this.groupProjects.find((project) => project.id === projectId);
|
|
|
|
this.setSelectedProject(this.selectedProject);
|
|
|
|
},
|
|
|
|
loadMoreProjects() {
|
|
|
|
this.fetchGroupProjects({ search: this.searchTerm, fetchNext: true });
|
2020-12-23 04:10:13 -05:00
|
|
|
},
|
2018-05-28 05:47:59 -04:00
|
|
|
},
|
|
|
|
};
|
2018-02-19 14:06:16 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2020-12-23 04:10:13 -05:00
|
|
|
<label class="gl-font-weight-bold gl-mt-3" data-testid="header-label">{{
|
|
|
|
$options.i18n.headerTitle
|
|
|
|
}}</label>
|
|
|
|
<gl-dropdown
|
|
|
|
data-testid="project-select-dropdown"
|
|
|
|
:text="selectedProjectName"
|
|
|
|
:header-text="$options.i18n.headerTitle"
|
|
|
|
block
|
|
|
|
menu-class="gl-w-full!"
|
|
|
|
:loading="initialLoading"
|
|
|
|
>
|
|
|
|
<gl-search-box-by-type
|
|
|
|
v-model.trim="searchTerm"
|
|
|
|
debounce="250"
|
|
|
|
:placeholder="$options.i18n.searchPlaceholder"
|
|
|
|
/>
|
|
|
|
<gl-dropdown-item
|
2021-01-14 04:10:22 -05:00
|
|
|
v-for="project in groupProjects"
|
|
|
|
v-show="!groupProjectsFlags.isLoading"
|
2020-12-23 04:10:13 -05:00
|
|
|
:key="project.id"
|
|
|
|
:name="project.name"
|
|
|
|
@click="selectProject(project.id)"
|
2018-02-19 14:06:16 -05:00
|
|
|
>
|
2021-01-14 04:10:22 -05:00
|
|
|
{{ project.nameWithNamespace }}
|
2020-12-23 04:10:13 -05:00
|
|
|
</gl-dropdown-item>
|
2021-01-14 04:10:22 -05:00
|
|
|
<gl-dropdown-text
|
|
|
|
v-show="groupProjectsFlags.isLoading"
|
|
|
|
data-testid="dropdown-text-loading-icon"
|
|
|
|
>
|
2020-12-23 04:10:13 -05:00
|
|
|
<gl-loading-icon class="gl-mx-auto" />
|
|
|
|
</gl-dropdown-text>
|
2021-01-14 04:10:22 -05:00
|
|
|
<gl-dropdown-text
|
|
|
|
v-if="isFetchResultEmpty && !groupProjectsFlags.isLoading"
|
|
|
|
data-testid="empty-result-message"
|
|
|
|
>
|
2020-12-23 04:10:13 -05:00
|
|
|
<span class="gl-text-gray-500">{{ $options.i18n.emptySearchResult }}</span>
|
|
|
|
</gl-dropdown-text>
|
2021-01-14 04:10:22 -05:00
|
|
|
<gl-intersection-observer v-if="hasNextPage" @appear="loadMoreProjects">
|
|
|
|
<gl-loading-icon v-if="groupProjectsFlags.isLoadingMore" size="md" />
|
|
|
|
</gl-intersection-observer>
|
2020-12-23 04:10:13 -05:00
|
|
|
</gl-dropdown>
|
2018-02-19 14:06:16 -05:00
|
|
|
</div>
|
|
|
|
</template>
|