2021-06-23 12:07:58 +00:00
|
|
|
<script>
|
|
|
|
import { GlFilteredSearchSuggestion, GlToken } from '@gitlab/ui';
|
2022-01-12 09:15:13 +00:00
|
|
|
import { createAlert } from '~/flash';
|
2021-06-23 12:07:58 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { s__ } from '~/locale';
|
|
|
|
|
|
|
|
import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue';
|
|
|
|
import { RUNNER_TAG_BG_CLASS } from '../../constants';
|
|
|
|
|
|
|
|
export const TAG_SUGGESTIONS_PATH = '/admin/runners/tag_list.json';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
BaseToken,
|
|
|
|
GlFilteredSearchSuggestion,
|
|
|
|
GlToken,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
config: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tags: [],
|
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getTagsOptions(search) {
|
|
|
|
// TODO This should be implemented via a GraphQL API
|
|
|
|
// The API should
|
|
|
|
// 1) scope to the rights of the user
|
|
|
|
// 2) stay up to date to the removal of old tags
|
2021-08-23 15:10:43 +00:00
|
|
|
// 3) consider the scope of search, like searching within the tags of a group
|
2021-06-23 12:07:58 +00:00
|
|
|
// See: https://gitlab.com/gitlab-org/gitlab/-/issues/333796
|
|
|
|
return axios
|
|
|
|
.get(TAG_SUGGESTIONS_PATH, {
|
|
|
|
params: {
|
|
|
|
search,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
return data.map(({ id, name }) => ({ id, value: name, text: name }));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async fetchTags(searchTerm) {
|
|
|
|
this.loading = true;
|
|
|
|
try {
|
|
|
|
this.tags = await this.getTagsOptions(searchTerm);
|
|
|
|
} catch {
|
2022-01-12 09:15:13 +00:00
|
|
|
createAlert({
|
2021-06-23 12:07:58 +00:00
|
|
|
message: s__('Runners|Something went wrong while fetching the tags suggestions'),
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
RUNNER_TAG_BG_CLASS,
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<base-token
|
|
|
|
v-bind="$attrs"
|
|
|
|
:config="config"
|
|
|
|
:suggestions-loading="loading"
|
|
|
|
:suggestions="tags"
|
|
|
|
@fetch-suggestions="fetchTags"
|
|
|
|
v-on="$listeners"
|
|
|
|
>
|
|
|
|
<template #view-token="{ viewTokenProps: { listeners, inputValue, activeTokenValue } }">
|
|
|
|
<gl-token variant="search-value" :class="$options.RUNNER_TAG_BG_CLASS" v-on="listeners">
|
|
|
|
{{ activeTokenValue ? activeTokenValue.text : inputValue }}
|
|
|
|
</gl-token>
|
|
|
|
</template>
|
|
|
|
<template #suggestions-list="{ suggestions }">
|
|
|
|
<gl-filtered-search-suggestion v-for="tag in suggestions" :key="tag.id" :value="tag.value">
|
|
|
|
{{ tag.text }}
|
|
|
|
</gl-filtered-search-suggestion>
|
|
|
|
</template>
|
|
|
|
</base-token>
|
|
|
|
</template>
|