2021-04-17 20:07:23 +05:30
|
|
|
<script>
|
|
|
|
import { GlDropdown, GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlSearchBoxByType,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
paramsName: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
projects: {
|
|
|
|
type: Array,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
selectedProject: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-04-17 20:07:23 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchTerm: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2021-06-08 01:23:25 +05:30
|
|
|
disableRepoDropdown() {
|
|
|
|
return this.projects === null;
|
|
|
|
},
|
2021-04-17 20:07:23 +05:30
|
|
|
filteredRepos() {
|
|
|
|
const lowerCaseSearchTerm = this.searchTerm.toLowerCase();
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
return this?.projects.filter(({ name }) => name.toLowerCase().includes(lowerCaseSearchTerm));
|
2021-04-17 20:07:23 +05:30
|
|
|
},
|
|
|
|
inputName() {
|
|
|
|
return `${this.paramsName}_project_id`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2021-06-08 01:23:25 +05:30
|
|
|
onClick(project) {
|
|
|
|
this.emitTargetProject(project);
|
2021-04-17 20:07:23 +05:30
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
emitTargetProject(project) {
|
|
|
|
this.$emit('selectProject', { direction: this.paramsName, project });
|
2021-04-17 20:07:23 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2021-06-08 01:23:25 +05:30
|
|
|
<input type="hidden" :name="inputName" :value="selectedProject.id" />
|
2021-04-17 20:07:23 +05:30
|
|
|
<gl-dropdown
|
2021-06-08 01:23:25 +05:30
|
|
|
:text="selectedProject.name"
|
2021-04-17 20:07:23 +05:30
|
|
|
:header-text="s__(`CompareRevisions|Select target project`)"
|
2023-03-04 22:38:38 +05:30
|
|
|
class="gl-w-full gl-font-monospace"
|
2021-04-17 20:07:23 +05:30
|
|
|
toggle-class="gl-min-w-0"
|
2021-06-08 01:23:25 +05:30
|
|
|
:disabled="disableRepoDropdown"
|
2021-04-17 20:07:23 +05:30
|
|
|
>
|
|
|
|
<template #header>
|
2021-06-08 01:23:25 +05:30
|
|
|
<gl-search-box-by-type v-if="!disableRepoDropdown" v-model.trim="searchTerm" />
|
2021-04-17 20:07:23 +05:30
|
|
|
</template>
|
2021-06-08 01:23:25 +05:30
|
|
|
<template v-if="!disableRepoDropdown">
|
2021-04-17 20:07:23 +05:30
|
|
|
<gl-dropdown-item
|
|
|
|
v-for="repo in filteredRepos"
|
|
|
|
:key="repo.id"
|
|
|
|
is-check-item
|
2021-06-08 01:23:25 +05:30
|
|
|
:is-checked="selectedProject.id === repo.id"
|
2021-04-17 20:07:23 +05:30
|
|
|
@click="onClick(repo)"
|
|
|
|
>
|
|
|
|
{{ repo.name }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
</template>
|
|
|
|
</gl-dropdown>
|
|
|
|
</div>
|
|
|
|
</template>
|