Commit 85e6aa4c authored by Miguel Rincon's avatar Miguel Rincon

Move pipeline mixin logic to a single file

This removes multiple inheritance in the pipelines table file

This change moves the logic from the share mixin to a single
file so that methods are easier to locate.
parent 966392e7
...@@ -2,21 +2,24 @@ ...@@ -2,21 +2,24 @@
import { GlButton, GlLoadingIcon, GlModal, GlLink } from '@gitlab/ui'; import { GlButton, GlLoadingIcon, GlModal, GlLink } from '@gitlab/ui';
import { getParameterByName } from '~/lib/utils/common_utils'; import { getParameterByName } from '~/lib/utils/common_utils';
import eventHub from '~/pipelines/event_hub'; import eventHub from '~/pipelines/event_hub';
import pipelinesMixin from '~/pipelines/mixins/pipelines'; import PipelinesMixin from '~/pipelines/mixins/pipelines_mixin';
import PipelinesPaginationApiMixin from '~/pipelines/mixins/pipelines_pagination_api_mixin';
import PipelinesService from '~/pipelines/services/pipelines_service'; import PipelinesService from '~/pipelines/services/pipelines_service';
import PipelineStore from '~/pipelines/stores/pipelines_store'; import PipelineStore from '~/pipelines/stores/pipelines_store';
import PipelinesTableComponent from '~/pipelines/components/pipelines_list/pipelines_table.vue';
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue'; import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';
import SvgBlankState from '~/pipelines/components/pipelines_list/blank_state.vue';
export default { export default {
components: { components: {
TablePagination,
GlButton, GlButton,
GlLink,
GlLoadingIcon, GlLoadingIcon,
GlModal, GlModal,
GlLink, PipelinesTableComponent,
TablePagination,
SvgBlankState,
}, },
mixins: [pipelinesMixin, PipelinesPaginationApiMixin], mixins: [PipelinesMixin],
props: { props: {
endpoint: { endpoint: {
type: String, type: String,
......
<script> <script>
import { GlIcon } from '@gitlab/ui'; import { GlIcon, GlLoadingIcon } from '@gitlab/ui';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import { deprecatedCreateFlash as createFlash } from '~/flash'; import { deprecatedCreateFlash as createFlash } from '~/flash';
import { getParameterByName } from '~/lib/utils/common_utils'; import { getParameterByName } from '~/lib/utils/common_utils';
...@@ -7,22 +7,28 @@ import { __, s__ } from '~/locale'; ...@@ -7,22 +7,28 @@ import { __, s__ } from '~/locale';
import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue'; import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue';
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue'; import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';
import { ANY_TRIGGER_AUTHOR, RAW_TEXT_WARNING, FILTER_TAG_IDENTIFIER } from '../../constants'; import { ANY_TRIGGER_AUTHOR, RAW_TEXT_WARNING, FILTER_TAG_IDENTIFIER } from '../../constants';
import pipelinesMixin from '../../mixins/pipelines'; import PipelinesMixin from '../../mixins/pipelines_mixin';
import PipelinesPaginationApiMixin from '../../mixins/pipelines_pagination_api_mixin';
import PipelinesService from '../../services/pipelines_service'; import PipelinesService from '../../services/pipelines_service';
import { validateParams } from '../../utils'; import { validateParams } from '../../utils';
import EmptyState from './empty_state.vue';
import NavigationControls from './nav_controls.vue'; import NavigationControls from './nav_controls.vue';
import PipelinesFilteredSearch from './pipelines_filtered_search.vue'; import PipelinesFilteredSearch from './pipelines_filtered_search.vue';
import PipelinesTableComponent from './pipelines_table.vue';
import SvgBlankState from './blank_state.vue';
export default { export default {
components: { components: {
TablePagination, EmptyState,
GlIcon,
GlLoadingIcon,
NavigationTabs, NavigationTabs,
NavigationControls, NavigationControls,
PipelinesFilteredSearch, PipelinesFilteredSearch,
GlIcon, PipelinesTableComponent,
SvgBlankState,
TablePagination,
}, },
mixins: [pipelinesMixin, PipelinesPaginationApiMixin], mixins: [PipelinesMixin],
props: { props: {
store: { store: {
type: Object, type: Object,
...@@ -217,6 +223,20 @@ export default { ...@@ -217,6 +223,20 @@ export default {
this.requestData = { page: this.page, scope: this.scope, ...this.validatedParams }; this.requestData = { page: this.page, scope: this.scope, ...this.validatedParams };
}, },
methods: { methods: {
onChangeTab(scope) {
if (this.scope === scope) {
return;
}
let params = {
scope,
page: '1',
};
params = this.onChangeWithFilter(params);
this.updateContent(params);
},
successCallback(resp) { successCallback(resp) {
// Because we are polling & the user is interacting verify if the response received // Because we are polling & the user is interacting verify if the response received
// matches the last request made // matches the last request made
......
import { GlLoadingIcon } from '@gitlab/ui';
import Visibility from 'visibilityjs'; import Visibility from 'visibilityjs';
import { deprecatedCreateFlash as createFlash } from '~/flash'; import { deprecatedCreateFlash as createFlash } from '~/flash';
import Poll from '~/lib/utils/poll'; import Poll from '~/lib/utils/poll';
import { historyPushState, buildUrlWithCurrentLocation } from '~/lib/utils/common_utils';
import { validateParams } from '~/pipelines/utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import SvgBlankState from '../components/pipelines_list/blank_state.vue';
import EmptyState from '../components/pipelines_list/empty_state.vue';
import PipelinesTableComponent from '../components/pipelines_list/pipelines_table.vue';
import { CANCEL_REQUEST } from '../constants'; import { CANCEL_REQUEST } from '../constants';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
components: {
PipelinesTableComponent,
SvgBlankState,
EmptyState,
GlLoadingIcon,
},
data() { data() {
return { return {
isLoading: false, isLoading: false,
...@@ -76,6 +68,25 @@ export default { ...@@ -76,6 +68,25 @@ export default {
this.poll.stop(); this.poll.stop();
}, },
methods: { methods: {
updateInternalState(parameters) {
this.poll.stop();
const queryString = Object.keys(parameters)
.map((parameter) => {
const value = parameters[parameter];
// update internal state for UI
this[parameter] = value;
return `${parameter}=${encodeURIComponent(value)}`;
})
.join('&');
// update polling parameters
this.requestData = parameters;
historyPushState(buildUrlWithCurrentLocation(`?${queryString}`));
this.isLoading = true;
},
/** /**
* Handles URL and query parameter changes. * Handles URL and query parameter changes.
* When the user uses the pagination or the tabs, * When the user uses the pagination or the tabs,
...@@ -184,5 +195,23 @@ export default { ...@@ -184,5 +195,23 @@ export default {
}) })
.finally(() => this.store.toggleIsRunningPipeline(false)); .finally(() => this.store.toggleIsRunningPipeline(false));
}, },
onChangePage(page) {
/* URLS parameters are strings, we need to parse to match types */
let params = {
page: Number(page).toString(),
};
if (this.scope) {
params.scope = this.scope;
}
params = this.onChangeWithFilter(params);
this.updateContent(params);
},
onChangeWithFilter(params) {
return { ...params, ...validateParams(this.requestData) };
},
}, },
}; };
/**
* API callbacks for pagination and tabs
*
* Components need to have `scope`, `page` and `requestData`
*/
import { validateParams } from '~/pipelines/utils';
import { historyPushState, buildUrlWithCurrentLocation } from '../../lib/utils/common_utils';
export default {
methods: {
onChangeTab(scope) {
if (this.scope === scope) {
return;
}
let params = {
scope,
page: '1',
};
params = this.onChangeWithFilter(params);
this.updateContent(params);
},
onChangePage(page) {
/* URLS parameters are strings, we need to parse to match types */
let params = {
page: Number(page).toString(),
};
if (this.scope) {
params.scope = this.scope;
}
params = this.onChangeWithFilter(params);
this.updateContent(params);
},
onChangeWithFilter(params) {
return { ...params, ...validateParams(this.requestData) };
},
updateInternalState(parameters) {
// stop polling
this.poll.stop();
const queryString = Object.keys(parameters)
.map((parameter) => {
const value = parameters[parameter];
// update internal state for UI
this[parameter] = value;
return `${parameter}=${encodeURIComponent(value)}`;
})
.join('&');
// update polling parameters
this.requestData = parameters;
historyPushState(buildUrlWithCurrentLocation(`?${queryString}`));
this.isLoading = true;
},
},
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment