Remove insights_credential from inventory

This commit is contained in:
Bill Nottingham
2021-06-16 16:47:42 -04:00
committed by Shane McDonald
parent 0947d30682
commit 1e68519c99
26 changed files with 38 additions and 267 deletions

View File

@@ -67,7 +67,7 @@ describe('<CredentialDetail />', () => {
test('should have proper number of delete detail requests', () => {
expect(
wrapper.find('DeleteButton').prop('deleteDetailsRequests')
).toHaveLength(6);
).toHaveLength(5);
});
test('should render details', () => {

View File

@@ -43,7 +43,7 @@ describe('<CredentialList />', () => {
test('should have proper number of delete detail requests', () => {
expect(
wrapper.find('ToolbarDeleteButton').prop('deleteDetailsRequests')
).toHaveLength(6);
).toHaveLength(5);
});
test('should fetch credentials from api and render the in the list', () => {

View File

@@ -1,53 +1,26 @@
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import { useHistory } from 'react-router-dom';
import { PageSection, Card } from '@patternfly/react-core';
import { CardBody } from '../../../components/Card';
import ContentLoading from '../../../components/ContentLoading';
import { InventoriesAPI, CredentialTypesAPI } from '../../../api';
import { InventoriesAPI } from '../../../api';
import InventoryForm from '../shared/InventoryForm';
function InventoryAdd() {
const [error, setError] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [credentialTypeId, setCredentialTypeId] = useState(null);
const history = useHistory();
useEffect(() => {
const loadData = async () => {
try {
const {
data: { results: loadedCredentialTypeId },
} = await CredentialTypesAPI.read({ kind: 'insights' });
setCredentialTypeId(loadedCredentialTypeId[0].id);
} catch (err) {
setError(err);
} finally {
setIsLoading(false);
}
};
loadData();
}, [isLoading, credentialTypeId]);
const handleCancel = () => {
history.push('/inventories');
};
const handleSubmit = async values => {
const {
instanceGroups,
organization,
insights_credential,
...remainingValues
} = values;
const { instanceGroups, organization, ...remainingValues } = values;
try {
const {
data: { id: inventoryId },
} = await InventoriesAPI.create({
organization: organization.id,
insights_credential: insights_credential
? insights_credential.id
: null,
...remainingValues,
});
if (instanceGroups) {
@@ -68,9 +41,6 @@ function InventoryAdd() {
}
};
if (isLoading) {
return <ContentLoading />;
}
return (
<PageSection>
<Card>
@@ -78,7 +48,6 @@ function InventoryAdd() {
<InventoryForm
onCancel={handleCancel}
onSubmit={handleSubmit}
credentialTypeId={credentialTypeId}
submitError={error}
/>
</CardBody>

View File

@@ -7,7 +7,7 @@ import {
} from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import { InventoriesAPI, CredentialTypesAPI } from '../../../api';
import { InventoriesAPI } from '../../../api';
import InventoryAdd from './InventoryAdd';
jest.mock('../../../api');
@@ -18,16 +18,6 @@ describe('<InventoryAdd />', () => {
beforeEach(async () => {
history = createMemoryHistory({ initialEntries: ['/inventories'] });
CredentialTypesAPI.read.mockResolvedValue({
data: {
results: [
{
id: 14,
name: 'insights',
},
],
},
});
InventoriesAPI.create.mockResolvedValue({ data: { id: 13 } });
await act(async () => {
wrapper = mountWithContexts(<InventoryAdd />, {
@@ -50,7 +40,6 @@ describe('<InventoryAdd />', () => {
wrapper.find('InventoryForm').prop('onSubmit')({
name: 'new Foo',
organization: { id: 2 },
insights_credential: { id: 47 },
instanceGroups,
});
});
@@ -58,7 +47,6 @@ describe('<InventoryAdd />', () => {
expect(InventoriesAPI.create).toHaveBeenCalledWith({
name: 'new Foo',
organization: 2,
insights_credential: 47,
});
instanceGroups.map(IG =>
expect(InventoriesAPI.associateInstanceGroup).toHaveBeenCalledWith(

View File

@@ -22,10 +22,6 @@ const mockInventory = {
copy: true,
adhoc: true,
},
insights_credential: {
id: 1,
name: 'Foo',
},
},
created: '2019-10-04T16:56:48.025455Z',
modified: '2019-10-04T16:56:48.025468Z',
@@ -43,7 +39,6 @@ const mockInventory = {
has_inventory_sources: false,
total_inventory_sources: 0,
inventory_sources_with_failures: 0,
insights_credential: null,
pending_deletion: false,
};

View File

@@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
import { object } from 'prop-types';
import { CardBody } from '../../../components/Card';
import { InventoriesAPI, CredentialTypesAPI } from '../../../api';
import { InventoriesAPI } from '../../../api';
import ContentLoading from '../../../components/ContentLoading';
import InventoryForm from '../shared/InventoryForm';
import { getAddedAndRemoved } from '../../../util/lists';
@@ -13,31 +13,19 @@ function InventoryEdit({ inventory }) {
const [error, setError] = useState(null);
const [associatedInstanceGroups, setInstanceGroups] = useState(null);
const [contentLoading, setContentLoading] = useState(true);
const [credentialTypeId, setCredentialTypeId] = useState(null);
const history = useHistory();
const isMounted = useIsMounted();
useEffect(() => {
const loadData = async () => {
try {
const [
{
data: { results: loadedInstanceGroups },
},
{
data: { results: loadedCredentialTypeId },
},
] = await Promise.all([
InventoriesAPI.readInstanceGroups(inventory.id),
CredentialTypesAPI.read({
kind: 'insights',
}),
]);
const {
data: { results: loadedInstanceGroups },
} = await InventoriesAPI.readInstanceGroups(inventory.id);
if (!isMounted.current) {
return;
}
setInstanceGroups(loadedInstanceGroups);
setCredentialTypeId(loadedCredentialTypeId[0].id);
} catch (err) {
setError(err);
} finally {
@@ -48,7 +36,7 @@ function InventoryEdit({ inventory }) {
};
loadData();
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [inventory.id, contentLoading, inventory, credentialTypeId]);
}, [inventory.id, contentLoading, inventory]);
const handleCancel = () => {
const url =
@@ -60,17 +48,9 @@ function InventoryEdit({ inventory }) {
};
const handleSubmit = async values => {
const {
instanceGroups,
insights_credential,
organization,
...remainingValues
} = values;
const { instanceGroups, organization, ...remainingValues } = values;
try {
await InventoriesAPI.update(inventory.id, {
insights_credential: insights_credential
? insights_credential.id
: null,
organization: organization.id,
...remainingValues,
});
@@ -109,7 +89,6 @@ function InventoryEdit({ inventory }) {
onSubmit={handleSubmit}
inventory={inventory}
instanceGroups={associatedInstanceGroups}
credentialTypeId={credentialTypeId}
submitError={error}
/>
</CardBody>

View File

@@ -7,7 +7,7 @@ import {
} from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import { InventoriesAPI, CredentialTypesAPI } from '../../../api';
import { InventoriesAPI } from '../../../api';
import InventoryEdit from './InventoryEdit';
jest.mock('../../../api');
@@ -28,10 +28,6 @@ const mockInventory = {
copy: true,
adhoc: true,
},
insights_credential: {
id: 1,
name: 'Foo',
},
},
created: '2019-10-04T16:56:48.025455Z',
modified: '2019-10-04T16:56:48.025468Z',
@@ -49,7 +45,6 @@ const mockInventory = {
has_inventory_sources: false,
total_inventory_sources: 0,
inventory_sources_with_failures: 0,
insights_credential: null,
pending_deletion: false,
};
@@ -65,16 +60,6 @@ describe('<InventoryEdit />', () => {
let history;
beforeEach(async () => {
CredentialTypesAPI.read.mockResolvedValue({
data: {
results: [
{
id: 14,
name: 'insights',
},
],
},
});
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: associatedInstanceGroups,
@@ -117,7 +102,6 @@ describe('<InventoryEdit />', () => {
name: 'Foo',
id: 13,
organization: { id: 1 },
insights_credential: { id: 13 },
instanceGroups,
});
});

View File

@@ -47,7 +47,6 @@ const mockInventories = [
has_inventory_sources: false,
total_inventory_sources: 0,
inventory_sources_with_failures: 0,
insights_credential: null,
pending_deletion: false,
},
{
@@ -83,7 +82,6 @@ const mockInventories = [
has_inventory_sources: false,
total_inventory_sources: 0,
inventory_sources_with_failures: 0,
insights_credential: null,
pending_deletion: false,
},
{
@@ -119,7 +117,6 @@ const mockInventories = [
has_inventory_sources: false,
total_inventory_sources: 0,
inventory_sources_with_failures: 0,
insights_credential: null,
pending_deletion: false,
},
];

View File

@@ -1,7 +1,7 @@
import React, { useCallback } from 'react';
import { Formik, useField, useFormikContext } from 'formik';
import { t } from '@lingui/macro';
import { func, number, shape } from 'prop-types';
import { func, shape } from 'prop-types';
import { Form } from '@patternfly/react-core';
import { VariablesField } from '../../../components/CodeEditor';
import FormField, { FormSubmitError } from '../../../components/FormField';
@@ -9,13 +9,12 @@ import FormActionGroup from '../../../components/FormActionGroup';
import { required } from '../../../util/validators';
import InstanceGroupsLookup from '../../../components/Lookup/InstanceGroupsLookup';
import OrganizationLookup from '../../../components/Lookup/OrganizationLookup';
import CredentialLookup from '../../../components/Lookup/CredentialLookup';
import {
FormColumnLayout,
FormFullWidthLayout,
} from '../../../components/FormLayout';
function InventoryFormFields({ credentialTypeId, inventory }) {
function InventoryFormFields({ inventory }) {
const { setFieldValue, setFieldTouched } = useFormikContext();
const [organizationField, organizationMeta, organizationHelpers] = useField(
'organization'
@@ -23,9 +22,6 @@ function InventoryFormFields({ credentialTypeId, inventory }) {
const [instanceGroupsField, , instanceGroupsHelpers] = useField(
'instanceGroups'
);
const [insightsCredentialField, insightsCredentialMeta] = useField(
'insights_credential'
);
const handleOrganizationUpdate = useCallback(
value => {
setFieldValue('organization', value);
@@ -34,14 +30,6 @@ function InventoryFormFields({ credentialTypeId, inventory }) {
[setFieldValue, setFieldTouched]
);
const handleCredentialUpdate = useCallback(
value => {
setFieldValue('insights_credential', value);
setFieldTouched('insights_credential', true, false);
},
[setFieldValue, setFieldTouched]
);
return (
<>
<FormField
@@ -70,17 +58,6 @@ function InventoryFormFields({ credentialTypeId, inventory }) {
autoPopulate={!inventory?.id}
validate={required(t`Select a value for this field`)}
/>
<CredentialLookup
helperTextInvalid={insightsCredentialMeta.error}
isValid={
!insightsCredentialMeta.touched || !insightsCredentialMeta.error
}
label={t`Insights Credential`}
credentialTypeId={credentialTypeId}
onChange={handleCredentialUpdate}
value={insightsCredentialField.value}
fieldName="insights_credential"
/>
<InstanceGroupsLookup
value={instanceGroupsField.value}
onChange={value => {
@@ -116,10 +93,6 @@ function InventoryForm({
(inventory.summary_fields && inventory.summary_fields.organization) ||
null,
instanceGroups: instanceGroups || [],
insights_credential:
(inventory.summary_fields &&
inventory.summary_fields.insights_credential) ||
null,
};
return (
@@ -150,7 +123,6 @@ InventoryForm.propType = {
handleCancel: func.isRequired,
instanceGroups: shape(),
inventory: shape(),
credentialTypeId: number.isRequired,
submitError: shape(),
};

View File

@@ -25,10 +25,6 @@ const inventory = {
copy: true,
adhoc: true,
},
insights_credential: {
id: 1,
name: 'Foo',
},
},
created: '2019-10-04T16:56:48.025455Z',
modified: '2019-10-04T16:56:48.025468Z',
@@ -46,7 +42,6 @@ const inventory = {
has_inventory_sources: false,
total_inventory_sources: 0,
inventory_sources_with_failures: 0,
insights_credential: null,
pending_deletion: false,
};
@@ -89,9 +84,6 @@ describe('<InventoryForm />', () => {
expect(wrapper.find('FormGroup[label="Description"]').length).toBe(1);
expect(wrapper.find('FormGroup[label="Organization"]').length).toBe(1);
expect(wrapper.find('FormGroup[label="Instance Groups"]').length).toBe(1);
expect(wrapper.find('FormGroup[label="Insights Credential"]').length).toBe(
1
);
expect(wrapper.find('VariablesField[label="Variables"]').length).toBe(1);
expect(wrapper.find('CodeEditor').prop('value')).toEqual('---');
});
@@ -107,12 +99,6 @@ describe('<InventoryForm />', () => {
wrapper.find('input#inventory-name').simulate('change', {
target: { value: 'new Foo', name: 'name' },
});
wrapper.find('CredentialLookup').invoke('onBlur')();
wrapper.find('CredentialLookup').invoke('onChange')({
id: 10,
name: 'credential',
});
});
wrapper.update();
expect(wrapper.find('OrganizationLookup').prop('value')).toEqual({
@@ -122,10 +108,6 @@ describe('<InventoryForm />', () => {
expect(wrapper.find('input#inventory-name').prop('value')).toEqual(
'new Foo'
);
expect(wrapper.find('CredentialLookup').prop('value')).toEqual({
id: 10,
name: 'credential',
});
});
test('should call handleCancel when Cancel button is clicked', async () => {

View File

@@ -91,6 +91,5 @@
"has_inventory_sources": false,
"total_inventory_sources": 0,
"inventory_sources_with_failures": 0,
"insights_credential": null,
"pending_deletion": false
}

View File

@@ -90,6 +90,5 @@
"has_inventory_sources": false,
"total_inventory_sources": 0,
"inventory_sources_with_failures": 0,
"insights_credential": null,
"pending_deletion": false
}

View File

@@ -33,9 +33,6 @@ describe('delete details', () => {
getRelatedResourceDeleteCounts(
relatedResourceDeleteRequests.credential({ id: 1 })
);
expect(InventoriesAPI.read).toBeCalledWith({
insights_credential: 1,
});
expect(InventorySourcesAPI.read).toBeCalledWith({
credentials__id: 1,
});

View File

@@ -58,13 +58,6 @@ export const relatedResourceDeleteRequests = {
request: () => ProjectsAPI.read({ credentials: selected.id }),
label: t`Projects`,
},
{
request: () =>
InventoriesAPI.read({
insights_credential: selected.id,
}),
label: t`Inventories`,
},
{
request: () =>
InventorySourcesAPI.read({