Skip to content

Commit 304e8d7

Browse files
committed
fix no-magic-numbers errors
1 parent 77e71ac commit 304e8d7

12 files changed

Lines changed: 53 additions & 21 deletions

File tree

webpack/JobInvocationDetail/JobInvocationActions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
UPDATE_JOB,
1616
} from './JobInvocationConstants';
1717

18+
const POLLING_INTERVAL_MS = 1000;
19+
1820
export const getJobInvocation = url => dispatch => {
1921
const fetchData = withInterval(
2022
get({
@@ -32,7 +34,7 @@ export const getJobInvocation = url => dispatch => {
3234
response?.data?.error?.message ||
3335
'Error',
3436
}),
35-
1000
37+
POLLING_INTERVAL_MS
3638
);
3739

3840
dispatch(fetchData);

webpack/JobInvocationDetail/JobInvocationSystemStatusChart.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ const JobInvocationSystemStatusChart = ({
5252
return '0';
5353
};
5454
const chartSize = 105;
55-
const [legendWidth, setLegendWidth] = useState(270);
55+
const defaultLegendWidth = 270;
56+
const [legendWidth, setLegendWidth] = useState(defaultLegendWidth);
5657

5758
// Calculates chart legend width based on its content
5859
useEffect(() => {

webpack/JobInvocationDetail/TemplateInvocation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import { OutputToggleGroup } from './TemplateInvocationComponents/OutputToggleGr
2020
import { PreviewTemplate } from './TemplateInvocationComponents/PreviewTemplate';
2121
import { OutputCodeBlock } from './TemplateInvocationComponents/OutputCodeBlock';
2222

23+
const COPIED_EXIT_DELAY_MS = 1500;
24+
const DEFAULT_EXIT_DELAY_MS = 600;
25+
const AUTO_REFRESH_INTERVAL_MS = 5000;
26+
2327
const CopyToClipboard = ({ fullOutput }) => {
2428
const clipboardCopyFunc = async (event, text) => {
2529
try {
@@ -41,7 +45,7 @@ const CopyToClipboard = ({ fullOutput }) => {
4145
textId="code-content"
4246
aria-label="Copy to clipboard"
4347
onClick={e => onClick(e, fullOutput)}
44-
exitDelay={copied ? 1500 : 600}
48+
exitDelay={copied ? COPIED_EXIT_DELAY_MS : DEFAULT_EXIT_DELAY_MS}
4549
maxWidth="110px"
4650
variant="plain"
4751
onTooltipHidden={() => setCopied(false)}
@@ -111,7 +115,7 @@ export const TemplateInvocation = ({
111115
} else if (intervalRef.current) {
112116
clearInterval(intervalRef.current);
113117
}
114-
}, 5000);
118+
}, AUTO_REFRESH_INTERVAL_MS);
115119
}
116120

117121
return () => {

webpack/JobInvocationDetail/TemplateInvocationComponents/OutputCodeBlock.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import PropTypes from 'prop-types';
88
import { Button } from '@patternfly/react-core';
99
import { translate as __ } from 'foremanReact/common/I18n';
1010

11+
const MS_PER_SECOND = 1000;
12+
1113
export const OutputCodeBlock = ({ code, showOutputType, scrollElement }) => {
1214
let lineCounter = 0;
1315
// eslint-disable-next-line no-control-regex
@@ -122,7 +124,7 @@ export const OutputCodeBlock = ({ code, showOutputType, scrollElement }) => {
122124
<div key={index} className={`line ${line.output_type}`}>
123125
<span
124126
className="counter"
125-
title={new Date(line.timestamp * 1000).toISOString()}
127+
title={new Date(line.timestamp * MS_PER_SECOND).toISOString()}
126128
>
127129
{lineCounter.toString().padStart(4, '\u00A0')}:{' '}
128130
</span>

webpack/JobWizard/JobWizard.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import { StartsBeforeErrorAlert, StartsAtErrorAlert } from './StartsErrorAlert';
4040
import { Footer } from './Footer';
4141
import './JobWizard.scss';
4242

43+
const SCHEDULE_CHECK_INTERVAL_MS = 5000;
44+
4345
export const JobWizard = ({ rerunData }) => {
4446
const routerSearch = useSelector(selectRouterSearch);
4547
const [feature, setFeature] = useState(routerSearch.feature);
@@ -237,7 +239,7 @@ export const JobWizard = ({ rerunData }) => {
237239
}
238240
};
239241
updateStartsError();
240-
const interval = setInterval(updateStartsError, 5000);
242+
const interval = setInterval(updateStartsError, SCHEDULE_CHECK_INTERVAL_MS);
241243

242244
return () => {
243245
interval && clearInterval(interval);

webpack/JobWizard/steps/Schedule/RepeatHour.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ import {
1414
import { translate as __ } from 'foremanReact/common/I18n';
1515
import { helpLabel } from '../form/FormHelpers';
1616

17+
const MINUTES_IN_HOUR = 60;
18+
const DEFAULT_MINUTE_OPTIONS = [0, 15, 30, 45];
19+
1720
export const RepeatHour = ({ repeatData, setRepeatData }) => {
1821
const isValidMinute = newMinute =>
1922
Number.isInteger(parseInt(newMinute, 10)) &&
2023
newMinute >= 0 &&
21-
newMinute < 60;
24+
newMinute < MINUTES_IN_HOUR;
2225

2326
const { minute } = repeatData;
2427
useEffect(() => {
@@ -27,7 +30,7 @@ export const RepeatHour = ({ repeatData, setRepeatData }) => {
2730
}
2831
}, [minute, setRepeatData]);
2932
const [minuteOpen, setMinuteOpen] = useState(false);
30-
const [options, setOptions] = useState([0, 15, 30, 45]);
33+
const [options, setOptions] = useState(DEFAULT_MINUTE_OPTIONS);
3134
const [isAlertOpen, setIsAlertOpen] = useState(false);
3235
return (
3336
<FormGroup

webpack/JobWizard/steps/Schedule/RepeatWeek.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import { translate as __, documentLocale } from 'foremanReact/common/I18n';
55
import { RepeatDaily } from './RepeatDaily';
66
import { noop } from '../../../helpers';
77

8+
const SUNDAY_REFERENCE_YEAR = 2017;
9+
const DAYS_IN_WEEK = 7;
10+
811
export const getWeekDays = () => {
912
const locale = documentLocale().replace(/-/g, '_');
10-
const baseDate = new Date(Date.UTC(2017, 0, 1)); // just a Sunday
13+
const baseDate = new Date(Date.UTC(SUNDAY_REFERENCE_YEAR, 0, 1));
1114
const weekDays = [];
1215
const formatOptions = { weekday: 'short', timeZone: 'UTC' };
13-
for (let i = 0; i < 7; i++) {
16+
for (let i = 0; i < DAYS_IN_WEEK; i++) {
1417
try {
1518
weekDays.push(baseDate.toLocaleDateString(locale, formatOptions));
1619
} catch {

webpack/JobWizard/steps/Schedule/ScheduleRecurring.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { PurposeField } from './PurposeField';
1818
import { DateTimePicker } from '../form/DateTimePicker';
1919
import { WizardTitle } from '../form/WizardTitle';
2020

21+
const ONE_MINUTE_MS = 60000;
22+
2123
export const ScheduleRecurring = ({
2224
scheduleValue,
2325
setScheduleValue,
@@ -114,8 +116,8 @@ export const ScheduleRecurring = ({
114116
setScheduleValue(current => ({
115117
...current,
116118
startsAt: new Date(
117-
new Date().getTime() + 60000
118-
).toISOString(), // 1 minute in the future
119+
new Date().getTime() + ONE_MINUTE_MS
120+
).toISOString(),
119121
isFuture: true,
120122
}))
121123
}

webpack/JobWizard/steps/Schedule/ScheduleType.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
import { WizardTitle } from '../form/WizardTitle';
1111
import { QueryType } from './QueryType';
1212

13+
const ONE_MINUTE_MS = 60000;
14+
1315
export const ScheduleType = ({
1416
scheduleType,
1517
isTypeStatic,
@@ -49,7 +51,9 @@ export const ScheduleType = ({
4951
onChange={() => {
5052
setScheduleValue(current => ({
5153
...current,
52-
startsAt: new Date(new Date().getTime() + 60000).toISOString(), // 1 minute in the future
54+
startsAt: new Date(
55+
new Date().getTime() + ONE_MINUTE_MS
56+
).toISOString(),
5357
scheduleType: SCHEDULE_TYPES.FUTURE,
5458
repeatType: repeatTypes.noRepeat,
5559
}));

webpack/JobWizard/steps/form/DateTimePicker.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ import {
88
import { debounce } from 'lodash';
99
import { translate as __, documentLocale } from 'foremanReact/common/I18n';
1010

11+
const PAD_SLICE = -2;
12+
const DEBOUNCE_MS = 1000;
13+
1114
const formatDateTime = d =>
1215
`${d.getFullYear()}-${`0${d.getMonth() + 1}`.slice(
13-
-2
14-
)}-${`0${d.getDate()}`.slice(-2)} ${`0${d.getHours()}`.slice(
15-
-2
16-
)}:${`0${d.getMinutes()}`.slice(-2)}:${`0${d.getSeconds()}`.slice(-2)}`;
16+
PAD_SLICE
17+
)}-${`0${d.getDate()}`.slice(PAD_SLICE)} ${`0${d.getHours()}`.slice(
18+
PAD_SLICE
19+
)}:${`0${d.getMinutes()}`.slice(PAD_SLICE)}:${`0${d.getSeconds()}`.slice(
20+
PAD_SLICE
21+
)}`;
1722

1823
export const DateTimePicker = ({
1924
dateTime,
@@ -103,7 +108,7 @@ export const DateTimePicker = ({
103108
aria-label={`${ariaLabel} datepicker`}
104109
value={formattedDate}
105110
placeholder="yyyy/mm/dd"
106-
onChange={debounce(onDateChange, 1000, {
111+
onChange={debounce(onDateChange, DEBOUNCE_MS, {
107112
leading: false,
108113
trailing: true,
109114
})}
@@ -123,7 +128,7 @@ export const DateTimePicker = ({
123128
time={dateTime ? dateObject.toString() : ''}
124129
inputProps={dateTime ? {} : { value: '' }}
125130
placeholder={includeSeconds ? 'hh:mm:ss' : 'hh:mm'}
126-
onChange={debounce(onTimeChange, 1000, {
131+
onChange={debounce(onTimeChange, DEBOUNCE_MS, {
127132
leading: false,
128133
trailing: true,
129134
})}

0 commit comments

Comments
 (0)