Skip to content

Commit

Permalink
feat(HMS-2255): deploy to image RG by default
Browse files Browse the repository at this point in the history
Use image RG by default, we disable selection of resource group entirely 
for now.

This also removes the disabled region selection, as we default to the 
Resource Group location(region) and that's the best practice in Azure, 
so we don't want to promote overriding it.
  • Loading branch information
ezr-ondrej committed Oct 24, 2023
1 parent 83043c1 commit 7dacabf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 42 deletions.
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

0 comments on commit 7dacabf

Please sign in to comment.