Merge pull request #7577 from AlexSCorey/RemovesInventoryScripts

Removes Inventory Script screens, routes, stubs etc.

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-08-03 18:37:25 +00:00 committed by GitHub
commit b11908ed1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 0 additions and 363 deletions

View File

@ -1,137 +0,0 @@
import React, { useCallback, useEffect } from 'react';
import { withRouter } from 'react-router-dom';
import { func, bool, number, node, string, oneOfType } from 'prop-types';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
import { FormGroup } from '@patternfly/react-core';
import Lookup from './Lookup';
import LookupErrorMessage from './shared/LookupErrorMessage';
import OptionsList from '../OptionsList';
import { InventoriesAPI, InventoryScriptsAPI } from '../../api';
import { InventoryScript } from '../../types';
import useRequest from '../../util/useRequest';
import { getQSConfig, parseQueryString, mergeParams } from '../../util/qs';
const QS_CONFIG = getQSConfig('inventory_scripts', {
order_by: 'name',
page: 1,
page_size: 5,
role_level: 'admin_role',
});
function InventoryScriptLookup({
helperTextInvalid,
history,
i18n,
inventoryId,
isValid,
onBlur,
onChange,
required,
value,
}) {
const {
result: { count, inventoryScripts },
error,
request: fetchInventoryScripts,
} = useRequest(
useCallback(async () => {
const parsedParams = parseQueryString(QS_CONFIG, history.location.search);
const {
data: { organization },
} = await InventoriesAPI.readDetail(inventoryId);
const { data } = await InventoryScriptsAPI.read(
mergeParams(parsedParams, { organization })
);
return {
count: data.count,
inventoryScripts: data.results,
};
}, [history.location.search, inventoryId]),
{
count: 0,
inventoryScripts: [],
}
);
useEffect(() => {
fetchInventoryScripts();
}, [fetchInventoryScripts]);
return (
<FormGroup
fieldId="inventory-script"
helperTextInvalid={helperTextInvalid}
isRequired={required}
validated={isValid ? 'default' : 'error'}
label={i18n._(t`Inventory script`)}
>
<Lookup
id="inventory-script-lookup"
header={i18n._(t`Inventory script`)}
value={value}
onChange={onChange}
onBlur={onBlur}
required={required}
qsConfig={QS_CONFIG}
renderOptionsList={({ state, dispatch, canDelete }) => (
<OptionsList
header={i18n._(t`Inventory script`)}
multiple={state.multiple}
name="inventory-script"
optionCount={count}
options={inventoryScripts}
qsConfig={QS_CONFIG}
readOnly={!canDelete}
deselectItem={item => dispatch({ type: 'DESELECT_ITEM', item })}
selectItem={item => dispatch({ type: 'SELECT_ITEM', item })}
value={state.selectedItems}
searchColumns={[
{
name: i18n._(t`Name`),
key: 'name',
isDefault: true,
},
{
name: i18n._(t`Created By (Username)`),
key: 'created_by__username',
},
{
name: i18n._(t`Modified By (Username)`),
key: 'modified_by__username',
},
]}
sortColumns={[
{
name: i18n._(t`Name`),
key: 'name',
},
]}
/>
)}
/>
<LookupErrorMessage error={error} />
</FormGroup>
);
}
InventoryScriptLookup.propTypes = {
helperTextInvalid: node,
inventoryId: oneOfType([number, string]).isRequired,
isValid: bool,
onBlur: func,
onChange: func.isRequired,
required: bool,
value: InventoryScript,
};
InventoryScriptLookup.defaultProps = {
helperTextInvalid: '',
isValid: true,
onBlur: () => {},
required: false,
value: null,
};
export default withI18n()(withRouter(InventoryScriptLookup));

View File

@ -98,10 +98,6 @@ function PromptInventorySourceDetail({ i18n, resource }) {
/>
)}
<Detail label={i18n._(t`Inventory File`)} value={source_path} />
<Detail
label={i18n._(t`Custom Inventory Script`)}
value={summary_fields?.source_script?.name}
/>
<Detail label={i18n._(t`Verbosity`)} value={VERBOSITY[verbosity]} />
<Detail
label={i18n._(t`Cache Timeout`)}

View File

