debian-mirror-gitlab/app/assets/javascripts/pipelines/components/pipelines_list/pipelines.vue

374 lines
9.8 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2021-04-29 21:17:54 +05:30
import { GlEmptyState, GlIcon, GlLoadingIcon } from '@gitlab/ui';
2020-03-13 15:44:24 +05:30
import { isEqual } from 'lodash';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as createFlash } from '~/flash';
2021-03-11 19:13:27 +05:30
import { getParameterByName } from '~/lib/utils/common_utils';
import { __, s__ } from '~/locale';
2020-07-28 23:09:34 +05:30
import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue';
2021-03-11 19:13:27 +05:30
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';
import { ANY_TRIGGER_AUTHOR, RAW_TEXT_WARNING, FILTER_TAG_IDENTIFIER } from '../../constants';
import PipelinesMixin from '../../mixins/pipelines_mixin';
import PipelinesService from '../../services/pipelines_service';
import { validateParams } from '../../utils';
import EmptyState from './empty_state.vue';
2018-11-08 19:23:39 +05:30
import NavigationControls from './nav_controls.vue';
2020-05-24 23:13:21 +05:30
import PipelinesFilteredSearch from './pipelines_filtered_search.vue';
2021-03-11 19:13:27 +05:30
import PipelinesTableComponent from './pipelines_table.vue';
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
export default {
components: {
2021-03-11 19:13:27 +05:30
EmptyState,
2021-04-29 21:17:54 +05:30
GlEmptyState,
2021-03-11 19:13:27 +05:30
GlIcon,
GlLoadingIcon,
2018-11-08 19:23:39 +05:30
NavigationTabs,
NavigationControls,
2020-05-24 23:13:21 +05:30
PipelinesFilteredSearch,
2021-03-11 19:13:27 +05:30
PipelinesTableComponent,
TablePagination,
2018-11-08 19:23:39 +05:30
},
2021-03-11 19:13:27 +05:30
mixins: [PipelinesMixin],
2018-11-08 19:23:39 +05:30
props: {
store: {
type: Object,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
// Can be rendered in 3 different places, with some visual differences
// Accepts root | child
// `root` -> main view
// `child` -> rendered inside MR or Commit View
viewType: {
type: String,
required: false,
default: 'root',
2018-03-17 18:26:18 +05:30
},
2018-11-08 19:23:39 +05:30
endpoint: {
type: String,
required: true,
2017-09-10 17:25:29 +05:30
},
2020-07-28 23:09:34 +05:30
pipelineScheduleUrl: {
type: String,
required: false,
default: '',
},
2018-11-08 19:23:39 +05:30
emptyStateSvgPath: {
type: String,
required: true,
},
errorStateSvgPath: {
type: String,
required: true,
},
noPipelinesSvgPath: {
type: String,
required: true,
},
hasGitlabCi: {
type: Boolean,
required: true,
2018-03-27 19:54:05 +05:30
},
2018-11-08 19:23:39 +05:30
canCreatePipeline: {
type: Boolean,
required: true,
2018-03-27 19:54:05 +05:30
},
2018-11-08 19:23:39 +05:30
ciLintPath: {
type: String,
required: false,
default: null,
},
resetCachePath: {
type: String,
required: false,
default: null,
},
newPipelinePath: {
type: String,
required: false,
default: null,
},
2020-05-24 23:13:21 +05:30
projectId: {
type: String,
required: true,
},
2020-06-23 00:09:42 +05:30
params: {
type: Object,
required: true,
},
2021-06-08 01:23:25 +05:30
codeQualityPagePath: {
type: String,
required: false,
default: null,
},
2018-11-08 19:23:39 +05:30
},
data() {
return {
// Start with loading state to avoid a glitch when the empty state will be rendered
isLoading: true,
state: this.store.state,
scope: getParameterByName('scope') || 'all',
page: getParameterByName('page') || '1',
requestData: {},
isResetCacheButtonLoading: false,
};
},
stateMap: {
// with tabs
loading: 'loading',
tableList: 'tableList',
error: 'error',
emptyTab: 'emptyTab',
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
// without tabs
emptyState: 'emptyState',
},
scopes: {
all: 'all',
finished: 'finished',
branches: 'branches',
tags: 'tags',
},
computed: {
/**
* `hasGitlabCi` handles both internal and external CI.
* The order on which the checks are made in this method is
* important to guarantee we handle all the corner cases.
*/
stateToRender() {
const { stateMap } = this.$options;
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
if (this.isLoading) {
return stateMap.loading;
}
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
if (this.hasError) {
return stateMap.error;
}
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
if (this.state.pipelines.length) {
return stateMap.tableList;
}
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
if ((this.scope !== 'all' && this.scope !== null) || this.hasGitlabCi) {
return stateMap.emptyTab;
}
return stateMap.emptyState;
},
/**
* Tabs are rendered in all states except empty state.
* They are not rendered before the first request to avoid a flicker on first load.
*/
shouldRenderTabs() {
const { stateMap } = this.$options;
return (
this.hasMadeRequest &&
[stateMap.loading, stateMap.tableList, stateMap.error, stateMap.emptyTab].includes(
this.stateToRender,
)
);
},
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
shouldRenderButtons() {
return (
(this.newPipelinePath || this.resetCachePath || this.ciLintPath) && this.shouldRenderTabs
);
},
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
emptyTabMessage() {
2020-07-28 23:09:34 +05:30
if (this.scope === this.$options.scopes.finished) {
return s__('Pipelines|There are currently no finished pipelines.');
2018-11-08 19:23:39 +05:30
}
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
return s__('Pipelines|There are currently no pipelines.');
},
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
tabs() {
const { count } = this.state;
const { scopes } = this.$options;
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
return [
{
name: __('All'),
scope: scopes.all,
count: count.all,
isActive: this.scope === 'all',
},
{
name: __('Finished'),
scope: scopes.finished,
isActive: this.scope === 'finished',
},
{
name: __('Branches'),
scope: scopes.branches,
isActive: this.scope === 'branches',
},
{
name: __('Tags'),
scope: scopes.tags,
isActive: this.scope === 'tags',
},
];
2017-09-10 17:25:29 +05:30
},
2020-06-23 00:09:42 +05:30
validatedParams() {
return validateParams(this.params);
},
2018-11-08 19:23:39 +05:30
},
created() {
this.service = new PipelinesService(this.endpoint);
2020-06-23 00:09:42 +05:30
this.requestData = { page: this.page, scope: this.scope, ...this.validatedParams };
2018-11-08 19:23:39 +05:30
},
methods: {
2021-03-11 19:13:27 +05:30
onChangeTab(scope) {
if (this.scope === scope) {
return;
}
let params = {
scope,
page: '1',
};
params = this.onChangeWithFilter(params);
this.updateContent(params);
},
2018-11-08 19:23:39 +05:30
successCallback(resp) {
// Because we are polling & the user is interacting verify if the response received
// matches the last request made
2020-03-13 15:44:24 +05:30
if (isEqual(resp.config.params, this.requestData)) {
2018-11-08 19:23:39 +05:30
this.store.storeCount(resp.data.count);
this.store.storePagination(resp.headers);
this.setCommonData(resp.data.pipelines);
}
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
handleResetRunnersCache(endpoint) {
this.isResetCacheButtonLoading = true;
2018-05-09 12:01:36 +05:30
2018-11-08 19:23:39 +05:30
this.service
.postAction(endpoint)
.then(() => {
this.isResetCacheButtonLoading = false;
createFlash(s__('Pipelines|Project cache successfully reset.'), 'notice');
})
.catch(() => {
this.isResetCacheButtonLoading = false;
createFlash(s__('Pipelines|Something went wrong while cleaning runners cache.'));
});
2017-09-10 17:25:29 +05:30
},
2020-05-24 23:13:21 +05:30
resetRequestData() {
this.requestData = { page: this.page, scope: this.scope };
},
filterPipelines(filters) {
this.resetRequestData();
2021-03-08 18:12:59 +05:30
filters.forEach((filter) => {
2020-05-24 23:13:21 +05:30
// do not add Any for username query param, so we
// can fetch all trigger authors
2020-06-23 00:09:42 +05:30
if (
filter.type &&
filter.value.data !== ANY_TRIGGER_AUTHOR &&
filter.type !== FILTER_TAG_IDENTIFIER
) {
2020-05-24 23:13:21 +05:30
this.requestData[filter.type] = filter.value.data;
}
2020-06-23 00:09:42 +05:30
if (filter.type === FILTER_TAG_IDENTIFIER) {
this.requestData.ref = filter.value.data;
}
2020-05-24 23:13:21 +05:30
if (!filter.type) {
createFlash(RAW_TEXT_WARNING, 'warning');
}
});
if (filters.length === 0) {
this.resetRequestData();
}
this.updateContent(this.requestData);
},
2018-11-08 19:23:39 +05:30
},
};
2017-09-10 17:25:29 +05:30
</script>
<template>
2018-03-17 18:26:18 +05:30
<div class="pipelines-container">
2017-09-10 17:25:29 +05:30
<div
2018-03-27 19:54:05 +05:30
v-if="shouldRenderTabs || shouldRenderButtons"
2021-03-08 18:12:59 +05:30
class="top-area scrolling-tabs-container inner-page-scroll-tabs gl-border-none"
2018-03-17 18:26:18 +05:30
>
2020-11-24 15:15:51 +05:30
<div class="fade-left"><gl-icon name="chevron-lg-left" :size="12" /></div>
<div class="fade-right"><gl-icon name="chevron-lg-right" :size="12" /></div>
2018-03-17 18:26:18 +05:30
2017-09-10 17:25:29 +05:30
<navigation-tabs
2018-03-27 19:54:05 +05:30
v-if="shouldRenderTabs"
2018-03-17 18:26:18 +05:30
:tabs="tabs"
scope="pipelines"
2018-11-08 19:23:39 +05:30
@onChangeTab="onChangeTab"
2018-03-17 18:26:18 +05:30
/>
2017-09-10 17:25:29 +05:30
<navigation-controls
2018-03-27 19:54:05 +05:30
v-if="shouldRenderButtons"
2017-09-10 17:25:29 +05:30
:new-pipeline-path="newPipelinePath"
2018-03-17 18:26:18 +05:30
:reset-cache-path="resetCachePath"
:ci-lint-path="ciLintPath"
2018-05-09 12:01:36 +05:30
:is-reset-cache-button-loading="isResetCacheButtonLoading"
2018-11-08 19:23:39 +05:30
@resetRunnersCache="handleResetRunnersCache"
2018-03-17 18:26:18 +05:30
/>
2017-09-10 17:25:29 +05:30
</div>
2020-05-24 23:13:21 +05:30
<pipelines-filtered-search
2021-04-29 21:17:54 +05:30
v-if="stateToRender !== $options.stateMap.emptyState"
2020-05-24 23:13:21 +05:30
:project-id="projectId"
2020-06-23 00:09:42 +05:30
:params="validatedParams"
2020-05-24 23:13:21 +05:30
@filterPipelines="filterPipelines"
/>
2017-09-10 17:25:29 +05:30
<div class="content-list pipelines">
2018-12-05 23:21:45 +05:30
<gl-loading-icon
2018-03-27 19:54:05 +05:30
v-if="stateToRender === $options.stateMap.loading"
:label="s__('Pipelines|Loading Pipelines')"
2020-04-22 19:07:51 +05:30
size="lg"
2018-03-17 18:26:18 +05:30
class="prepend-top-20"
/>
2017-09-10 17:25:29 +05:30
<empty-state
2018-03-27 19:54:05 +05:30
v-else-if="stateToRender === $options.stateMap.emptyState"
2018-03-17 18:26:18 +05:30
:empty-state-svg-path="emptyStateSvgPath"
2018-03-27 19:54:05 +05:30
:can-set-ci="canCreatePipeline"
2021-06-08 01:23:25 +05:30
:code-quality-page-path="codeQualityPagePath"
2018-03-17 18:26:18 +05:30
/>
2017-09-10 17:25:29 +05:30
2021-04-29 21:17:54 +05:30
<gl-empty-state
2018-03-27 19:54:05 +05:30
v-else-if="stateToRender === $options.stateMap.error"
:svg-path="errorStateSvgPath"
2021-04-29 21:17:54 +05:30
:title="
2019-02-15 15:39:39 +05:30
s__(`Pipelines|There was an error fetching the pipelines.
Try again in a few moments or contact your support team.`)
"
2018-03-17 18:26:18 +05:30
/>
2017-09-10 17:25:29 +05:30
2021-04-29 21:17:54 +05:30
<gl-empty-state
2018-03-27 19:54:05 +05:30
v-else-if="stateToRender === $options.stateMap.emptyTab"
:svg-path="noPipelinesSvgPath"
2021-04-29 21:17:54 +05:30
:title="emptyTabMessage"
2018-03-27 19:54:05 +05:30
/>
2017-09-10 17:25:29 +05:30
2021-01-29 00:20:46 +05:30
<div v-else-if="stateToRender === $options.stateMap.tableList">
2017-09-10 17:25:29 +05:30
<pipelines-table-component
:pipelines="state.pipelines"
2020-07-28 23:09:34 +05:30
:pipeline-schedule-url="pipelineScheduleUrl"
2017-09-10 17:25:29 +05:30
:update-graph-dropdown="updateGraphDropdown"
2018-03-17 18:26:18 +05:30
:view-type="viewType"
/>
2017-09-10 17:25:29 +05:30
</div>
<table-pagination
v-if="shouldRenderPagination"
2018-03-17 18:26:18 +05:30
:change="onChangePage"
:page-info="state.pageInfo"
/>
2017-09-10 17:25:29 +05:30
</div>
</div>
</template>