Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions webpack/components/ConfirmModal.js

This file was deleted.

3 changes: 0 additions & 3 deletions webpack/components/ConfirmModal.scss

This file was deleted.

44 changes: 0 additions & 44 deletions webpack/components/IndexLayout.js

This file was deleted.

6 changes: 0 additions & 6 deletions webpack/components/IndexTable/IndexTableHelper.js

This file was deleted.

73 changes: 0 additions & 73 deletions webpack/components/IndexTable/index.js

This file was deleted.

28 changes: 21 additions & 7 deletions webpack/components/LineChart/LineChartHelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/** Backend sends [label, values, color]; legacy Foreman charts used spread columns. */
import { chart_color_black_500 as chartColorBlack500 } from '@patternfly/react-tokens';

const TIMESTAMP_THRESHOLD = 1e12;
const MS_PER_SECOND = 1000;
const DEFAULT_TICK_MID = 0.5;
const MIN_TICK_STEP = 0.1;
const EXPONENTIAL_THRESHOLD = 1e21;
const CLAMP_SCALE_FACTOR = 0.9;
const HOURS_PER_HALF_DAY = 12;
const MINUTES_PER_HOUR = 60;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, do we really really have to declare a constant saying that there are 60 minutes in an hour in every single plugin we have? I mean I get where it's coming from, but it feels a bit silly

@MariaAga MariaAga Jul 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly dont want someone to delete a small constant from core because they think no one uses them, and cause much damage. It seems like a simple way to ensure that. As 1 hour is a fact generally, its not like core decides what is an hour. (unlike status names for example)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamruzicka I had same question, and now I think that it will be safer do redefine it in plugins.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I'm convinced.

While the argument of "what if we delete the constant from core" is appealing from the developer's point of view, it also sounds a lot like "but then we won't be able to freely change what is essentially a public interface".

As 1 hour is a fact generally, its not like core decides what is an hour. (unlike status names for example)

This goes both ways. Neither foreman nor plugins decide what http 401 means, yet this one gets imported, while the others do not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with @adamruzicka.
Just had a look, there are some libraries like https://github.com/date-fns/date-fns/blob/4098115cf705e3af7f663d8e5b0686e39a9f478a/pkgs/core/src/constants/index.ts#L133 - but it would be another npm package we need to maintain...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adamruzicka & @sbernhard , those are good points, I will update my PRs to import from core.
And as you said, we want to avoid more npm packages to maintain, so I'll just keep the data in core.

const SECONDS_PER_MINUTE = 60;

const getColumnValues = col => {
if (Array.isArray(col[1])) return col[1];

Expand Down Expand Up @@ -32,7 +42,7 @@ const getSeriesColor = col => {

const toMs = val => {
const n = Number(val);
return n >= 1e12 ? n : n * 1000;
return n >= TIMESTAMP_THRESHOLD ? n : n * MS_PER_SECOND;
};

/** Process raw backend data into chart series for PatternFly line charts. */
Expand Down Expand Up @@ -101,17 +111,17 @@ export const getYTickValues = (chartData, hiddenSeries = new Set()) => {
});
});

if (maxY <= 0) return [0, 0.5, 1.0];
if (maxY <= 0) return [0, DEFAULT_TICK_MID, 1.0];

const step = Math.max(0.1, Math.ceil((maxY / 4) * 10) / 10);
const step = Math.max(MIN_TICK_STEP, Math.ceil((maxY / 4) * 10) / 10);
return [0, 1, 2, 3, 4, 5].map(i => Math.round(i * step * 10) / 10);
};