@ -30,7 +30,6 @@ describe('PromptInventorySourceDetail', () => {
assertDetail(wrapper, 'Source', 'scm');
assertDetail(wrapper, 'Project', 'Mock Project');
assertDetail(wrapper, 'Inventory File', 'foo');
assertDetail(wrapper, 'Custom Inventory Script', 'Mock Script');
assertDetail(wrapper, 'Verbosity', '2 (More Verbose)');
assertDetail(wrapper, 'Cache Timeout', '2 Seconds');
expect(

View File

@ -7,7 +7,6 @@ import Dashboard from './screens/Dashboard';
import Hosts from './screens/Host';
import InstanceGroups from './screens/InstanceGroup';
import Inventory from './screens/Inventory';
import InventoryScripts from './screens/InventoryScript';
import { Jobs } from './screens/Job';
import ManagementJobs from './screens/ManagementJob';
import NotificationTemplates from './screens/NotificationTemplate';
@ -79,11 +78,6 @@ function getRouteConfig(i18n) {
path: '/hosts',
screen: Hosts,
},
{
title: i18n._(t`Inventory Scripts`),
path: '/inventory_scripts',
screen: InventoryScripts,
},
],
},
{

View File

@ -52,7 +52,6 @@ describe('<InventorySourceAdd />', () => {
['openstack', 'OpenStack'],
['rhv', 'Red Hat Virtualization'],
['tower', 'Ansible Tower'],
['custom', 'Custom Script'],
],
},
},

View File

@ -50,7 +50,6 @@ function InventorySourceDetail({ inventorySource, i18n }) {
modified_by,
organization,
source_project,
source_script,
user_capabilities,
},
} = inventorySource;
@ -220,10 +219,6 @@ function InventorySourceDetail({ inventorySource, i18n }) {
label={i18n._(t`Inventory file`)}
value={source_path === '' ? i18n._(t`/ (project root)`) : source_path}
/>
<Detail
label={i18n._(t`Custom inventory script`)}
value={source_script?.name}
/>
<Detail label={i18n._(t`Verbosity`)} value={VERBOSITY[verbosity]} />
<Detail
label={i18n._(t`Cache timeout`)}

View File

@ -27,7 +27,6 @@ InventorySourcesAPI.readOptions.mockResolvedValue({
['openstack', 'OpenStack'],
['rhv', 'Red Hat Virtualization'],
['tower', 'Ansible Tower'],
['custom', 'Custom Script'],
],
},
},
@ -63,7 +62,6 @@ describe('InventorySourceDetail', () => {
assertDetail(wrapper, 'Ansible environment', '/venv/custom');
assertDetail(wrapper, 'Project', 'Mock Project');
assertDetail(wrapper, 'Inventory file', 'foo');
assertDetail(wrapper, 'Custom inventory script', 'Mock Script');
assertDetail(wrapper, 'Verbosity', '2 (Debug)');
assertDetail(wrapper, 'Cache timeout', '2 seconds');
expect(

View File

@ -54,7 +54,6 @@ describe('<InventorySourceAdd />', () => {
['openstack', 'OpenStack'],
['rhv', 'Red Hat Virtualization'],
['tower', 'Ansible Tower'],
['custom', 'Custom Script'],
],
},
},

View File

@ -25,7 +25,6 @@ import {
import {
AzureSubForm,
CloudFormsSubForm,
CustomScriptSubForm,
EC2SubForm,
GCESubForm,
OpenStackSubForm,
@ -173,7 +172,6 @@ const InventorySourceFormFields = ({ sourceOptions, i18n }) => {
{
azure_rm: <AzureSubForm sourceOptions={sourceOptions} />,
cloudforms: <CloudFormsSubForm />,
custom: <CustomScriptSubForm />,
ec2: <EC2SubForm sourceOptions={sourceOptions} />,
gce: <GCESubForm sourceOptions={sourceOptions} />,
openstack: <OpenStackSubForm />,

View File

@ -36,7 +36,6 @@ describe('<InventorySourceForm />', () => {
['openstack', 'OpenStack'],
['rhv', 'Red Hat Virtualization'],
['tower', 'Ansible Tower'],
['custom', 'Custom Script'],
],
},
},

View File

@ -1,43 +0,0 @@
import React from 'react';
import { useField } from 'formik';
import { useParams } from 'react-router-dom';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
import CredentialLookup from '../../../../components/Lookup/CredentialLookup';
import InventoryScriptLookup from '../../../../components/Lookup/InventoryScriptLookup';
import { OptionsField, SourceVarsField, VerbosityField } from './SharedFields';
const CustomScriptSubForm = ({ i18n }) => {
const { id } = useParams();
const [credentialField, , credentialHelpers] = useField('credential');
const [scriptField, scriptMeta, scriptHelpers] = useField('source_script');
return (
<>
<CredentialLookup
credentialTypeNamespace="cloud"
label={i18n._(t`Credential`)}
value={credentialField.value}
onChange={value => {
credentialHelpers.setValue(value);
}}
/>
<InventoryScriptLookup
helperTextInvalid={scriptMeta.error}
isValid={!scriptMeta.touched || !scriptMeta.error}
onBlur={() => scriptHelpers.setTouched()}
onChange={value => {
scriptHelpers.setValue(value);
}}
inventoryId={id}
value={scriptField.value}
required
/>
<VerbosityField />
<OptionsField />
<SourceVarsField />
</>
);
};
export default withI18n()(CustomScriptSubForm);

View File

@ -1,100 +0,0 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { Formik } from 'formik';
import { mountWithContexts } from '../../../../../testUtils/enzymeHelpers';
import CustomScriptSubForm from './CustomScriptSubForm';
import {
CredentialsAPI,
InventoriesAPI,
InventoryScriptsAPI,
} from '../../../../api';
jest.mock('../../../../api/models/Credentials');
jest.mock('../../../../api/models/Inventories');
jest.mock('../../../../api/models/InventoryScripts');
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({
id: 789,
}),
}));
const initialValues = {
credential: null,
custom_virtualenv: '',
group_by: '',
instance_filters: '',
overwrite: false,
overwrite_vars: false,
source_path: '',
source_project: null,
source_regions: '',
source_script: null,
source_vars: '---\n',
update_cache_timeout: 0,
update_on_launch: true,
update_on_project_update: false,
verbosity: 1,
};
describe('<CustomScriptSubForm />', () => {
let wrapper;
CredentialsAPI.read.mockResolvedValue({
data: { count: 0, results: [] },
});
InventoriesAPI.readDetail.mockResolvedValue({
data: { organization: 123 },
});
InventoryScriptsAPI.read.mockResolvedValue({
data: { count: 0, results: [] },
});
beforeAll(async () => {
await act(async () => {
wrapper = mountWithContexts(
<Formik initialValues={initialValues}>
<CustomScriptSubForm />
</Formik>
);
});
});
afterAll(() => {
jest.clearAllMocks();
wrapper.unmount();
});
test('should render subform fields', () => {
expect(wrapper.find('FormGroup[label="Credential"]')).toHaveLength(1);
expect(wrapper.find('FormGroup[label="Inventory script"]')).toHaveLength(1);
expect(wrapper.find('FormGroup[label="Verbosity"]')).toHaveLength(1);
expect(wrapper.find('FormGroup[label="Update options"]')).toHaveLength(1);
expect(
wrapper.find('FormGroup[label="Cache timeout (seconds)"]')
).toHaveLength(1);
expect(
wrapper.find('VariablesField[label="Source variables"]')
).toHaveLength(1);
});
test('should make expected api calls', () => {
expect(CredentialsAPI.read).toHaveBeenCalledTimes(1);
expect(CredentialsAPI.read).toHaveBeenCalledWith({
credential_type__namespace: 'cloud',
order_by: 'name',
page: 1,
page_size: 5,
});
expect(InventoriesAPI.readDetail).toHaveBeenCalledTimes(1);
expect(InventoriesAPI.readDetail).toHaveBeenCalledWith(789);
expect(InventoryScriptsAPI.read).toHaveBeenCalledTimes(1);
expect(InventoryScriptsAPI.read).toHaveBeenCalledWith({
organization: 123,
role_level: 'admin_role',
order_by: 'name',
page: 1,
page_size: 5,
});
});
});

View File

@ -1,6 +1,5 @@
export { default as AzureSubForm } from './AzureSubForm';
export { default as CloudFormsSubForm } from './CloudFormsSubForm';
export { default as CustomScriptSubForm } from './CustomScriptSubForm';
export { default as EC2SubForm } from './EC2SubForm';
export { default as GCESubForm } from './GCESubForm';
export { default as OpenStackSubForm } from './OpenStackSubForm';

View File

@ -1,28 +0,0 @@
import React, { Component, Fragment } from 'react';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
import {
PageSection,
PageSectionVariants,
Title,
} from '@patternfly/react-core';
class InventoryScripts extends Component {
render() {
const { i18n } = this.props;
const { light } = PageSectionVariants;
return (
<Fragment>
<PageSection variant={light} className="pf-m-condensed">
<Title size="2xl" headingLevel="h2">
{i18n._(t`Inventory Scripts`)}
</Title>
</PageSection>
<PageSection />
</Fragment>
);
}
}
export default withI18n()(InventoryScripts);

View File

@ -1,29 +0,0 @@
import React from 'react';
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
import InventoryScripts from './InventoryScripts';
describe('<InventoryScripts />', () => {
let pageWrapper;
let pageSections;
let title;
beforeEach(() => {
pageWrapper = mountWithContexts(<InventoryScripts />);
pageSections = pageWrapper.find('PageSection');
title = pageWrapper.find('Title');
});
afterEach(() => {
pageWrapper.unmount();
});
test('initially renders without crashing', () => {
expect(pageWrapper.length).toBe(1);
expect(pageSections.length).toBe(2);
expect(title.length).toBe(1);
expect(title.props().size).toBe('2xl');
expect(pageSections.first().props().variant).toBe('light');
});
});

View File

@ -1 +0,0 @@
export { default } from './InventoryScripts';

View File

@ -85,7 +85,6 @@ function InventorySourcesList({ i18n, nodeResource, onUpdateNodeResource }) {
[`openstack`, i18n._(t`OpenStack`)],
[`rhv`, i18n._(t`Red Hat Virtualization`)],
[`tower`, i18n._(t`Ansible Tower`)],
[`custom`, i18n._(t`Custom script`)],
],
},
]}