debian-mirror-gitlab/app/assets/javascripts/environments/components/environment_folder.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

118 lines
3.2 KiB
Vue
Raw Normal View History

2021-12-11 22:18:48 +05:30
<script>
2022-01-26 12:08:38 +05:30
import { GlButton, GlCollapse, GlIcon, GlBadge, GlLink } from '@gitlab/ui';
import { __, s__ } from '~/locale';
2022-05-07 20:08:51 +05:30
import pollIntervalQuery from '../graphql/queries/poll_interval.query.graphql';
2021-12-11 22:18:48 +05:30
import folderQuery from '../graphql/queries/folder.query.graphql';
2022-05-07 20:08:51 +05:30
import { ENVIRONMENT_COUNT_BY_SCOPE } from '../constants';
2022-03-02 08:16:31 +05:30
import EnvironmentItem from './new_environment_item.vue';
2021-12-11 22:18:48 +05:30
export default {
components: {
2022-03-02 08:16:31 +05:30
EnvironmentItem,
2022-01-26 12:08:38 +05:30
GlButton,
2021-12-11 22:18:48 +05:30
GlCollapse,
GlIcon,
GlBadge,
GlLink,
},
props: {
nestedEnvironment: {
type: Object,
required: true,
},
2022-05-07 20:08:51 +05:30
scope: {
type: String,
required: true,
},
2021-12-11 22:18:48 +05:30
},
data() {
2022-05-07 20:08:51 +05:30
return { visible: false, interval: undefined };
2021-12-11 22:18:48 +05:30
},
apollo: {
folder: {
query: folderQuery,
variables() {
2022-05-07 20:08:51 +05:30
return { environment: this.nestedEnvironment.latest, scope: this.scope };
2021-12-11 22:18:48 +05:30
},
2022-05-07 20:08:51 +05:30
},
interval: {
query: pollIntervalQuery,
2021-12-11 22:18:48 +05:30
},
},
2022-01-26 12:08:38 +05:30
i18n: {
collapse: __('Collapse'),
expand: __('Expand'),
link: s__('Environments|Show all'),
},
2021-12-11 22:18:48 +05:30
computed: {
icons() {
return this.visible
2022-07-23 23:45:48 +05:30
? { caret: 'chevron-lg-down', folder: 'folder-open' }
: { caret: 'chevron-lg-right', folder: 'folder-o' };
2021-12-11 22:18:48 +05:30
},
2022-01-26 12:08:38 +05:30
label() {
return this.visible ? this.$options.i18n.collapse : this.$options.i18n.expand;
},
2021-12-11 22:18:48 +05:30
count() {
2022-05-07 20:08:51 +05:30
const count = ENVIRONMENT_COUNT_BY_SCOPE[this.scope];
return this.folder?.[count] ?? 0;
2021-12-11 22:18:48 +05:30
},
folderClass() {
return { 'gl-font-weight-bold': this.visible };
},
folderPath() {
return this.nestedEnvironment.latest.folderPath;
},
2022-03-02 08:16:31 +05:30
environments() {
return this.folder?.environments;
},
2021-12-11 22:18:48 +05:30
},
methods: {
toggleCollapse() {
this.visible = !this.visible;
2022-07-16 23:28:13 +05:30
if (this.visible) {
this.$apollo.queries.folder.startPolling(this.interval);
} else {
this.$apollo.queries.folder.stopPolling();
}
2021-12-11 22:18:48 +05:30
},
2022-03-02 08:16:31 +05:30
isFirstEnvironment(index) {
return index === 0;
},
2021-12-11 22:18:48 +05:30
},
};
</script>
<template>
2022-03-02 08:16:31 +05:30
<div
:class="{ 'gl-pb-5': !visible }"
class="gl-border-b-solid gl-border-gray-100 gl-border-1 gl-pt-3"
>
<div class="gl-w-full gl-display-flex gl-align-items-center gl-px-3">
2022-01-26 12:08:38 +05:30
<gl-button
class="gl-mr-4 gl-fill-current-color gl-text-gray-500"
:aria-label="label"
:icon="icons.caret"
size="small"
category="tertiary"
@click="toggleCollapse"
2021-12-11 22:18:48 +05:30
/>
<gl-icon class="gl-mr-2 gl-fill-current-color gl-text-gray-500" :name="icons.folder" />
<div class="gl-mr-2 gl-text-gray-500" :class="folderClass">
{{ nestedEnvironment.name }}
</div>
<gl-badge size="sm" class="gl-mr-auto">{{ count }}</gl-badge>
2022-01-26 12:08:38 +05:30
<gl-link v-if="visible" :href="folderPath">{{ $options.i18n.link }}</gl-link>
2021-12-11 22:18:48 +05:30
</div>
2022-03-02 08:16:31 +05:30
<gl-collapse :visible="visible">
<environment-item
v-for="(environment, index) in environments"
:key="environment.name"
:environment="environment"
:class="{ 'gl-mt-5': isFirstEnvironment(index) }"
class="gl-border-gray-100 gl-border-t-solid gl-border-1 gl-pt-3"
in-folder
/>
</gl-collapse>
2021-12-11 22:18:48 +05:30
</div>
</template>