forked from eclipse-xpanse/xpanse-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'eclipse-xpanse:main' into main
- Loading branch information
Showing
30 changed files
with
1,517 additions
and
705 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 0 additions & 96 deletions
96
src/components/content/order/common/AvailabilityZoneInfo.tsx
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
src/components/content/order/common/availabilityzone/AvailabilityZoneButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { AvailabilityZoneConfig } from '../../../../../xpanse-api/generated'; | ||
import { Alert, Flex, Radio } from 'antd'; | ||
import React from 'react'; | ||
|
||
export function AvailabilityZoneButton({ | ||
availabilityZoneConfig, | ||
availabilityZones, | ||
selectRegion, | ||
onAvailabilityZoneChange, | ||
selectAvailabilityZones, | ||
}: { | ||
availabilityZoneConfig: AvailabilityZoneConfig; | ||
availabilityZones: string[] | undefined; | ||
selectRegion: string; | ||
onAvailabilityZoneChange: (varName: string, availabilityZone: string | undefined) => void; | ||
selectAvailabilityZones: Record<string, string | undefined>; | ||
}) { | ||
const DEFAULT_OPTIONAL_AZ = 'Not Selected'; | ||
function onChange(varName: string, availabilityZone: string) { | ||
onAvailabilityZoneChange(varName, availabilityZone !== DEFAULT_OPTIONAL_AZ ? availabilityZone : undefined); | ||
} | ||
|
||
return ( | ||
<> | ||
<Flex vertical gap='middle'> | ||
{availabilityZoneConfig.mandatory ? ( | ||
availabilityZones && availabilityZones.length > 0 ? ( | ||
<Radio.Group | ||
buttonStyle='solid' | ||
onChange={(e) => { | ||
onChange(availabilityZoneConfig.varName, e.target.value as string); | ||
}} | ||
value={selectAvailabilityZones[availabilityZoneConfig.varName]} | ||
> | ||
{availabilityZones.map((availabilityZonesVariable) => ( | ||
<Radio.Button | ||
name={availabilityZoneConfig.displayName} | ||
key={availabilityZonesVariable} | ||
value={availabilityZonesVariable} | ||
> | ||
{availabilityZonesVariable} | ||
</Radio.Button> | ||
))} | ||
</Radio.Group> | ||
) : ( | ||
<Alert | ||
message={'No availability zones found for region ' + selectRegion} | ||
description={'Mandatory field. Cannot proceed.'} | ||
type={'error'} | ||
closable={false} | ||
/> | ||
) | ||
) : ( | ||
<Radio.Group | ||
buttonStyle='solid' | ||
onChange={(e) => { | ||
onChange(availabilityZoneConfig.varName, e.target.value as string); | ||
}} | ||
value={selectAvailabilityZones[availabilityZoneConfig.varName] ?? DEFAULT_OPTIONAL_AZ} | ||
> | ||
{availabilityZones && availabilityZones.length > 0 ? ( | ||
<> | ||
<Radio.Button name={availabilityZoneConfig.displayName} value={DEFAULT_OPTIONAL_AZ}> | ||
{DEFAULT_OPTIONAL_AZ} | ||
</Radio.Button> | ||
{availabilityZones.map((availabilityZonesVariable) => ( | ||
<Radio.Button | ||
name={availabilityZoneConfig.displayName} | ||
key={availabilityZonesVariable} | ||
value={availabilityZonesVariable} | ||
> | ||
{availabilityZonesVariable} | ||
</Radio.Button> | ||
))} | ||
; | ||
</> | ||
) : ( | ||
<Alert | ||
message={'No availability zones found for region ' + selectRegion} | ||
description={'Optional field. Can proceed.'} | ||
type={'success'} | ||
closable={false} | ||
/> | ||
)} | ||
</Radio.Group> | ||
)} | ||
</Flex> | ||
</> | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/components/content/order/common/availabilityzone/AvailabilityZoneError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { ApiError, Response } from '../../../../../xpanse-api/generated'; | ||
import { Alert } from 'antd'; | ||
import { convertStringArrayToUnorderedList } from '../../../../utils/generateUnorderedList'; | ||
import React from 'react'; | ||
|
||
export function AvailabilityZoneError({ error }: { error: Error }) { | ||
if (error instanceof ApiError && error.body && 'details' in error.body) { | ||
const response: Response = error.body as Response; | ||
return ( | ||
<Alert | ||
message={response.resultType.valueOf()} | ||
description={convertStringArrayToUnorderedList(response.details)} | ||
type={'error'} | ||
closable={false} | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<Alert | ||
message='Fetching Availability Regions Failed' | ||
description={error.message} | ||
type={'error'} | ||
closable={false} | ||
/> | ||
); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/components/content/order/common/availabilityzone/AvailabilityZoneFormItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { AvailabilityZoneConfig, UserOrderableServiceVo } from '../../../../../xpanse-api/generated'; | ||
import { Form } from 'antd'; | ||
import React from 'react'; | ||
import { AvailabilityZoneButton } from './AvailabilityZoneButton'; | ||
import useGetAvailabilityZonesForRegionQuery from '../utils/useGetAvailabilityZonesForRegionQuery'; | ||
import { AvailabilityZoneLoading } from './AvailabilityZoneLoading'; | ||
import { AvailabilityZoneError } from './AvailabilityZoneError'; | ||
|
||
export function AvailabilityZoneFormItem({ | ||
availabilityZoneConfig, | ||
selectRegion, | ||
onAvailabilityZoneChange, | ||
selectAvailabilityZones, | ||
selectCsp, | ||
}: { | ||
availabilityZoneConfig: AvailabilityZoneConfig; | ||
selectRegion: string; | ||
onAvailabilityZoneChange: (varName: string, availabilityZone: string | undefined) => void; | ||
selectAvailabilityZones: Record<string, string | undefined>; | ||
selectCsp: UserOrderableServiceVo.csp; | ||
}) { | ||
const availabilityZonesVariableRequest = useGetAvailabilityZonesForRegionQuery(selectCsp, selectRegion); | ||
|
||
function getFormContent() { | ||
if (availabilityZonesVariableRequest.isLoading || availabilityZonesVariableRequest.isFetching) { | ||
return <AvailabilityZoneLoading key={availabilityZoneConfig.varName} />; | ||
} | ||
if (availabilityZonesVariableRequest.isError) { | ||
return ( | ||
<AvailabilityZoneError | ||
error={availabilityZonesVariableRequest.error} | ||
key={availabilityZoneConfig.varName} | ||
/> | ||
); | ||
} | ||
if (availabilityZonesVariableRequest.data) { | ||
return ( | ||
<AvailabilityZoneButton | ||
availabilityZoneConfig={availabilityZoneConfig} | ||
selectRegion={selectRegion} | ||
availabilityZones={availabilityZonesVariableRequest.data} | ||
onAvailabilityZoneChange={onAvailabilityZoneChange} | ||
selectAvailabilityZones={selectAvailabilityZones} | ||
/> | ||
); | ||
} | ||
return null; | ||
} | ||
return ( | ||
<Form.Item | ||
key={availabilityZoneConfig.varName} | ||
label={<p style={{ fontWeight: 'bold' }}>{availabilityZoneConfig.displayName}</p>} | ||
required={availabilityZoneConfig.mandatory} | ||
rules={[ | ||
{ | ||
required: availabilityZoneConfig.mandatory, | ||
message: availabilityZoneConfig.displayName + 'is required', | ||
}, | ||
{ type: 'string' }, | ||
]} | ||
> | ||
{getFormContent()} | ||
</Form.Item> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/components/content/order/common/availabilityzone/AvailabilityZoneLoading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { Skeleton } from 'antd'; | ||
import React from 'react'; | ||
|
||
export function AvailabilityZoneLoading() { | ||
return <Skeleton active={true} loading={true} paragraph={{ rows: 1, width: ['20%'] }} />; | ||
} |
Oops, something went wrong.