2019-09-30 21:07:59 +05:30
|
|
|
<script>
|
2023-04-23 21:23:45 +05:30
|
|
|
import { GlCollapsibleListbox } from '@gitlab/ui';
|
2019-09-30 21:07:59 +05:30
|
|
|
import { __ } from '~/locale';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2023-04-23 21:23:45 +05:30
|
|
|
GlCollapsibleListbox,
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
projects: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
selectedProject: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
2023-04-23 21:23:45 +05:30
|
|
|
selectedProjectValue() {
|
|
|
|
return this.selectedProject?.id && String(this.selectedProject.id);
|
|
|
|
},
|
|
|
|
toggleText() {
|
|
|
|
return this.selectedProject?.name || __('Select private project');
|
|
|
|
},
|
|
|
|
listboxItems() {
|
|
|
|
return this.projects.map(({ id, name }) => {
|
|
|
|
return {
|
|
|
|
value: String(id),
|
|
|
|
text: name,
|
|
|
|
};
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2023-04-23 21:23:45 +05:30
|
|
|
selectProject(projectId) {
|
|
|
|
const project = this.projects.find(({ id }) => String(id) === projectId);
|
|
|
|
this.$emit('select', project);
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-04-23 21:23:45 +05:30
|
|
|
<gl-collapsible-listbox
|
|
|
|
icon="lock"
|
|
|
|
:items="listboxItems"
|
|
|
|
:selected="selectedProjectValue"
|
|
|
|
:toggle-text="toggleText"
|
|
|
|
block
|
|
|
|
@select="selectProject"
|
|
|
|
/>
|
2019-09-30 21:07:59 +05:30
|
|
|
</template>
|