|
| 1 | +import { |
| 2 | + AnalyticalTable, |
| 3 | + Icon, |
| 4 | + Popover, |
| 5 | + FlexBox, |
| 6 | + FlexBoxJustifyContent, |
| 7 | + Button, |
| 8 | + PopoverDomRef, |
| 9 | +} from '@ui5/webcomponents-react'; |
| 10 | +import { AnalyticalTableColumnDefinition } from '@ui5/webcomponents-react/wrappers'; |
| 11 | +import PopoverPlacement from '@ui5/webcomponents/dist/types/PopoverPlacement.js'; |
| 12 | +import '@ui5/webcomponents-icons/dist/copy'; |
| 13 | +import { JSX, useRef, useState, MouseEvent, ReactNode, FC } from 'react'; |
| 14 | +import { |
| 15 | + ControlPlaneStatusType, |
| 16 | + ReadyStatus, |
| 17 | + ControlPlaneStatusCondition, |
| 18 | +} from '../../lib/api/types/crate/controlPlanes'; |
| 19 | +import ReactTimeAgo from 'react-time-ago'; |
| 20 | +import { AnimatedHoverTextButton } from '../Helper/AnimatedHoverTextButton.tsx'; |
| 21 | +import { useTranslation } from 'react-i18next'; |
| 22 | +import { useLink } from '../../lib/shared/useLink.ts'; |
| 23 | +import TooltipCell from '../Shared/TooltipCell.tsx'; |
| 24 | + |
| 25 | +interface CellData<T> { |
| 26 | + cell: { |
| 27 | + value: ReactNode; |
| 28 | + }; |
| 29 | + row: { |
| 30 | + original: T; |
| 31 | + [key: string]: unknown; |
| 32 | + }; |
| 33 | + [key: string]: unknown; |
| 34 | +} |
| 35 | + |
| 36 | +type MCPHealthPopoverButtonProps = { |
| 37 | + resourceObject: unknown; |
| 38 | +}; |
| 39 | + |
| 40 | +const ResourceStatusPopoverButton: FC<MCPHealthPopoverButtonProps> = ({ resourceObject }) => { |
| 41 | + const popoverRef = useRef<PopoverDomRef>(null); |
| 42 | + const [open, setOpen] = useState(false); |
| 43 | + |
| 44 | + const handleOpenerClick = (e: MouseEvent<HTMLButtonElement>) => { |
| 45 | + if (popoverRef.current) { |
| 46 | + (popoverRef.current as unknown as { opener: EventTarget | null }).opener = e.target; |
| 47 | + setOpen((prev) => !prev); |
| 48 | + } |
| 49 | + }; |
| 50 | + |
| 51 | + // const statusTableColumns: AnalyticalTableColumnDefinition[] = [ |
| 52 | + // { |
| 53 | + // Header: t('MCPHealthPopoverButton.statusHeader'), |
| 54 | + // accessor: 'status', |
| 55 | + // width: 50, |
| 56 | + // Cell: (instance: CellData<ControlPlaneStatusCondition>) => { |
| 57 | + // const isReady = instance.cell.value === 'True'; |
| 58 | + // return ( |
| 59 | + // <Icon |
| 60 | + // style={{ color: isReady ? 'green' : 'red' }} |
| 61 | + // name={isReady ? 'sap-icon://sys-enter' : 'sap-icon://pending'} |
| 62 | + // /> |
| 63 | + // ); |
| 64 | + // }, |
| 65 | + // }, |
| 66 | + // { |
| 67 | + // Header: t('MCPHealthPopoverButton.typeHeader'), |
| 68 | + // accessor: 'type', |
| 69 | + // width: 150, |
| 70 | + // Cell: (instance: CellData<ControlPlaneStatusCondition>) => { |
| 71 | + // return <TooltipCell>{instance.cell.value}</TooltipCell>; |
| 72 | + // }, |
| 73 | + // }, |
| 74 | + // { |
| 75 | + // Header: t('MCPHealthPopoverButton.messageHeader'), |
| 76 | + // accessor: 'message', |
| 77 | + // width: 350, |
| 78 | + // Cell: (instance: CellData<ControlPlaneStatusCondition>) => { |
| 79 | + // return <TooltipCell>{instance.cell.value}</TooltipCell>; |
| 80 | + // }, |
| 81 | + // }, |
| 82 | + // { |
| 83 | + // Header: t('MCPHealthPopoverButton.reasonHeader'), |
| 84 | + // accessor: 'reason', |
| 85 | + // width: 100, |
| 86 | + // Cell: (instance: CellData<ControlPlaneStatusCondition>) => { |
| 87 | + // return <TooltipCell>{instance.cell.value}</TooltipCell>; |
| 88 | + // }, |
| 89 | + // }, |
| 90 | + // { |
| 91 | + // Header: t('MCPHealthPopoverButton.transitionHeader'), |
| 92 | + // accessor: 'lastTransitionTime', |
| 93 | + // width: 110, |
| 94 | + // Cell: (instance: CellData<ControlPlaneStatusCondition>) => { |
| 95 | + // const rawDate = instance.cell.value; |
| 96 | + // const date = new Date(rawDate as string); |
| 97 | + // return ( |
| 98 | + // <TooltipCell> |
| 99 | + // <ReactTimeAgo date={date} /> |
| 100 | + // </TooltipCell> |
| 101 | + // ); |
| 102 | + // }, |
| 103 | + // }, |
| 104 | + // ]; |
| 105 | + |
| 106 | + return ( |
| 107 | + <div className="component-title-row"> |
| 108 | + <AnimatedHoverTextButton icon={<span />} text={'test'} onClick={handleOpenerClick} /> |
| 109 | + <Popover ref={popoverRef} open={open} placement={PopoverPlacement.Bottom}> |
| 110 | + {/*<StatusTable*/} |
| 111 | + {/* status={mcpStatus}*/} |
| 112 | + {/* tableColumns={statusTableColumns}*/} |
| 113 | + {/* githubIssuesLink={constructGithubIssuesLink()}*/} |
| 114 | + {/*/>*/} |
| 115 | + test3 |
| 116 | + </Popover> |
| 117 | + </div> |
| 118 | + ); |
| 119 | +}; |
| 120 | + |
| 121 | +// type StatusTableProps = { |
| 122 | +// status: ControlPlaneStatusType | undefined; |
| 123 | +// tableColumns: AnalyticalTableColumnDefinition[]; |
| 124 | +// githubIssuesLink: string; |
| 125 | +// }; |
| 126 | + |
| 127 | +// const StatusTable = ({ status, tableColumns, githubIssuesLink }: StatusTableProps) => { |
| 128 | +// const { t } = useTranslation(); |
| 129 | +// |
| 130 | +// const sortedConditions = status?.conditions ? [...status.conditions].sort((a, b) => (a.type < b.type ? -1 : 1)) : []; |
| 131 | +// |
| 132 | +// return ( |
| 133 | +// <div style={{ width: 770 }}> |
| 134 | +// <AnalyticalTable scaleWidthMode="Default" columns={tableColumns} data={sortedConditions} /> |
| 135 | +// <FlexBox justifyContent={FlexBoxJustifyContent.End} style={{ marginTop: '0.5rem' }}> |
| 136 | +// <a href={githubIssuesLink} target="_blank" rel="noreferrer"> |
| 137 | +// <Button>{t('MCPHealthPopoverButton.createSupportTicketButton')}</Button> |
| 138 | +// </a> |
| 139 | +// </FlexBox> |
| 140 | +// </div> |
| 141 | +// ); |
| 142 | +// }; |
| 143 | + |
| 144 | +const getIconForOverallStatus = (status: ReadyStatus | undefined): JSX.Element => { |
| 145 | + switch (status) { |
| 146 | + case ReadyStatus.Ready: |
| 147 | + return <Icon style={{ color: 'green' }} name="sap-icon://sys-enter" />; |
| 148 | + case ReadyStatus.NotReady: |
| 149 | + return <Icon style={{ color: 'red' }} name="sap-icon://pending" />; |
| 150 | + case ReadyStatus.InDeletion: |
| 151 | + return <Icon style={{ color: 'orange' }} name="sap-icon://delete" />; |
| 152 | + default: |
| 153 | + return <></>; |
| 154 | + } |
| 155 | +}; |
0 commit comments