Commit 1eda0077 authored by pburdette's avatar pburdette

Validate query params

Validate query params and
clean up the code. Also updated
a few specs.
parent 84b93dc1
<script> <script>
import { isEqual } from 'lodash'; import { isEqual, pickBy } from 'lodash';
import { __, sprintf, s__ } from '../../locale'; import { __, sprintf, s__ } from '../../locale';
import createFlash from '../../flash'; import createFlash from '../../flash';
import PipelinesService from '../services/pipelines_service'; import PipelinesService from '../services/pipelines_service';
...@@ -10,7 +10,7 @@ import NavigationControls from './nav_controls.vue'; ...@@ -10,7 +10,7 @@ import NavigationControls from './nav_controls.vue';
import { getParameterByName } from '../../lib/utils/common_utils'; import { getParameterByName } from '../../lib/utils/common_utils';
import CIPaginationMixin from '../../vue_shared/mixins/ci_pagination_api_mixin'; import CIPaginationMixin from '../../vue_shared/mixins/ci_pagination_api_mixin';
import PipelinesFilteredSearch from './pipelines_filtered_search.vue'; import PipelinesFilteredSearch from './pipelines_filtered_search.vue';
import { ANY_TRIGGER_AUTHOR, RAW_TEXT_WARNING } from '../constants'; import { ANY_TRIGGER_AUTHOR, RAW_TEXT_WARNING, SUPPORTED_FILTER_PARAMETERS } from '../constants';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
export default { export default {
...@@ -224,20 +224,15 @@ export default { ...@@ -224,20 +224,15 @@ export default {
canFilterPipelines() { canFilterPipelines() {
return this.glFeatures.filterPipelinesSearch; return this.glFeatures.filterPipelinesSearch;
}, },
validatedParams() {
return pickBy(this.params, (val, key) => SUPPORTED_FILTER_PARAMETERS.includes(key) && val);
},
}, },
created() { created() {
const { username, ref } = this.params;
this.service = new PipelinesService(this.endpoint); this.service = new PipelinesService(this.endpoint);
this.requestData = { page: this.page, scope: this.scope }; this.requestData = { page: this.page, scope: this.scope };
if (username) { Object.assign(this.requestData, this.validatedParams);
this.requestData.username = username;
}
if (ref) {
this.requestData.ref = ref;
}
}, },
methods: { methods: {
successCallback(resp) { successCallback(resp) {
...@@ -320,7 +315,7 @@ export default { ...@@ -320,7 +315,7 @@ export default {
v-if="canFilterPipelines" v-if="canFilterPipelines"
:pipelines="state.pipelines" :pipelines="state.pipelines"
:project-id="projectId" :project-id="projectId"
:params="params" :params="validatedParams"
@filterPipelines="filterPipelines" @filterPipelines="filterPipelines"
/> />
......
...@@ -3,6 +3,7 @@ import { GlFilteredSearch } from '@gitlab/ui'; ...@@ -3,6 +3,7 @@ import { GlFilteredSearch } from '@gitlab/ui';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import PipelineTriggerAuthorToken from './tokens/pipeline_trigger_author_token.vue'; import PipelineTriggerAuthorToken from './tokens/pipeline_trigger_author_token.vue';
import PipelineBranchNameToken from './tokens/pipeline_branch_name_token.vue'; import PipelineBranchNameToken from './tokens/pipeline_branch_name_token.vue';
import { map } from 'lodash';
export default { export default {
components: { components: {
...@@ -46,30 +47,10 @@ export default { ...@@ -46,30 +47,10 @@ export default {
]; ];
}, },
paramsValue() { paramsValue() {
const valueArray = []; return map(this.params, (val, key) => ({
const { username, ref } = this.params; type: key,
value: { data: val, operator: '=' },
if (username) { }));
valueArray.push({
type: 'username',
value: {
data: username,
operator: '=',
},
});
}
if (ref) {
valueArray.push({
type: 'ref',
value: {
data: ref,
operator: '=',
},
});
}
return valueArray;
}, },
}, },
methods: { methods: {
......
...@@ -5,6 +5,7 @@ export const PIPELINES_TABLE = 'PIPELINES_TABLE'; ...@@ -5,6 +5,7 @@ export const PIPELINES_TABLE = 'PIPELINES_TABLE';
export const LAYOUT_CHANGE_DELAY = 300; export const LAYOUT_CHANGE_DELAY = 300;
export const FILTER_PIPELINES_SEARCH_DELAY = 200; export const FILTER_PIPELINES_SEARCH_DELAY = 200;
export const ANY_TRIGGER_AUTHOR = 'Any'; export const ANY_TRIGGER_AUTHOR = 'Any';
export const SUPPORTED_FILTER_PARAMETERS = ['username', 'ref'];
export const TestStatus = { export const TestStatus = {
FAILED: 'failed', FAILED: 'failed',
......
...@@ -78,10 +78,8 @@ describe('Pipelines filtered search', () => { ...@@ -78,10 +78,8 @@ describe('Pipelines filtered search', () => {
describe('Url query params', () => { describe('Url query params', () => {
const params = { const params = {
page: '1',
ref: 'master',
scope: 'all',
username: 'deja.green', username: 'deja.green',
ref: 'master',
}; };
beforeEach(() => { beforeEach(() => {
......
...@@ -65,6 +65,7 @@ describe('Pipeline Branch Name Token', () => { ...@@ -65,6 +65,7 @@ describe('Pipeline Branch Name Token', () => {
expect(Api.branches).toHaveBeenCalled(); expect(Api.branches).toHaveBeenCalled();
expect(wrapper.vm.branches).toEqual(mockBranchesAfterMap); expect(wrapper.vm.branches).toEqual(mockBranchesAfterMap);
expect(findLoadingIcon().exists()).toBe(false);
}); });
describe('displays loading icon correctly', () => { describe('displays loading icon correctly', () => {
......
...@@ -64,6 +64,7 @@ describe('Pipeline Trigger Author Token', () => { ...@@ -64,6 +64,7 @@ describe('Pipeline Trigger Author Token', () => {
expect(Api.projectUsers).toHaveBeenCalled(); expect(Api.projectUsers).toHaveBeenCalled();
expect(wrapper.vm.users).toEqual(users); expect(wrapper.vm.users).toEqual(users);
expect(findLoadingIcon().exists()).toBe(false);
}); });
describe('displays loading icon correctly', () => { describe('displays loading icon correctly', () => {
......
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