Skip to content

Commit 4050434

Browse files
committed
Update MCPHealthPopoverButton.tsx
1 parent 37bcef5 commit 4050434

File tree

1 file changed

+48
-60
lines changed

1 file changed

+48
-60
lines changed
Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
import { AnalyticalTable, Icon, Popover, FlexBox, FlexBoxJustifyContent, Button } from '@ui5/webcomponents-react';
2-
import { AnalyticalTableColumnDefinition } from '@ui5/webcomponents-react/wrappers';
1+
import {
2+
AnalyticalTable,
3+
Icon,
4+
Popover,
5+
FlexBox,
6+
FlexBoxJustifyContent,
7+
Button,
8+
PopoverDomRef,
9+
} from '@ui5/webcomponents-react';
10+
import { AnalyticalTableColumnDefinition, AnalyticalTableCell } from '@ui5/webcomponents-react/wrappers';
311
import PopoverPlacement from '@ui5/webcomponents/dist/types/PopoverPlacement.js';
412
import '@ui5/webcomponents-icons/dist/copy';
5-
import { JSX, useRef, useState } from 'react';
6-
import { ControlPlaneStatusType, ReadyStatus } from '../../lib/api/types/crate/controlPlanes';
13+
import { JSX, useRef, useState, MouseEvent } from 'react';
14+
import { ControlPlaneStatusType, ReadyStatus, ControlPlaneCondition } from '../../lib/api/types/crate/controlPlanes';
715
import ReactTimeAgo from 'react-time-ago';
816
import { AnimatedHoverTextButton } from '../Helper/AnimatedHoverTextButton.tsx';
917
import { useTranslation } from 'react-i18next';
1018
import { useLink } from '../../lib/shared/useLink.ts';
1119
import TooltipCell from '../Shared/TooltipCell.tsx';
12-
export default function MCPHealthPopoverButton({
13-
mcpStatus,
14-
projectName,
15-
workspaceName,
16-
mcpName,
17-
}: {
20+
21+
type MCPHealthPopoverButtonProps = {
1822
mcpStatus: ControlPlaneStatusType | undefined;
1923
projectName: string;
2024
workspaceName: string;
2125
mcpName: string;
22-
}) {
23-
const popoverRef = useRef(null);
26+
};
27+
28+
const MCPHealthPopoverButton = ({ mcpStatus, projectName, workspaceName, mcpName }: MCPHealthPopoverButtonProps) => {
29+
const popoverRef = useRef<PopoverDomRef>(null);
2430
const [open, setOpen] = useState(false);
2531
const { githubIssuesSupportTicket } = useLink();
26-
2732
const { t } = useTranslation();
2833

29-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
30-
const handleOpenerClick = (e: any) => {
34+
const handleOpenerClick = (e: MouseEvent<HTMLButtonElement>) => {
3135
if (popoverRef.current) {
32-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33-
const ref = popoverRef.current as any;
34-
ref.opener = e.target;
36+
(popoverRef.current as unknown as { opener: EventTarget | null }).opener = e.target;
3537
setOpen((prev) => !prev);
3638
}
3739
};
3840

39-
const getTicketTitle = () => {
41+
const getTicketTitle = (): string => {
4042
switch (mcpStatus?.status) {
4143
case ReadyStatus.Ready:
4244
return t('MCPHealthPopoverButton.supportTicketTitleReady');
@@ -49,13 +51,13 @@ export default function MCPHealthPopoverButton({
4951
}
5052
};
5153

52-
const constructGithubIssuesLink = () => {
54+
const constructGithubIssuesLink = (): string => {
5355
const clusterDetails = `${projectName}/${workspaceName}/${mcpName}`;
5456

5557
const statusDetails = mcpStatus?.conditions
5658
? `${t('MCPHealthPopoverButton.statusDetailsLabel')}: ${mcpStatus.status}\n\n${t('MCPHealthPopoverButton.detailsLabel')}\n` +
57-
mcpStatus?.conditions
58-
.map((condition) => {
59+
mcpStatus.conditions
60+
.map((condition: ControlPlaneCondition) => {
5961
let text = `- ${condition.type}: ${condition.status}\n`;
6062
if (condition.reason) text += ` - ${t('MCPHealthPopoverButton.reasonHeader')}: ${condition.reason}\n`;
6163
if (condition.message) text += ` - ${t('MCPHealthPopoverButton.messageHeader')}: ${condition.message}\n`;
@@ -79,8 +81,7 @@ export default function MCPHealthPopoverButton({
7981
Header: t('MCPHealthPopoverButton.statusHeader'),
8082
accessor: 'status',
8183
width: 50,
82-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
83-
Cell: (instance: any) => {
84+
Cell: (instance: AnalyticalTableCell<ControlPlaneCondition>) => {
8485
const isReady = instance.cell.value === 'True';
8586
return (
8687
<Icon
@@ -94,38 +95,33 @@ export default function MCPHealthPopoverButton({
9495
Header: t('MCPHealthPopoverButton.typeHeader'),
9596
accessor: 'type',
9697
width: 150,
97-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
98-
Cell: (instance: any) => {
98+
Cell: (instance: AnalyticalTableCell<ControlPlaneCondition>) => {
9999
return <TooltipCell>{instance.cell.value}</TooltipCell>;
100100
},
101101
},
102102
{
103103
Header: t('MCPHealthPopoverButton.messageHeader'),
104104
accessor: 'message',
105105
width: 350,
106-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
107-
Cell: (instance: any) => {
106+
Cell: (instance: AnalyticalTableCell<ControlPlaneCondition>) => {
108107
return <TooltipCell>{instance.cell.value}</TooltipCell>;
109108
},
110109
},
111110
{
112111
Header: t('MCPHealthPopoverButton.reasonHeader'),
113112
accessor: 'reason',
114113
width: 100,
115-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
116-
Cell: (instance: any) => {
114+
Cell: (instance: AnalyticalTableCell<ControlPlaneCondition>) => {
117115
return <TooltipCell>{instance.cell.value}</TooltipCell>;
118116
},
119117
},
120118
{
121119
Header: t('MCPHealthPopoverButton.transitionHeader'),
122120
accessor: 'lastTransitionTime',
123121
width: 110,
124-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125-
Cell: (instance: any) => {
122+
Cell: (instance: AnalyticalTableCell<ControlPlaneCondition>) => {
126123
const rawDate = instance.cell.value;
127124
const date = new Date(rawDate);
128-
129125
return (
130126
<TooltipCell>
131127
<ReactTimeAgo date={date} />
@@ -143,58 +139,50 @@ export default function MCPHealthPopoverButton({
143139
onClick={handleOpenerClick}
144140
/>
145141
<Popover ref={popoverRef} open={open} placement={PopoverPlacement.Bottom}>
146-
{
147-
<StatusTable
148-
status={mcpStatus}
149-
tableColumns={statusTableColumns}
150-
githubIssuesLink={constructGithubIssuesLink()}
151-
/>
152-
}
142+
<StatusTable
143+
status={mcpStatus}
144+
tableColumns={statusTableColumns}
145+
githubIssuesLink={constructGithubIssuesLink()}
146+
/>
153147
</Popover>
154148
</div>
155149
);
156-
}
150+
};
157151

158-
function StatusTable({
159-
status,
160-
tableColumns,
161-
githubIssuesLink,
162-
}: {
152+
export default MCPHealthPopoverButton;
153+
154+
type StatusTableProps = {
163155
status: ControlPlaneStatusType | undefined;
164156
tableColumns: AnalyticalTableColumnDefinition[];
165157
githubIssuesLink: string;
166-
}) {
158+
};
159+
160+
const StatusTable = ({ status, tableColumns, githubIssuesLink }: StatusTableProps) => {
167161
const { t } = useTranslation();
168162

163+
const sortedConditions = status?.conditions ? [...status.conditions].sort((a, b) => (a.type < b.type ? -1 : 1)) : [];
164+
169165
return (
170166
<div style={{ width: 770 }}>
171-
<AnalyticalTable
172-
scaleWidthMode="Default"
173-
columns={tableColumns}
174-
data={
175-
status?.conditions?.sort((a, b) => {
176-
return a.type < b.type ? -1 : 1;
177-
}) ?? []
178-
}
179-
/>
167+
<AnalyticalTable scaleWidthMode="Default" columns={tableColumns} data={sortedConditions} />
180168
<FlexBox justifyContent={FlexBoxJustifyContent.End} style={{ marginTop: '0.5rem' }}>
181169
<a href={githubIssuesLink} target="_blank" rel="noreferrer">
182170
<Button>{t('MCPHealthPopoverButton.createSupportTicketButton')}</Button>
183171
</a>
184172
</FlexBox>
185173
</div>
186174
);
187-
}
175+
};
188176

189-
function getIconForOverallStatus(status: ReadyStatus | undefined): JSX.Element {
177+
const getIconForOverallStatus = (status: ReadyStatus | undefined): JSX.Element => {
190178
switch (status) {
191179
case ReadyStatus.Ready:
192180
return <Icon style={{ color: 'green' }} name="sap-icon://sys-enter" />;
193181
case ReadyStatus.NotReady:
194182
return <Icon style={{ color: 'red' }} name="sap-icon://pending" />;
195183
case ReadyStatus.InDeletion:
196184
return <Icon style={{ color: 'orange' }} name="sap-icon://delete" />;
197-
case undefined:
185+
default:
198186
return <></>;
199187
}
200-
}
188+
};

0 commit comments

Comments
 (0)