Commit 4dd67a77 authored by Alexander Turinske's avatar Alexander Turinske

Use generalized PAGE_SIZE constant and utils

- condense PAGE_SIZE usage in ee/threat_monitoring
  to one constant
- utilize existing utils for parsing response headers
parent 995503b7
...@@ -17,18 +17,11 @@ import getAlertsQuery from '~/graphql_shared/queries/get_alerts.query.graphql'; ...@@ -17,18 +17,11 @@ import getAlertsQuery from '~/graphql_shared/queries/get_alerts.query.graphql';
import { convertToSnakeCase } from '~/lib/utils/text_utility'; import { convertToSnakeCase } from '~/lib/utils/text_utility';
import { joinPaths } from '~/lib/utils/url_utility'; import { joinPaths } from '~/lib/utils/url_utility';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
import { PAGE_SIZE } from 'ee/threat_monitoring/constants';
import AlertDrawer from './alert_drawer.vue'; import AlertDrawer from './alert_drawer.vue';
import AlertFilters from './alert_filters.vue'; import AlertFilters from './alert_filters.vue';
import AlertStatus from './alert_status.vue'; import AlertStatus from './alert_status.vue';
import { import { DEFAULT_FILTERS, FIELDS, MESSAGES, STATUSES, DOMAIN, CLOSED } from './constants';
DEFAULT_FILTERS,
FIELDS,
MESSAGES,
PAGE_SIZE,
STATUSES,
DOMAIN,
CLOSED,
} from './constants';
export default { export default {
PAGE_SIZE, PAGE_SIZE,
......
...@@ -62,8 +62,6 @@ export const FIELDS = [ ...@@ -62,8 +62,6 @@ export const FIELDS = [
}, },
]; ];
export const PAGE_SIZE = 20;
export const DEFAULT_FILTERS = { statuses: ['TRIGGERED', 'ACKNOWLEDGED'] }; export const DEFAULT_FILTERS = { statuses: ['TRIGGERED', 'ACKNOWLEDGED'] };
export const DOMAIN = 'threat_monitoring'; export const DOMAIN = 'threat_monitoring';
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
import produce from 'immer'; import produce from 'immer';
import getUsersProjects from '~/graphql_shared/queries/get_users_projects.query.graphql'; import getUsersProjects from '~/graphql_shared/queries/get_users_projects.query.graphql';
import ProjectSelector from '~/vue_shared/components/project_selector/project_selector.vue'; import ProjectSelector from '~/vue_shared/components/project_selector/project_selector.vue';
import { PAGE_SIZE } from 'ee/threat_monitoring/constants';
const defaultPageInfo = { endCursor: '', hasNextPage: false }; const defaultPageInfo = { endCursor: '', hasNextPage: false };
export default { export default {
MINIMUM_QUERY_LENGTH: 3, MINIMUM_QUERY_LENGTH: 3,
PROJECTS_PER_PAGE: 20,
SEARCH_ERROR: 'SEARCH_ERROR', SEARCH_ERROR: 'SEARCH_ERROR',
QUERY_TOO_SHORT_ERROR: 'QUERY_TOO_SHORT_ERROR', QUERY_TOO_SHORT_ERROR: 'QUERY_TOO_SHORT_ERROR',
NO_RESULTS_ERROR: 'NO_RESULTS_ERROR', NO_RESULTS_ERROR: 'NO_RESULTS_ERROR',
...@@ -17,7 +17,7 @@ export default { ...@@ -17,7 +17,7 @@ export default {
variables() { variables() {
return { return {
search: this.searchQuery, search: this.searchQuery,
first: this.$options.PROJECTS_PER_PAGE, first: PAGE_SIZE,
searchNamespaces: true, searchNamespaces: true,
sort: 'similarity', sort: 'similarity',
}; };
......
...@@ -43,3 +43,5 @@ spec: ...@@ -43,3 +43,5 @@ spec:
]; ];
export const ALL_ENVIRONMENT_NAME = s__('ThreatMonitoring|All Environments'); export const ALL_ENVIRONMENT_NAME = s__('ThreatMonitoring|All Environments');
export const PAGE_SIZE = 20;
import createFlash from '~/flash'; import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { PAGE_SIZE } from 'ee/threat_monitoring/constants';
import * as types from './mutation_types'; import * as types from './mutation_types';
export const setEnvironmentEndpoint = ({ commit }, endpoint) => { export const setEnvironmentEndpoint = ({ commit }, endpoint) => {
...@@ -29,12 +31,12 @@ const getEnvironments = async (url, page = 1) => { ...@@ -29,12 +31,12 @@ const getEnvironments = async (url, page = 1) => {
try { try {
const { data, headers } = await axios.get(url, { const { data, headers } = await axios.get(url, {
params: { params: {
per_page: 20, per_page: PAGE_SIZE,
page, page,
}, },
}); });
const nextPage = headers && headers['x-next-page']; const { nextPage } = parseIntPagination(normalizeHeaders(headers));
return { environments: data.environments, nextPage }; return { environments: data.environments, nextPage };
} catch { } catch {
throw new Error(); throw new Error();
......
...@@ -13,7 +13,7 @@ jest.mock('~/flash'); ...@@ -13,7 +13,7 @@ jest.mock('~/flash');
const environmentsEndpoint = 'environmentsEndpoint'; const environmentsEndpoint = 'environmentsEndpoint';
const networkPolicyStatisticsEndpoint = 'networkPolicyStatisticsEndpoint'; const networkPolicyStatisticsEndpoint = 'networkPolicyStatisticsEndpoint';
const nextPage = 'someHash'; const nextPage = 2;
describe('Threat Monitoring actions', () => { describe('Threat Monitoring actions', () => {
let state; let state;
......
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