Skip to content

Commit 31d647c

Browse files
mcanoyjacobsee
andauthored
Feature Availability Zone (#614)
* WIP: Add selector and info display for availability zones * further attempts at getting the availability zone to post * Push for Spencer * default the availability zone in the hosting environment card itself * Remove commented out code that didn't work * Update hosting env snapshot * add support to pull version manifest without token. remove ability to fetch and engagement by customer / project in path. * feature map availability zone * remove console.log Co-authored-by: Jacob See <[email protected]>
1 parent c310e9a commit 31d647c

File tree

22 files changed

+125
-74
lines changed

22 files changed

+125
-74
lines changed

src/app.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, useEffect } from 'react';
22
import '@patternfly/react-core/dist/styles/base.css';
33
import { BrowserRouter as Router, useLocation } from 'react-router-dom';
44
import qs from 'query-string';
@@ -107,6 +107,12 @@ export const App = ({ config }: { config: Config }) => {
107107
const FeatureProvider = ({ children }) => {
108108
const location = useLocation();
109109
const versionContext = useContext(VersionContext);
110+
useEffect(() => {
111+
if (!versionContext.versions) {
112+
versionContext?.fetchVersions();
113+
}
114+
}, [versionContext]);
115+
110116
const { appConfig } = useConfig();
111117
let version = versionContext.versions?.mainVersion?.value;
112118
if (appConfig?.allowVersionOverride) {

src/common/app_features.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export const APP_FEATURES = {
88
engagementCardIcons: 'engagementCardIcons',
99
dashboardDateSelector: 'dashboard-date-selector',
1010
engagementWriter: 'engagementWriter',
11-
copyFrom: 'copyFrom'
11+
copyFrom: 'copyFrom',
12+
availabilityZone: 'availabilityZone',
1213
};
1314

1415
export type AppFeature = keyof typeof APP_FEATURES;

src/common/human_readable_engagement_field.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function getHumanReadableFieldName(field: string): string {
1313
location: `Location`,
1414
ocp_cloud_provider_name: 'Cloud Provider Name',
1515
ocp_cloud_provider_region: 'Cloud Provider Region',
16+
ocp_cloud_provider_availability_zone: 'Cloud Provider Availability Zone',
1617
ocp_cluster_size: 'Cluster Size',
1718
ocp_persistent_storage_size: `Persistent Storage Size`,
1819
ocp_sub_domain: 'Subdomain',

src/common/version_feature_factory.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export type FeatureVersionMap = {
55
[key in AppFeature]?: string;
66
};
77

8-
export const FEATURE_VERSION_MAP: FeatureVersionMap = {};
8+
export const FEATURE_VERSION_MAP: FeatureVersionMap = {
9+
availabilityZone: 'v1.3.40',
10+
};
911

1012
const getSemverFromVersionString = (version: string = ''): string => {
1113
return semver.clean(version);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { InfoCircleIcon } from '@patternfly/react-icons';
3+
import { Tooltip, TooltipPosition } from '@patternfly/react-core';
4+
import { EngagementFormConfig } from '../../../schemas/engagement_config';
5+
import { useEngagement } from '../../../context/engagement_context/engagement_hook';
6+
7+
export function AvailabilityZoneTooltip() {
8+
const { engagementFormConfig } = useEngagement();
9+
10+
function createTooltipText(engagementFormConfig: EngagementFormConfig) {
11+
let text = [<div key={'tooltipText'} />];
12+
(engagementFormConfig?.cloud_options?.availability_zones?.options ?? []).map(
13+
(option: any, index: number) => {
14+
return text.push(<div key={index}>{descriptionText(option)}</div>);
15+
}
16+
);
17+
return text;
18+
}
19+
20+
function descriptionText(option?: any) {
21+
return (
22+
<>
23+
<b style={{ color: '#73BCF7' }}> {option.label} </b>
24+
<br /> {option.description}
25+
<br />
26+
</>
27+
);
28+
}
29+
30+
return (
31+
<>
32+
<Tooltip
33+
content={createTooltipText(engagementFormConfig)}
34+
entryDelay={0}
35+
exitDelay={10}
36+
maxWidth={'45rem'}
37+
isContentLeftAligned={true}
38+
position={TooltipPosition.top}
39+
>
40+
<InfoCircleIcon style={{ fontSize: 'small', marginLeft: '1rem' }} />
41+
</Tooltip>
42+
</>
43+
);
44+
}

src/components/engagement_data_cards/hosting_environment_card/hosting_environment_card.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ export function HostingEnvironmentCard() {
8181
const onSave = () => {
8282
saveEngagement({
8383
...(currentChanges as Engagement),
84-
hosting_environments: hostingEnvironments,
84+
hosting_environments: hostingEnvironments.map(he => ({
85+
...he,
86+
ocp_cloud_provider_availability_zone:
87+
he.ocp_cloud_provider_availability_zone ??
88+
engagementFormConfig?.cloud_options?.availability_zones?.options?.find(
89+
element => element.default
90+
).value,
91+
})),
8592
});
8693
};
8794

src/components/engagement_edit_modals/__tests__/__snapshots__/hosting_environment_edit_modal.spec.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Object {
148148
>
149149
<select
150150
aria-invalid="false"
151+
aria-label="Hosting Type"
151152
class="pf-c-form-control"
152153
data-ouia-component-id="OUIA-Generated-FormSelect-default-1"
153154
data-ouia-component-type="PF4/FormSelect"
@@ -288,6 +289,7 @@ Object {
288289
289290
</div>
290291
</div>
292+
291293
<div
292294
class="pf-c-form__group"
293295
>

src/components/engagement_edit_modals/hosting_environment_edit_modal.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { useFeatures } from '../../context/feature_context/feature_hook';
1616
import { APP_FEATURES } from '../../common/app_features';
1717
import { useSubdomainUniqueness } from '../../hooks/subdomain_checker';
1818
import { hasRequiredFields } from '../../common/validate_hosting_environment';
19+
import { AvailabilityZoneTooltip } from '../engagement_data_cards/hosting_environment_card/availability_zone_tooltip';
20+
1921
export interface OpenShiftClusterEditModalProps {
2022
hostingEnvironment: Partial<HostingEnvironment>;
2123
isOpen: boolean;
@@ -59,7 +61,14 @@ export function OpenShiftClusterEditModal({
5961
hostingEnvironment
6062
);
6163

62-
const onSave = () => {
64+
const onSave = async () => {
65+
if (hostingEnvironment.ocp_cloud_provider_availability_zone === undefined) {
66+
await setHostingEnvironment({
67+
...hostingEnvironment,
68+
ocp_cloud_provider_availability_zone: engagementFormConfig?.cloud_options?.availability_zones?.options?.find(element => element.default).value,
69+
} as HostingEnvironment);
70+
hostingEnvironment.ocp_cloud_provider_availability_zone = engagementFormConfig?.cloud_options?.availability_zones?.options?.find(element => element.default).value;
71+
}
6372
propsOnSave(hostingEnvironment);
6473
onClose();
6574
};
@@ -127,6 +136,7 @@ export function OpenShiftClusterEditModal({
127136
hostingEnvironment={hostingEnvironment}
128137
/>
129138
<SelectFormField
139+
arial-label="Provider Region"
130140
label="Provider Region"
131141
isDisabled={
132142
availableProviderRegionOptions?.length === 0 ||
@@ -144,7 +154,29 @@ export function OpenShiftClusterEditModal({
144154
onChange={value => onChange('ocp_cloud_provider_region', value)}
145155
value={hostingEnvironment?.ocp_cloud_provider_region}
146156
/>
157+
{hasFeature(APP_FEATURES.availabilityZone) ?
158+
<SelectFormField
159+
aria-label='Availability Zone'
160+
label={<>Availability Zone
161+
<AvailabilityZoneTooltip /></>}
162+
isDisabled={
163+
engagementFormConfig?.cloud_options?.availability_zones?.options?.length === 0 ||
164+
!hasFeature(APP_FEATURES.writer)
165+
}
166+
testId="provider-availability-zone-select"
167+
emptyValue={{
168+
label: "Select an availability zone configuration"
169+
}}
170+
options={engagementFormConfig?.cloud_options?.availability_zones?.options?.map?.(
171+
v => ({ label: v.label, disabled: v.disabled, value: v.value })
172+
)}
173+
onChange={value => onChange('ocp_cloud_provider_availability_zone', value)}
174+
value={hostingEnvironment?.ocp_cloud_provider_availability_zone ?? engagementFormConfig?.cloud_options?.availability_zones?.options?.find(element => element.default).value}
175+
/>
176+
177+
: ''}
147178
<SelectFormField
179+
aria-label='OpenShift version'
148180
value={hostingEnvironment?.ocp_version || ''}
149181
testId="oc_version_select"
150182
emptyValue={{ label: 'Select a version' }}
@@ -170,6 +202,7 @@ export function OpenShiftClusterEditModal({
170202
<SelectFormField
171203
value={hostingEnvironment?.ocp_persistent_storage_size}
172204
testId="persistent-storage-select"
205+
aria-label='Persistent Storage Needs'
173206
label="Persistent Storage Needs"
174207
options={engagementFormConfig?.openshift_options?.persistent_storage?.options?.map?.(
175208
v => ({ label: v.label, disabled: v.disabled, value: v.value })
@@ -189,6 +222,7 @@ export function OpenShiftClusterEditModal({
189222
value={hostingEnvironment?.ocp_cluster_size || ''}
190223
emptyValue={{ label: 'Select cluster size' }}
191224
label="Cluster Size"
225+
aria-label="Cluster Size"
192226
isDisabled={!hasFeature(APP_FEATURES.writer)}
193227
onChange={value => onChange('ocp_cluster_size', value)}
194228
/>

src/components/engagement_form_fields/__tests__/__snapshots__/engagement_form_fields.spec.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Object {
163163
>
164164
<select
165165
aria-invalid="false"
166+
aria-label="Hosting Type"
166167
class="pf-c-form-control"
167168
data-ouia-component-id="OUIA-Generated-FormSelect-default-1"
168169
data-ouia-component-type="PF4/FormSelect"
@@ -264,6 +265,7 @@ Object {
264265
>
265266
<select
266267
aria-invalid="false"
268+
aria-label="Hosting Type"
267269
class="pf-c-form-control"
268270
data-ouia-component-id="OUIA-Generated-FormSelect-default-1"
269271
data-ouia-component-type="PF4/FormSelect"

src/components/engagement_form_fields/cloud_provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function CloudProviderFormField({
2323
return (
2424
<>
2525
<FormGroup fieldId="Hosting Platform" label="Hosting Type">
26-
<FormSelect isRequired isDisabled={true}>
26+
<FormSelect isRequired isDisabled={true} aria-label="Hosting Type">
2727
<FormSelectOption label={'OpenShift Container Platform'} aria-label="Hosting Platform"/>
2828
</FormSelect>
2929
</FormGroup>

0 commit comments

Comments
 (0)