Skip to content
Merged
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
22 changes: 22 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const tfmConfig = require('@theforeman/test/src/pluginConfig');
const { foremanRelativePath, foremanLocation } = require('@theforeman/find-foreman');

const foremanReactRelative = 'webpack/assets/javascripts/react_app';
const foremanFull = foremanLocation();
const foremanReactFull = foremanRelativePath(foremanReactRelative);

tfmConfig.moduleNameMapper['^foremanReact(.*)$'] = `${foremanReactFull}/$1`;

tfmConfig.resolver = null;
tfmConfig.moduleDirectories = [
`${foremanFull}/node_modules`,
`${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`,
'node_modules',
];

tfmConfig.setupFilesAfterEnv = [
...(tfmConfig.setupFilesAfterEnv || []),
'@testing-library/jest-dom',
];

module.exports = tfmConfig;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"scripts": {
"lint": "tfm-lint --plugin -d /webpack",
"lint:custom": "eslint ./webpack",
"test": "tfm-test --plugin",
"test:watch": "tfm-test --plugin --watchAll",
"test:current": "tfm-test --plugin --watch",
"test": "tfm-test --plugin --config jest.config.js",
"test:watch": "tfm-test --plugin --config jest.config.js --watchAll",
"test:current": "tfm-test --plugin --config jest.config.js --watch",
"publish-coverage": "tfm-publish-coverage"
},
"repository": {
Expand Down
14 changes: 4 additions & 10 deletions webpack/JobInvocationDetail/CheckboxesActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@patternfly/react-icons';
import axios from 'axios';
import { foremanUrl } from 'foremanReact/common/helpers';
import { usePermissions } from 'foremanReact/common/hooks/Permissions/permissionHooks';
import { translate as __, sprintf } from 'foremanReact/common/I18n';
import { addToast } from 'foremanReact/components/ToastsList';
import PropTypes from 'prop-types';
Expand All @@ -24,10 +25,7 @@ import {
DIRECT_OPEN_HOST_LIMIT,
templateInvocationPageUrl,
} from './JobInvocationConstants';
import {
selectHasPermission,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this is no longer used, it can be removed from JobInvocationSelectors

selectTaskCancelable,
} from './JobInvocationSelectors';
import { selectTaskCancelable } from './JobInvocationSelectors';
import OpenAllInvocationsModal from './OpenAllInvocationsModal';

/* eslint-disable camelcase */
Expand Down Expand Up @@ -115,12 +113,8 @@ export const CheckboxesActions = ({
const dispatch = useDispatch();
const [toBeOpened, setToBeOpened] = useState([]);

const hasCreatePermission = useSelector(
selectHasPermission('create_job_invocations')
);
const hasCancelPermission = useSelector(
selectHasPermission('cancel_job_invocations')
);
const hasCreatePermission = usePermissions(['create_job_invocations']);
const hasCancelPermission = usePermissions(['cancel_job_invocations']);
const jobSearchQuery = `job_invocation.id = ${jobID}`;
const filterQuery =
filter && filter !== 'all_statuses'
Expand Down
8 changes: 4 additions & 4 deletions webpack/JobInvocationDetail/JobInvocationConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useForemanHostDetailsPageUrl } from 'foremanReact/Root/Context/ForemanC
import JobStatusIcon from '../react_app/components/RecentJobsCard/JobStatusIcon';

export const JOB_INVOCATION_KEY = 'JOB_INVOCATION_KEY';
export const CURRENT_PERMISSIONS = 'CURRENT_PERMISSIONS';
export const UPDATE_JOB = 'UPDATE_JOB';
export const CANCEL_JOB = 'CANCEL_JOB';
export const GET_TASK = 'GET_TASK';
Expand All @@ -20,9 +19,6 @@ export const GET_TEMPLATE_INVOCATION = 'GET_TEMPLATE_INVOCATION';
export const DIRECT_OPEN_HOST_LIMIT = 3;
export const ALL_JOB_HOSTS = 'ALL_JOB_HOSTS';
export const AWAITING_STATUS_FILTER = '(job_invocation.result = N/A)';
export const currentPermissionsUrl = foremanUrl(
'/api/v2/permissions/current_permissions'
);

export const showTemplateInvocationUrl = (hostID, jobID) =>
`/show_template_invocation_by_host/${hostID}/job_invocation/${jobID}`;
Expand All @@ -32,6 +28,10 @@ export const templateInvocationPageUrl = (hostID, jobID) =>
`/job_invocations_detail/${jobID}/host_invocation/${hostID}`;

export const jobInvocationDetailsUrl = id => `/job_invocations/${id}`;
export const jobInvocationsIndexPath = '/job_invocations';
export const jobInvocationsNewPath = '/job_invocations/new';
export const jobInvocationsIndexUrl = foremanUrl(jobInvocationsIndexPath);
export const jobInvocationsNewUrl = foremanUrl(jobInvocationsNewPath);

export const STATUS = {
PENDING: 'pending',
Expand Down
52 changes: 52 additions & 0 deletions webpack/JobInvocationDetail/JobInvocationEmptyState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import PropTypes from 'prop-types';
import React from 'react';
import { PageSection, PageSectionVariants } from '@patternfly/react-core';
import { translate as __ } from 'foremanReact/common/I18n';
import ResourceLoadFailedEmptyState from 'foremanReact/components/common/EmptyState/ResourceLoadFailedEmptyState';
import {
jobInvocationsIndexUrl,
jobInvocationsNewUrl,
} from './JobInvocationConstants';

const JobInvocationEmptyState = ({
jobInvocationId,
httpStatus,
errorMessage,
}) => (
<PageSection variant={PageSectionVariants.light}>
<ResourceLoadFailedEmptyState
resourceLabel={__('job invocation')}
resourceId={jobInvocationId}
httpStatus={httpStatus}
errorMessage={errorMessage}
viewPermissions={['view_job_invocations']}
requiredPermissions={['view_job_invocations']}
primaryAction={{
label: __('Go to job invocations'),
url: jobInvocationsIndexUrl,
ouiaId: 'job-invocation-empty-state-go-to-job-invocations-button',
}}
secondaryActions={[
{
label: __('Create a new job invocation'),
url: jobInvocationsNewUrl,
ouiaId: 'job-invocation-empty-state-create-new-job-invocation-button',
},
]}
ouiaIdPrefix="job-invocation-empty-state"
/>
</PageSection>
);

JobInvocationEmptyState.propTypes = {
jobInvocationId: PropTypes.string.isRequired,
httpStatus: PropTypes.number,
errorMessage: PropTypes.string,
};

JobInvocationEmptyState.defaultProps = {
httpStatus: null,
errorMessage: null,
};

export default JobInvocationEmptyState;
15 changes: 0 additions & 15 deletions webpack/JobInvocationDetail/JobInvocationSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import {
selectAPIResponse,
selectAPIStatus,
} from 'foremanReact/redux/API/APISelectors';
import { STATUS as APIStatus } from 'foremanReact/constants';
import {
JOB_INVOCATION_KEY,
GET_TASK,
GET_TEMPLATE_INVOCATION,
LIST_TEMPLATE_INVOCATIONS,
CURRENT_PERMISSIONS,
} from './JobInvocationConstants';

export const selectItems = state =>
Expand All @@ -29,16 +27,3 @@ export const selectTemplateInvocationStatus = hostID => state =>
export const selectTemplateInvocationList = state =>
selectAPIResponse(state, LIST_TEMPLATE_INVOCATIONS)
?.template_invocations_task_by_hosts;

export const selectCurrentPermisions = state =>
selectAPIResponse(state, CURRENT_PERMISSIONS);

export const selectHasPermission = permissionRequired => state => {
const status = selectAPIStatus(state, CURRENT_PERMISSIONS);
const selectCurrentPermissions = selectCurrentPermisions(state)?.results;
return status === APIStatus.RESOLVED
? selectCurrentPermissions?.some(
permission => permission.name === permissionRequired
)
: false;
};
Loading
Loading