/** Rule counts are whole numbers; avoid decimal formatting in tooltips. */
export const formatTooltipValue = value => {
const num = Number(value);
if (!Number.isFinite(num)) return '';
if (Math.abs(num) >= 1e21) {
if (Math.abs(num) >= EXPONENTIAL_THRESHOLD) {
return num.toExponential(1);
}
return String(Math.round(num));
Expand All @@ -128,14 +138,14 @@ export const clampChartPadding = (padding, width, height) => {

const horizontalTotal = left + right;
if (horizontalTotal >= width) {
const scale = (width * 0.9) / horizontalTotal;
const scale = (width * CLAMP_SCALE_FACTOR) / horizontalTotal;
left *= scale;
right *= scale;
}

const verticalTotal = top + bottom;
if (verticalTotal >= height) {
const scale = (height * 0.9) / verticalTotal;
const scale = (height * CLAMP_SCALE_FACTOR) / verticalTotal;
top *= scale;
bottom *= scale;
}
Expand All @@ -154,7 +164,11 @@ export const getTimeseriesXDomain = chartData => {
const max = Math.max(...times);

if (min === max) {
const offset = 12 * 60 * 60 * 1000;
const offset =
HOURS_PER_HALF_DAY *
MINUTES_PER_HOUR *
SECONDS_PER_MINUTE *
MS_PER_SECOND;
return [new Date(min - offset), new Date(max + offset)];
}

Expand Down
42 changes: 0 additions & 42 deletions webpack/components/LinkButton.js

This file was deleted.

3 changes: 3 additions & 0 deletions webpack/components/OpenscapRemediationWizard/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const JOB_INVOCATION_API_REQUEST_KEY = 'OPENSCAP_REX_JOB_INVOCATIONS';
export const SNIPPET_SH = 'urn:xccdf:fix:script:sh';
export const SNIPPET_ANSIBLE = 'urn:xccdf:fix:script:ansible';

export const TOOLTIP_COPIED_EXIT_DELAY_MS = 1500;
export const TOOLTIP_DEFAULT_EXIT_DELAY_MS = 600;

export const WIZARD_TITLES = {
snippetSelect: __('Select snippet'),
reviewHosts: __('Review hosts'),
Expand Down
4 changes: 2 additions & 2 deletions webpack/components/OpenscapRemediationWizard/steps/Finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';

import { translate as __ } from 'foremanReact/common/I18n';
import { foremanUrl } from 'foremanReact/common/helpers';
import { STATUS } from 'foremanReact/constants';
import { STATUS, HTTP_STATUS_CODES } from 'foremanReact/constants';
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
import Loading from 'foremanReact/components/Loading';
import PermissionDenied from 'foremanReact/components/PermissionDenied';
Expand Down Expand Up @@ -91,7 +91,7 @@ const Finish = ({ onClose }) => {
</Button>
);
const errorComponent =
statusCode === 403 ? (
statusCode === HTTP_STATUS_CODES.FORBIDDEN ? (
<PermissionDenied
missingPermissions={data?.error?.missing_permissions}
primaryButton={closeBtn}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
import OpenscapRemediationWizardContext from '../OpenscapRemediationWizardContext';
import WizardHeader from '../WizardHeader';
import ViewSelectedHostsLink from '../ViewSelectedHostsLink';
import { FAIL_RULE_SEARCH } from '../constants';
import {
FAIL_RULE_SEARCH,
TOOLTIP_COPIED_EXIT_DELAY_MS,
TOOLTIP_DEFAULT_EXIT_DELAY_MS,
} from '../constants';
import { findFixBySnippet } from '../helpers';

import './ReviewRemediation.scss';
Expand Down Expand Up @@ -78,7 +82,11 @@ const ReviewRemediation = () => {
textId="code-content"
aria-label="Copy to clipboard"
onClick={e => onCopyClick(e, snippetText)}
exitDelay={copied ? 1500 : 600}
exitDelay={
copied
? TOOLTIP_COPIED_EXIT_DELAY_MS
: TOOLTIP_DEFAULT_EXIT_DELAY_MS
}
maxWidth="110px"
variant="plain"
onTooltipHidden={() => setCopied(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import WizardHeader from '../WizardHeader';
import EmptyState from '../../EmptyState';
import { errorMsg, supportedRemediationSnippets } from '../helpers';

const URN_TAIL_SEGMENTS = -2;

const SnippetSelect = () => {
const {
fixes,
Expand All @@ -44,7 +46,7 @@ const SnippetSelect = () => {
if (mapped) return mapped;

return join(
map(slice(split(system, ':'), -2), n => capitalize(n)),
map(slice(split(system, ':'), URN_TAIL_SEGMENTS), n => capitalize(n)),
' '
);
};
Expand Down
Loading
Loading