Skip to content
Snippets Groups Projects
Verified Commit e4cb0b9e authored by Artur Fedorov's avatar Artur Fedorov :speech_balloon: Committed by GitLab
Browse files

Merge branch '527204-create-constants-file' into 'master'

Create constants file

See merge request gitlab-org/gitlab!186379



Merged-by: default avatarArtur Fedorov <afedorov@gitlab.com>
Approved-by: default avatarArtur Fedorov <afedorov@gitlab.com>
Reviewed-by: default avatarArtur Fedorov <afedorov@gitlab.com>
Co-authored-by: Alexander Turinske's avatarAlexander Turinske <aturinske@gitlab.com>
parents 63a2c161 413ac484
No related branches found
No related tags found
No related merge requests found
import { __ } from '~/locale';
import { getWeekdayNames } from '~/lib/utils/datetime_utility';
import { DAILY } from '../constants';
export const DEFAULT_TIMEZONE = 'Etc/UTC';
export const DEFAULT_START_WEEKDAY = 'Monday';
export const DEFAULT_START_MONTH_DAY = 1;
export const WEEKLY = 'weekly';
export const MONTHLY = 'monthly';
export const MINIMUM_SECONDS = 600; // 10 minutes, set in ee/app/validators/json_schemas/security_orchestration_policy.json
export const MINIMUM_SECONDS_IN_MINUTES = MINIMUM_SECONDS / 60;
export const MAXIMUM_SECONDS = 2629746; // 30 days, set in ee/app/validators/json_schemas/security_orchestration_policy.json
export const CADENCE_OPTIONS = [
{ value: DAILY, text: __('Daily') },
{ value: WEEKLY, text: __('Weekly') },
{ value: MONTHLY, text: __('Monthly') },
];
// Constants for time units in seconds
export const TIME_UNITS = {
MINUTE: 60,
HOUR: 3600,
DAY: 86400, // 24 hours * 60 minutes * 60 seconds
};
export const CADENCE_CONFIG = {
[DAILY]: {
time_window: { value: TIME_UNITS.MINUTE },
},
[WEEKLY]: {
days: [DEFAULT_START_WEEKDAY],
time_window: { value: TIME_UNITS.DAY },
},
[MONTHLY]: {
days_of_month: [DEFAULT_START_MONTH_DAY],
time_window: { value: TIME_UNITS.DAY },
},
};
export const TIME_UNIT_OPTIONS = [
{ value: TIME_UNITS.MINUTE, text: __('Minutes') },
{ value: TIME_UNITS.HOUR, text: __('Hours') },
{ value: TIME_UNITS.DAY, text: __('Days') },
];
// Constants for time units in seconds
export const DEFAULT_TIME_PER_UNIT = {
[TIME_UNITS.MINUTE]: MINIMUM_SECONDS,
[TIME_UNITS.HOUR]: TIME_UNITS.HOUR,
[TIME_UNITS.DAY]: TIME_UNITS.DAY,
};
/**
* Time options in one hour increments for the daily scheduler
* @returns {Array} Array of time options
*/
export const HOUR_MINUTE_LIST = Array.from(Array(24).keys()).map((num) => {
const hour = num.toString().length === 1 ? `0${num}:00` : `${num}:00`;
return { value: hour, text: hour };
});
/**
* Weekday options for the weekly scheduler
* @returns {Array} Array of weekday options
*/
export const WEEKDAY_OPTIONS = getWeekdayNames().map((day) => {
return { value: day, text: day };
});
......@@ -9,15 +9,17 @@ import BranchSelection from 'ee/security_orchestration/components/policy_editor/
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown/timezone_dropdown.vue';
import { getHostname } from '../../utils';
import { PROJECT_DEFAULT_BRANCH } from '../../constants';
import { DEFAULT_TIMEZONE } from './constants';
import {
CADENCE_OPTIONS,
DEFAULT_TIME_PER_UNIT,
DEFAULT_TIMEZONE,
HOUR_MINUTE_LIST,
MINIMUM_SECONDS_IN_MINUTES,
WEEKDAY_OPTIONS,
TIME_UNIT_OPTIONS,
TIME_UNITS,
WEEKDAY_OPTIONS,
} from './constants';
import {
isCadenceWeekly,
isCadenceMonthly,
isValidCadence,
......
import { __ } from '~/locale';
import { isNumeric } from '~/lib/utils/number_utils';
import { getWeekdayNames } from '~/lib/utils/datetime_utility';
import { DAILY, WEEKLY, MONTHLY } from '../constants';
import { CADENCE_CONFIG, MAXIMUM_SECONDS, MINIMUM_SECONDS, TIME_UNITS } from './constants';
const DEFAULT_START_WEEKDAY = 'Monday';
const DEFAULT_START_MONTH_DAY = 1;
export const MINIMUM_SECONDS = 600; // 10 minutes, set in ee/app/validators/json_schemas/security_orchestration_policy.json
export const MINIMUM_SECONDS_IN_MINUTES = MINIMUM_SECONDS / 60;
export const MAXIMUM_SECONDS = 2629746; // 30 days, set in ee/app/validators/json_schemas/security_orchestration_policy.json
export const isCadenceWeekly = (cadence) => cadence === WEEKLY;
export const isCadenceMonthly = (cadence) => cadence === MONTHLY;
export const CADENCE_OPTIONS = [
{ value: DAILY, text: __('Daily') },
{ value: WEEKLY, text: __('Weekly') },
{ value: MONTHLY, text: __('Monthly') },
];
// Constants for time units in seconds
export const TIME_UNITS = {
MINUTE: 60,
HOUR: 3600,
DAY: 86400, // 24 hours * 60 minutes * 60 seconds
};
// Constants for time units in seconds
export const DEFAULT_TIME_PER_UNIT = {
[TIME_UNITS.MINUTE]: MINIMUM_SECONDS,
[TIME_UNITS.HOUR]: TIME_UNITS.HOUR,
[TIME_UNITS.DAY]: TIME_UNITS.DAY,
};
export const TIME_UNIT_OPTIONS = [
{ value: TIME_UNITS.MINUTE, text: __('Minutes') },
{ value: TIME_UNITS.HOUR, text: __('Hours') },
{ value: TIME_UNITS.DAY, text: __('Days') },
];
const CADENCE_CONFIG = {
[DAILY]: {
time_window: { value: TIME_UNITS.MINUTE },
},
[WEEKLY]: {
days: [DEFAULT_START_WEEKDAY],
time_window: { value: TIME_UNITS.DAY },
},
[MONTHLY]: {
days_of_month: [DEFAULT_START_MONTH_DAY],
time_window: { value: TIME_UNITS.DAY },
},
};
/**
* Ensures the time is within the limits
* @param {number} time - Time value in seconds
......@@ -78,23 +31,6 @@ export const updateScheduleCadence = ({ schedule, cadence }) => {
return updatedSchedule;
};
/**
* Time options in one hour increments for the daily scheduler
* @returns {Array} Array of time options
*/
export const HOUR_MINUTE_LIST = Array.from(Array(24).keys()).map((num) => {
const hour = num.toString().length === 1 ? `0${num}:00` : `${num}:00`;
return { value: hour, text: hour };
});
/**
* Weekday options for the weekly scheduler
* @returns {Array} Array of weekday options
*/
export const WEEKDAY_OPTIONS = getWeekdayNames().map((day) => {
return { value: day, text: day };
});
/**
* Generate options for monthly day selection
* @returns {Array} Array of day options
......
......@@ -4,11 +4,11 @@ import ScheduleForm from 'ee/security_orchestration/components/policy_editor/pip
import BranchSelection from 'ee/security_orchestration/components/policy_editor/scan_result/rule/branch_selection.vue';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown/timezone_dropdown.vue';
import {
TIME_UNITS,
MINIMUM_SECONDS,
MAXIMUM_SECONDS,
DEFAULT_TIME_PER_UNIT,
} from 'ee/security_orchestration/components/policy_editor/pipeline_execution/rule/utils';
MAXIMUM_SECONDS,
MINIMUM_SECONDS,
TIME_UNITS,
} from 'ee/security_orchestration/components/policy_editor/pipeline_execution/rule/constants';
jest.mock('ee/security_orchestration/components/policy_editor/utils', () => ({
...jest.requireActual('ee/security_orchestration/components/policy_editor/utils'),
......
......@@ -4,10 +4,12 @@ import {
secondsToValue,
timeUnitToSeconds,
updateScheduleCadence,
} from 'ee/security_orchestration/components/policy_editor/pipeline_execution/rule/utils';
import {
MAXIMUM_SECONDS,
MINIMUM_SECONDS,
TIME_UNITS,
} from 'ee/security_orchestration/components/policy_editor/pipeline_execution/rule/utils';
} from 'ee/security_orchestration/components/policy_editor/pipeline_execution/rule/constants';
describe('Pipeline execution rule utils', () => {
describe('getValueWithinLimits', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment