-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1159 from sgratch/add-openshift-ui-link
🐾 Provide the OCP UI URL as part of the remote OCP provider detais page
- Loading branch information
Showing
9 changed files
with
142 additions
and
1 deletion.
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
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
43 changes: 43 additions & 0 deletions
43
...klift-console-plugin/src/modules/Providers/modals/EditProviderUI/OpenshiftEditUIModal.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,43 @@ | ||
import React from 'react'; | ||
import { ForkliftTrans, useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { ProviderModel } from '@kubev2v/types'; | ||
import { ModalVariant } from '@patternfly/react-core'; | ||
|
||
import { validateOpenshiftUILink } from '../../utils'; | ||
import { EditModal } from '../EditModal'; | ||
|
||
import { patchProviderUI } from './utils/patchProviderUI'; | ||
import { EditProviderUIModalProps } from './EditProviderUIModal'; | ||
|
||
export const OpenshiftEditUIModal: React.FC<EditProviderUIModalProps> = (props) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
const ModalBody = ( | ||
<ForkliftTrans> | ||
<p>Link for the OpenShift Virtualization web console UI.</p> | ||
<p> | ||
Use this link to access the user interface for the provider's virtualization | ||
management. | ||
</p> | ||
<p>If no link value is specify then a default auto calculated or an empty value is set.</p> | ||
</ForkliftTrans> | ||
); | ||
|
||
return ( | ||
<EditModal | ||
{...props} | ||
jsonPath={['metadata', 'annotations', 'forklift.konveyor.io/providerUI']} | ||
title={props?.title || t('Edit provider web UI link')} | ||
label={props?.label || t('Provider web UI link')} | ||
model={ProviderModel} | ||
variant={ModalVariant.large} | ||
body={ModalBody} | ||
helperText={t( | ||
'Link for OpenShift Virtualization web console UI. For example, https://console-openshift-console.apps.openshift-domain.com.', | ||
)} | ||
onConfirmHook={patchProviderUI} | ||
validationHook={validateOpenshiftUILink} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/forklift-console-plugin/src/modules/Providers/modals/EditProviderUI/index.ts
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
41 changes: 41 additions & 0 deletions
41
...ugin/src/modules/Providers/utils/validators/provider/openshift/validateOpenshiftUILink.ts
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,41 @@ | ||
import { validateURL, ValidationMsg } from '../../common'; | ||
|
||
export const validateOpenshiftUILink = (uiLink: string | number): ValidationMsg => { | ||
// For a newly opened form where the field is not set yet, set the validation type to default. | ||
if (uiLink === undefined) { | ||
return { | ||
type: 'default', | ||
msg: 'The link for OpenShift Virtualization web console UI. For example, https://console-openshift-console.apps.openshift-domain.com.', | ||
}; | ||
} | ||
|
||
// Sanity check | ||
if (typeof uiLink !== 'string') { | ||
return { | ||
type: 'error', | ||
msg: 'The link for the OpenShift Virtualization web console UI is not a string', | ||
}; | ||
} | ||
|
||
const trimmedUrl: string = uiLink.trim(); | ||
const isValidURL = validateURL(trimmedUrl); | ||
|
||
if (trimmedUrl === '') { | ||
return { | ||
type: 'warning', | ||
msg: 'The link for the OpenShift Virtualization web console UI is empty. A default or an empty value will be used.', | ||
}; | ||
} | ||
|
||
if (!isValidURL) { | ||
return { | ||
type: 'error', | ||
msg: 'The link for the OpenShift Virtualization web console UI invalid. It should include the schema and path, for example: https://console-openshift-console.apps.openshift-domain.com.', | ||
}; | ||
} | ||
|
||
return { | ||
type: 'success', | ||
msg: 'The link for OpenShift Virtualization web console UI. For example, https://console-openshift-console.apps.openshift-domain.com.', | ||
}; | ||
}; |
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
37 changes: 37 additions & 0 deletions
37
.../Providers/views/details/components/DetailsSection/utils/getOpenshiftProviderWebUILink.ts
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,37 @@ | ||
import { V1beta1Provider } from '@kubev2v/types'; | ||
|
||
import { getProviderUIAnnotation } from './getProviderUIAnnotation'; | ||
|
||
/** | ||
* A function for auto calculating the Openshift UI link. | ||
* It extracts the provider's Openshift UI link, E.g. https://console-openshift-console.apps.example.com | ||
* from the Openshift URL, E.g. https://api.example.com:6443 | ||
* | ||
* returns the calculated web ui link or an empty string if calculation is avoided | ||
*/ | ||
export const getOpenshiftProviderWebUILink = (provider: V1beta1Provider): string => { | ||
// Check for custom link | ||
const customLink = getProviderUIAnnotation(provider); | ||
if (customLink) { | ||
return customLink; | ||
} | ||
|
||
const url = provider?.spec?.url; | ||
if (!url) { | ||
return ''; | ||
} | ||
const urlObj = new URL(url); | ||
|
||
// remove the port | ||
urlObj.port = ''; | ||
|
||
// replace the host prefix of 'api.' with 'console-openshift-console.apps.' | ||
if (urlObj.host.startsWith('api.')) { | ||
const newHostName = 'console-openshift-console.apps.' + urlObj.host.slice(4); | ||
urlObj.host = newHostName; | ||
|
||
return urlObj.toString(); | ||
} else { | ||
return ''; | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
...nsole-plugin/src/modules/Providers/views/details/components/DetailsSection/utils/index.ts
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