Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(HMS-2255): deploy to image RG by default #353

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 8 additions & 2 deletions src/Components/AzureResourceGroup/AzureResourceGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { azureSourceUploadInfo } from '../../mocks/fixtures/sources.fixtures';
import AzureResourceGroup from '.';

describe('AzureResourceGroup', () => {
test('disables and prepopulates resource group select with the default value', async () => {
const rgSelect = await mountSelectAndOpen('Image RG');
expect(rgSelect).toBeDisabled();
expect(rgSelect).toHaveValue('Image RG');
});

test('populate resource group select', async () => {
await mountSelectAndOpen();
const items = await screen.findAllByLabelText(/^Resource group/);
Expand All @@ -29,8 +35,8 @@ describe('AzureResourceGroup', () => {
});
});

const mountSelectAndOpen = async () => {
render(<AzureResourceGroup />, {
const mountSelectAndOpen = async (imageResourceGroup = null) => {
render(<AzureResourceGroup imageResourceGroup={imageResourceGroup} />, {
contextValues: { chosenSource: '66' },
});
const selectDropdown = await screen.findByLabelText('Select resource group');
Expand Down
20 changes: 15 additions & 5 deletions src/Components/AzureResourceGroup/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React from 'react';

import { Spinner, Select, SelectOption, TextInput } from '@patternfly/react-core';
Expand All @@ -6,18 +7,18 @@ import { AZURE_RG_KEY } from '../../API/queryKeys';
import { fetchResourceGroups } from '../../API';
import { useWizardContext } from '../Common/WizardContext';

const AzureResourceGroup = () => {
const AzureResourceGroup = ({ imageResourceGroup }) => {
const [isOpen, setIsOpen] = React.useState(false);
const [{ chosenSource, azureResourceGroup }, setWizardContext] = useWizardContext();
const [selection, setSelection] = React.useState(azureResourceGroup);
const [selection, setSelection] = React.useState(azureResourceGroup || imageResourceGroup);

const {
isInitialLoading: isLoading,
error,
data: resourceGroups,
} = useQuery([AZURE_RG_KEY, chosenSource], () => fetchResourceGroups(chosenSource), {
staleTime: 30 * 1000, // data is considered fresh for 30 seconds
enabled: !!chosenSource,
enabled: !!chosenSource && !imageResourceGroup,
});

if (!chosenSource || chosenSource === '') {
Expand Down Expand Up @@ -84,15 +85,24 @@ const AzureResourceGroup = () => {
isOpen={isOpen}
onClear={clearSelection}
selections={selection}
placeholderText="redhat-deployed (default)"
isDisabled={!!imageResourceGroup}
placeholderText="(default) image resource group"
typeAheadAriaLabel="Select resource group"
maxHeight="220px"
>
{resourceGroups.map((name, idx) => (
{(resourceGroups || [selection]).map((name, idx) => (
<SelectOption aria-label={`Resource group ${name}`} key={idx} value={name} />
))}
</Select>
);
};

AzureResourceGroup.propTypes = {
imageResourceGroup: PropTypes.string,
};

AzureResourceGroup.defaultProps = {
imageResourceGroup: null,
};

export default AzureResourceGroup;
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import React from 'react';
import { Form, FormGroup, Popover, Title, Button, Text } from '@patternfly/react-core';
import { HelpIcon } from '@patternfly/react-icons';

import { AZURE_PROVIDER } from '../../../../constants';
import { imageProps } from '../../helpers';
import SourcesSelect from '../../../SourcesSelect';
import InstanceCounter from '../../../InstanceCounter';
import InstanceTypesSelect from '../../../InstanceTypesSelect';
import RegionsSelect from '../../../RegionsSelect';
import AzureResourceGroup from '../../../AzureResourceGroup';
import { useWizardContext } from '../../../Common/WizardContext';

const AccountCustomizationsAzure = ({ setStepValidated, image }) => {
const [wizardContext, setWizardContext] = useWizardContext();
const [wizardContext] = useWizardContext();
const [validations, setValidation] = React.useState({
sources: wizardContext.chosenSource ? 'success' : 'default',
types: wizardContext.chosenInstanceType ? 'success' : 'default',
Expand All @@ -26,14 +24,6 @@ const AccountCustomizationsAzure = ({ setStepValidated, image }) => {
setStepValidated(!errorExists);
}, [validations]);

const onRegionChange = ({ region, imageID }) => {
setWizardContext((prevState) => ({
...prevState,
chosenRegion: region,
chosenImageID: imageID,
}));
};

return (
<Form>
<Title ouiaId="account_custom_title" headingLevel="h1" size="xl">
Expand All @@ -56,35 +46,18 @@ const AccountCustomizationsAzure = ({ setStepValidated, image }) => {
}
/>
</FormGroup>
<FormGroup
label="Select location"
isRequired
fieldId="azure-select-location"
labelIcon={
<Popover headerContent={<div>Azure locations</div>}>
<Button
ouiaId="location_help"
type="button"
aria-label="More info for location field"
onClick={(e) => e.preventDefault()}
aria-describedby="azure-select-location"
className="pf-c-form__group-label-help"
variant="plain"
>
<HelpIcon noVerticalAlign />
</Button>
</Popover>
}
>
<RegionsSelect provider={AZURE_PROVIDER} currentRegion={wizardContext.chosenRegion} onChange={onRegionChange} composeID={image.id} />
</FormGroup>
<FormGroup
label="Azure resource group"
fieldId="azure-resource-group-select"
labelIcon={
<Popover
headerContent={<div>Azure resource group</div>}
bodyContent={<div>Azure resource group to deploy the VM resources into. If left blank, defaults to &lsquo;redhat-deployed&rsquo;.</div>}
bodyContent={
<div>
<p>Azure resource group to deploy the VM resources into. Defaults to the resource group image is located in.</p>
<p>The location (Azure region) of the resource group is used for all resources deployed.</p>
</div>
}
>
<Button
ouiaId="resource_group_help"
Expand All @@ -100,7 +73,7 @@ const AccountCustomizationsAzure = ({ setStepValidated, image }) => {
</Popover>
}
>
<AzureResourceGroup />
<AzureResourceGroup imageResourceGroup={image.uploadOptions?.resource_group} />
</FormGroup>
<FormGroup
label="Select instance size"
Expand Down
Loading