2020-03-10 12:08:16 +00:00
|
|
|
<script>
|
|
|
|
import { GlIcon, GlFormGroup, GlFormRadio, GlFormRadioGroup, GlLink } from '@gitlab/ui';
|
2020-09-05 00:08:43 +00:00
|
|
|
import defaultVisibilityQuery from '../queries/snippet_visibility.query.graphql';
|
|
|
|
import { defaultSnippetVisibilityLevels } from '../utils/blob';
|
|
|
|
import { SNIPPET_LEVELS_RESTRICTED, SNIPPET_LEVELS_DISABLED } from '~/snippets/constants';
|
2020-03-10 12:08:16 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlIcon,
|
|
|
|
GlFormGroup,
|
|
|
|
GlFormRadio,
|
|
|
|
GlFormRadioGroup,
|
|
|
|
GlLink,
|
|
|
|
},
|
2020-09-05 00:08:43 +00:00
|
|
|
apollo: {
|
|
|
|
defaultVisibility: {
|
|
|
|
query: defaultVisibilityQuery,
|
|
|
|
manual: true,
|
|
|
|
result({ data: { visibilityLevels, multipleLevelsRestricted } }) {
|
|
|
|
this.visibilityLevels = defaultSnippetVisibilityLevels(visibilityLevels);
|
|
|
|
this.multipleLevelsRestricted = multipleLevelsRestricted;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-03-10 12:08:16 +00:00
|
|
|
props: {
|
|
|
|
helpLink: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
isProjectSnippet: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-04-01 09:07:45 +00:00
|
|
|
value: {
|
2020-03-10 12:08:16 +00:00
|
|
|
type: String,
|
2020-09-05 00:08:43 +00:00
|
|
|
required: true,
|
2020-03-10 12:08:16 +00:00
|
|
|
},
|
|
|
|
},
|
2020-09-05 00:08:43 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
visibilityLevels: [],
|
|
|
|
multipleLevelsRestricted: false,
|
|
|
|
};
|
2020-03-10 12:08:16 +00:00
|
|
|
},
|
2020-09-05 00:08:43 +00:00
|
|
|
SNIPPET_LEVELS_DISABLED,
|
|
|
|
SNIPPET_LEVELS_RESTRICTED,
|
2020-03-10 12:08:16 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div class="form-group">
|
|
|
|
<label>
|
|
|
|
{{ __('Visibility level') }}
|
|
|
|
<gl-link v-if="helpLink" :href="helpLink" target="_blank"
|
|
|
|
><gl-icon :size="12" name="question"
|
|
|
|
/></gl-link>
|
|
|
|
</label>
|
2020-09-05 00:08:43 +00:00
|
|
|
<gl-form-group id="visibility-level-setting" class="gl-mb-0">
|
|
|
|
<gl-form-radio-group :checked="value" stacked v-bind="$attrs" v-on="$listeners">
|
2020-03-10 12:08:16 +00:00
|
|
|
<gl-form-radio
|
2020-09-05 00:08:43 +00:00
|
|
|
v-for="option in visibilityLevels"
|
2020-04-01 09:07:45 +00:00
|
|
|
:key="option.value"
|
2020-03-10 12:08:16 +00:00
|
|
|
:value="option.value"
|
|
|
|
class="mb-3"
|
|
|
|
>
|
|
|
|
<div class="d-flex align-items-center">
|
|
|
|
<gl-icon :size="16" :name="option.icon" />
|
2020-04-01 09:07:45 +00:00
|
|
|
<span class="font-weight-bold ml-1 js-visibility-option">{{ option.label }}</span>
|
2020-03-10 12:08:16 +00:00
|
|
|
</div>
|
2020-04-01 09:07:45 +00:00
|
|
|
<template #help>{{
|
|
|
|
isProjectSnippet && option.description_project
|
|
|
|
? option.description_project
|
|
|
|
: option.description
|
|
|
|
}}</template>
|
2020-03-10 12:08:16 +00:00
|
|
|
</gl-form-radio>
|
|
|
|
</gl-form-radio-group>
|
|
|
|
</gl-form-group>
|
2020-09-05 00:08:43 +00:00
|
|
|
|
|
|
|
<div class="text-muted" data-testid="restricted-levels-info">
|
|
|
|
<template v-if="!visibilityLevels.length">{{ $options.SNIPPET_LEVELS_DISABLED }}</template>
|
|
|
|
<template v-else-if="multipleLevelsRestricted">{{
|
|
|
|
$options.SNIPPET_LEVELS_RESTRICTED
|
|
|
|
}}</template>
|
|
|
|
</div>
|
2020-03-10 12:08:16 +00:00
|
|
|
</div>
|
|
|
|
</template>
|