2018-02-19 14:06:16 -05:00
|
|
|
<script>
|
2020-12-23 04:10:13 -05:00
|
|
|
import {
|
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownText,
|
|
|
|
GlSearchBoxByType,
|
|
|
|
GlLoadingIcon,
|
|
|
|
} from '@gitlab/ui';
|
2018-05-28 05:47:59 -04:00
|
|
|
import eventHub from '../eventhub';
|
2020-12-23 04:10:13 -05:00
|
|
|
import { s__ } from '~/locale';
|
2018-05-28 05:47:59 -04:00
|
|
|
import Api from '../../api';
|
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: {
|
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,
|
|
|
|
isFetching: false,
|
|
|
|
projects: [],
|
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: {
|
|
|
|
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() {
|
|
|
|
return this.projects.length === 0;
|
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() {
|
|
|
|
this.fetchProjects();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async mounted() {
|
|
|
|
await this.fetchProjects();
|
2019-09-04 12:33:02 -04:00
|
|
|
|
2020-12-23 04:10:13 -05:00
|
|
|
this.initialLoading = false;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async fetchProjects() {
|
|
|
|
this.isFetching = true;
|
|
|
|
try {
|
|
|
|
const projects = await Api.groupProjects(this.groupId, this.searchTerm, this.fetchOptions);
|
2019-09-04 12:33:02 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
this.projects = projects.map((project) => {
|
2020-12-23 04:10:13 -05:00
|
|
|
return {
|
|
|
|
id: project.id,
|
|
|
|
name: project.name,
|
|
|
|
namespacedName: project.name_with_namespace,
|
|
|
|
path: project.path_with_namespace,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
/* Handled in Api.groupProjects */
|
|
|
|
} finally {
|
|
|
|
this.isFetching = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectProject(projectId) {
|
2020-12-23 16:10:24 -05:00
|
|
|
this.selectedProject = this.projects.find((project) => project.id === projectId);
|
2020-12-23 04:10:13 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
TODO Remove eventhub, use Vuex for BoardNewIssue and GraphQL for BoardNewIssueNew
|
|
|
|
https://gitlab.com/gitlab-org/gitlab/-/issues/276173
|
|
|
|
*/
|
|
|
|
eventHub.$emit('setSelectedProject', this.selectedProject);
|
|
|
|
},
|
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
|
|
|
|
v-for="project in projects"
|
|
|
|
v-show="!isFetching"
|
|
|
|
:key="project.id"
|
|
|
|
:name="project.name"
|
|
|
|
@click="selectProject(project.id)"
|
2018-02-19 14:06:16 -05:00
|
|
|
>
|
2020-12-23 04:10:13 -05:00
|
|
|
{{ project.namespacedName }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-text v-show="isFetching" data-testid="dropdown-text-loading-icon">
|
|
|
|
<gl-loading-icon class="gl-mx-auto" />
|
|
|
|
</gl-dropdown-text>
|
|
|
|
<gl-dropdown-text v-if="isFetchResultEmpty && !isFetching" data-testid="empty-result-message">
|
|
|
|
<span class="gl-text-gray-500">{{ $options.i18n.emptySearchResult }}</span>
|
|
|
|
</gl-dropdown-text>
|
|
|
|
</gl-dropdown>
|
2018-02-19 14:06:16 -05:00
|
|
|
</div>
|
|
|
|
</template>
|