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

253 lines
7.5 KiB
Vue
Raw Normal View History

2021-12-11 22:18:48 +05:30
<script>
2022-01-26 12:08:38 +05:30
import { GlBadge, GlPagination, GlTab, GlTabs } from '@gitlab/ui';
import { s__, __, sprintf } from '~/locale';
import { updateHistory, setUrlParams, queryToObject } from '~/lib/utils/url_utility';
import environmentAppQuery from '../graphql/queries/environment_app.query.graphql';
import pollIntervalQuery from '../graphql/queries/poll_interval.query.graphql';
import pageInfoQuery from '../graphql/queries/page_info.query.graphql';
2022-03-02 08:16:31 +05:30
import environmentToDeleteQuery from '../graphql/queries/environment_to_delete.query.graphql';
import environmentToRollbackQuery from '../graphql/queries/environment_to_rollback.query.graphql';
import environmentToStopQuery from '../graphql/queries/environment_to_stop.query.graphql';
2022-04-04 11:22:00 +05:30
import environmentToChangeCanaryQuery from '../graphql/queries/environment_to_change_canary.query.graphql';
2021-12-11 22:18:48 +05:30
import EnvironmentFolder from './new_environment_folder.vue';
2022-01-26 12:08:38 +05:30
import EnableReviewAppModal from './enable_review_app_modal.vue';
2022-03-02 08:16:31 +05:30
import StopEnvironmentModal from './stop_environment_modal.vue';
import EnvironmentItem from './new_environment_item.vue';
import ConfirmRollbackModal from './confirm_rollback_modal.vue';
import DeleteEnvironmentModal from './delete_environment_modal.vue';
2022-04-04 11:22:00 +05:30
import CanaryUpdateModal from './canary_update_modal.vue';
2021-12-11 22:18:48 +05:30
export default {
components: {
2022-03-02 08:16:31 +05:30
DeleteEnvironmentModal,
2022-04-04 11:22:00 +05:30
CanaryUpdateModal,
2022-03-02 08:16:31 +05:30
ConfirmRollbackModal,
2021-12-11 22:18:48 +05:30
EnvironmentFolder,
2022-01-26 12:08:38 +05:30
EnableReviewAppModal,
2022-03-02 08:16:31 +05:30
EnvironmentItem,
StopEnvironmentModal,
2021-12-11 22:18:48 +05:30
GlBadge,
2022-01-26 12:08:38 +05:30
GlPagination,
2021-12-11 22:18:48 +05:30
GlTab,
GlTabs,
},
apollo: {
environmentApp: {
query: environmentAppQuery,
2022-01-26 12:08:38 +05:30
variables() {
return {
scope: this.scope,
page: this.page ?? 1,
};
},
pollInterval() {
return this.interval;
},
2021-12-11 22:18:48 +05:30
},
2022-01-26 12:08:38 +05:30
interval: {
query: pollIntervalQuery,
},
pageInfo: {
query: pageInfoQuery,
},
2022-03-02 08:16:31 +05:30
environmentToDelete: {
query: environmentToDeleteQuery,
},
environmentToRollback: {
query: environmentToRollbackQuery,
},
environmentToStop: {
query: environmentToStopQuery,
},
2022-04-04 11:22:00 +05:30
environmentToChangeCanary: {
query: environmentToChangeCanaryQuery,
},
weight: {
query: environmentToChangeCanaryQuery,
},
2022-01-26 12:08:38 +05:30
},
inject: ['newEnvironmentPath', 'canCreateEnvironment'],
i18n: {
newEnvironmentButtonLabel: s__('Environments|New environment'),
reviewAppButtonLabel: s__('Environments|Enable review app'),
available: __('Available'),
stopped: __('Stopped'),
prevPage: __('Go to previous page'),
nextPage: __('Go to next page'),
next: __('Next'),
prev: __('Prev'),
goto: (page) => sprintf(__('Go to page %{page}'), { page }),
},
modalId: 'enable-review-app-info',
data() {
const { page = '1', scope = 'available' } = queryToObject(window.location.search);
return {
interval: undefined,
isReviewAppModalVisible: false,
page: parseInt(page, 10),
scope,
2022-03-02 08:16:31 +05:30
environmentToDelete: {},
environmentToRollback: {},
environmentToStop: {},
2022-04-04 11:22:00 +05:30
environmentToChangeCanary: {},
weight: 0,
2022-01-26 12:08:38 +05:30
};
2021-12-11 22:18:48 +05:30
},
computed: {
2022-01-26 12:08:38 +05:30
canSetupReviewApp() {
return this.environmentApp?.reviewApp?.canSetupReviewApp;
},
2021-12-11 22:18:48 +05:30
folders() {
2022-03-02 08:16:31 +05:30
return this.environmentApp?.environments?.filter((e) => e.size > 1) ?? [];
},
environments() {
return this.environmentApp?.environments?.filter((e) => e.size === 1) ?? [];
2021-12-11 22:18:48 +05:30
},
availableCount() {
return this.environmentApp?.availableCount;
},
2022-01-26 12:08:38 +05:30
addEnvironment() {
if (!this.canCreateEnvironment) {
return null;
}
return {
text: this.$options.i18n.newEnvironmentButtonLabel,
attributes: {
href: this.newEnvironmentPath,
category: 'primary',
variant: 'confirm',
},
};
},
openReviewAppModal() {
if (!this.canSetupReviewApp) {
return null;
}
return {
text: this.$options.i18n.reviewAppButtonLabel,
attributes: {
category: 'secondary',
variant: 'confirm',
},
};
},
stoppedCount() {
return this.environmentApp?.stoppedCount;
},
totalItems() {
return this.pageInfo?.total;
},
itemsPerPage() {
return this.pageInfo?.perPage;
},
},
mounted() {
window.addEventListener('popstate', this.syncPageFromQueryParams);
},
destroyed() {
window.removeEventListener('popstate', this.syncPageFromQueryParams);
this.$apollo.queries.environmentApp.stopPolling();
},
methods: {
showReviewAppModal() {
this.isReviewAppModalVisible = true;
},
setScope(scope) {
this.scope = scope;
2022-03-02 08:16:31 +05:30
this.moveToPage(1);
2022-01-26 12:08:38 +05:30
},
movePage(direction) {
this.moveToPage(this.pageInfo[`${direction}Page`]);
},
moveToPage(page) {
this.page = page;
updateHistory({
url: setUrlParams({ page: this.page }),
title: document.title,
});
this.resetPolling();
},
syncPageFromQueryParams() {
const { page = '1' } = queryToObject(window.location.search);
this.page = parseInt(page, 10);
},
resetPolling() {
this.$apollo.queries.environmentApp.stopPolling();
this.$nextTick(() => {
if (this.interval) {
this.$apollo.queries.environmentApp.startPolling(this.interval);
} else {
this.$apollo.queries.environmentApp.refetch({ scope: this.scope, page: this.page });
}
});
},
2021-12-11 22:18:48 +05:30
},
};
</script>
<template>
<div>
2022-01-26 12:08:38 +05:30
<enable-review-app-modal
v-if="canSetupReviewApp"
v-model="isReviewAppModalVisible"
:modal-id="$options.modalId"
data-testid="enable-review-app-modal"
/>
2022-03-02 08:16:31 +05:30
<delete-environment-modal :environment="environmentToDelete" graphql />
<stop-environment-modal :environment="environmentToStop" graphql />
<confirm-rollback-modal :environment="environmentToRollback" graphql />
2022-04-04 11:22:00 +05:30
<canary-update-modal :environment="environmentToChangeCanary" :weight="weight" />
2022-01-26 12:08:38 +05:30
<gl-tabs
:action-secondary="addEnvironment"
:action-primary="openReviewAppModal"
sync-active-tab-with-query-params
query-param-name="scope"
@primary="showReviewAppModal"
>
<gl-tab query-param-value="available" @click="setScope('available')">
2021-12-11 22:18:48 +05:30
<template #title>
2022-01-26 12:08:38 +05:30
<span>{{ $options.i18n.available }}</span>
2021-12-11 22:18:48 +05:30
<gl-badge size="sm" class="gl-tab-counter-badge">
{{ availableCount }}
</gl-badge>
</template>
2022-01-26 12:08:38 +05:30
</gl-tab>
<gl-tab query-param-value="stopped" @click="setScope('stopped')">
<template #title>
<span>{{ $options.i18n.stopped }}</span>
<gl-badge size="sm" class="gl-tab-counter-badge">
{{ stoppedCount }}
</gl-badge>
</template>
2021-12-11 22:18:48 +05:30
</gl-tab>
</gl-tabs>
2022-01-26 12:08:38 +05:30
<environment-folder
v-for="folder in folders"
:key="folder.name"
class="gl-mb-3"
:nested-environment="folder"
/>
2022-03-02 08:16:31 +05:30
<environment-item
v-for="environment in environments"
:key="environment.name"
class="gl-mb-3 gl-border-gray-100 gl-border-1 gl-border-b-solid"
:environment="environment.latest"
/>
2022-01-26 12:08:38 +05:30
<gl-pagination
align="center"
:total-items="totalItems"
:per-page="itemsPerPage"
:value="page"
:next="$options.i18n.next"
:prev="$options.i18n.prev"
:label-previous-page="$options.prevPage"
:label-next-page="$options.nextPage"
:label-page="$options.goto"
@next="movePage('next')"
@previous="movePage('previous')"
@input="moveToPage"
/>
2021-12-11 22:18:48 +05:30
</div>
</template>