|
| 1 | +import React from 'react'; |
| 2 | +import { EditProviderUIModal, useModal } from 'src/modules/Providers/modals'; |
| 3 | +import { ForkliftTrans, useForkliftTranslation } from 'src/utils/i18n'; |
| 4 | + |
| 5 | +import { ExternalLink } from '@kubev2v/common'; |
| 6 | +import { DescriptionListDescription } from '@patternfly/react-core'; |
| 7 | + |
| 8 | +import { DetailsItem } from '../../../../../utils'; |
| 9 | + |
| 10 | +import { ProviderDetailsItemProps } from './ProviderDetailsItem'; |
| 11 | + |
| 12 | +/** |
| 13 | + * @typedef {Object} ExternalManagementLinkDetailsItemProps - extends ProviderDetailsItemProps |
| 14 | + * |
| 15 | + * @property {string} [webUILinkText - A label text to be displayed as a content. |
| 16 | + * @property {string} [webUILink] - provider's management system external link. |
| 17 | + */ |
| 18 | +export interface ExternalManagementLinkDetailsItemProps extends ProviderDetailsItemProps { |
| 19 | + webUILinkText?: string; |
| 20 | + webUILink?: string; |
| 21 | +} |
| 22 | + |
| 23 | +/** |
| 24 | + * Component for displaying the provider management system external link. |
| 25 | + * |
| 26 | + * @component |
| 27 | + * @param {DetailsItemProps} props - The props of the details item. |
| 28 | + */ |
| 29 | +export const ExternalManagementLinkDetailsItem: React.FC< |
| 30 | + ExternalManagementLinkDetailsItemProps |
| 31 | +> = ({ resource: provider, moreInfoLink, helpContent, canPatch, webUILinkText, webUILink }) => { |
| 32 | + const { t } = useForkliftTranslation(); |
| 33 | + const { showModal } = useModal(); |
| 34 | + |
| 35 | + const defaultHelpContent = ( |
| 36 | + <ForkliftTrans> |
| 37 | + <p> |
| 38 | + Use the external management system link to access the web-based user interface for the |
| 39 | + provider virtual machine management system. |
| 40 | + </p> |
| 41 | + <p>You can edit and store the link to the management system to customize the link URL.</p> |
| 42 | + </ForkliftTrans> |
| 43 | + ); |
| 44 | + |
| 45 | + const webUILinkContent = webUILink ? ( |
| 46 | + <ExternalLink text={webUILinkText} href={webUILink} isInline={true}> |
| 47 | + {webUILink} |
| 48 | + </ExternalLink> |
| 49 | + ) : ( |
| 50 | + <span className="text-muted"> |
| 51 | + {canPatch && provider?.metadata |
| 52 | + ? t('Click the pencil for setting provider web UI link') |
| 53 | + : t('No value for provider web UI link')} |
| 54 | + </span> |
| 55 | + ); |
| 56 | + |
| 57 | + return ( |
| 58 | + <DescriptionListDescription> |
| 59 | + <DetailsItem |
| 60 | + title={t('External management system')} |
| 61 | + moreInfoLink={moreInfoLink} |
| 62 | + helpContent={helpContent ?? defaultHelpContent} |
| 63 | + crumbs={['metadata', 'annotations', 'forklift.konveyor.io/providerUI']} |
| 64 | + content={webUILinkContent} |
| 65 | + onEdit={ |
| 66 | + canPatch && |
| 67 | + provider?.metadata && |
| 68 | + (() => showModal(<EditProviderUIModal resource={provider} content={webUILink} />)) |
| 69 | + } |
| 70 | + /> |
| 71 | + </DescriptionListDescription> |
| 72 | + ); |
| 73 | +}; |
0 commit comments