debian-mirror-gitlab/app/assets/javascripts/boards/components/project_select.vue

143 lines
3.8 KiB
Vue
Raw Normal View History

2018-03-27 19:54:05 +05:30
<script>
2021-03-08 18:12:59 +05:30
import {
GlDropdown,
GlDropdownItem,
GlDropdownText,
GlSearchBoxByType,
GlIntersectionObserver,
GlLoadingIcon,
} from '@gitlab/ui';
2021-04-17 20:07:23 +05:30
import { mapActions, mapState, mapGetters } from 'vuex';
2021-03-08 18:12:59 +05:30
import { s__ } from '~/locale';
2019-12-04 20:38:33 +05:30
import { featureAccessLevel } from '~/pages/projects/shared/permissions/constants';
2021-02-22 17:27:13 +05:30
import { ListType } from '../constants';
2018-05-09 12:01:36 +05:30
2018-11-08 19:23:39 +05:30
export default {
2021-03-08 18:12:59 +05:30
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-12-13 13:39:08 +05:30
components: {
2021-03-08 18:12:59 +05:30
GlIntersectionObserver,
2018-12-13 13:39:08 +05:30
GlLoadingIcon,
2021-03-08 18:12:59 +05:30
GlDropdown,
GlDropdownItem,
GlDropdownText,
GlSearchBoxByType,
2018-12-13 13:39:08 +05:30
},
2021-03-08 18:12:59 +05:30
inject: ['groupId'],
2018-11-08 19:23:39 +05:30
props: {
2019-12-04 20:38:33 +05:30
list: {
type: Object,
required: true,
},
2018-11-08 19:23:39 +05:30
},
data() {
return {
2021-03-08 18:12:59 +05:30
initialLoading: true,
2018-11-08 19:23:39 +05:30
selectedProject: {},
2021-03-08 18:12:59 +05:30
searchTerm: '',
2018-11-08 19:23:39 +05:30
};
},
computed: {
2021-04-17 20:07:23 +05:30
...mapState(['groupProjectsFlags']),
...mapGetters(['activeGroupProjects']),
2018-11-08 19:23:39 +05:30
selectedProjectName() {
2021-03-08 18:12:59 +05:30
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-04-17 20:07:23 +05:30
return this.activeGroupProjects.length === 0;
2021-03-08 18:12:59 +05:30
},
hasNextPage() {
return this.groupProjectsFlags.pageInfo?.hasNextPage;
},
},
watch: {
searchTerm() {
this.fetchGroupProjects({ search: this.searchTerm });
2018-03-27 19:54:05 +05:30
},
2018-11-08 19:23:39 +05:30
},
mounted() {
2021-03-08 18:12:59 +05:30
this.fetchGroupProjects({});
2019-12-04 20:38:33 +05:30
2021-03-08 18:12:59 +05:30
this.initialLoading = false;
},
methods: {
...mapActions(['fetchGroupProjects', 'setSelectedProject']),
selectProject(projectId) {
2021-04-17 20:07:23 +05:30
this.selectedProject = this.activeGroupProjects.find((project) => project.id === projectId);
2021-03-08 18:12:59 +05:30
this.setSelectedProject(this.selectedProject);
},
loadMoreProjects() {
this.fetchGroupProjects({ search: this.searchTerm, fetchNext: true });
},
2018-11-08 19:23:39 +05:30
},
};
2018-03-27 19:54:05 +05:30
</script>
<template>
<div>
2021-03-08 18:12:59 +05:30
<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-04-17 20:07:23 +05:30
v-for="project in activeGroupProjects"
2021-03-08 18:12:59 +05:30
v-show="!groupProjectsFlags.isLoading"
:key="project.id"
:name="project.name"
@click="selectProject(project.id)"
>
{{ project.nameWithNamespace }}
</gl-dropdown-item>
<gl-dropdown-text
v-show="groupProjectsFlags.isLoading"
data-testid="dropdown-text-loading-icon"
>
2021-09-30 23:02:18 +05:30
<gl-loading-icon class="gl-mx-auto" size="sm" />
2021-03-08 18:12:59 +05:30
</gl-dropdown-text>
<gl-dropdown-text
v-if="isFetchResultEmpty && !groupProjectsFlags.isLoading"
data-testid="empty-result-message"
2018-03-27 19:54:05 +05:30
>
2021-03-08 18:12:59 +05:30
<span class="gl-text-gray-500">{{ $options.i18n.emptySearchResult }}</span>
</gl-dropdown-text>
<gl-intersection-observer v-if="hasNextPage" @appear="loadMoreProjects">
<gl-loading-icon v-if="groupProjectsFlags.isLoadingMore" size="md" />
</gl-intersection-observer>
</gl-dropdown>
2018-03-27 19:54:05 +05:30
</div>
</template>