Skip to content

Commit 2e791dc

Browse files
committed
fix(type)
1 parent f6936c5 commit 2e791dc

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

src/lib/api/types/crate/controlPlanes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export interface Metadata {
66
name: string;
77
namespace: string;
88
creationTimestamp: string;
9-
annotations: {
9+
annotations?: {
1010
'openmcp.cloud/display-name': string;
11-
'openmcp.cloud/created-by': string;
11+
'openmcp.cloud/created-by'?: string;
1212
};
1313
}
1414

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { McpHeader } from './McpHeader';
22
import { ControlPlaneType } from '../../../lib/api/types/crate/controlPlanes.ts';
33

4-
const mcp = {
5-
metadata: {
6-
name: 'my-control-plane',
7-
creationTimestamp: '2024-04-15T10:30:00.000Z',
8-
annotations: {
9-
'openmcp.cloud/created-by': '[email protected]',
10-
},
11-
},
12-
} as ControlPlaneType;
13-
144
describe('McpHeader', () => {
15-
it('renders MCP matadata', () => {
5+
it('renders MCP metadata', () => {
6+
const mcp = {
7+
metadata: {
8+
name: 'my-control-plane',
9+
creationTimestamp: '2024-04-15T10:30:00.000Z',
10+
annotations: {
11+
'openmcp.cloud/created-by': '[email protected]',
12+
},
13+
},
14+
} as ControlPlaneType;
15+
1616
cy.clock(new Date('2024-04-17T10:30:00.000Z').getTime()); // 2 days after MCP creation date
1717
const creationDateAsString = new Date('2024-04-15T10:30:00.000Z').toLocaleDateString(undefined, {
1818
day: 'numeric',
@@ -26,4 +26,25 @@ describe('McpHeader', () => {
2626
cy.contains('span', '[email protected]').should('be.visible');
2727
cy.contains('span', `${creationDateAsString} (2 days ago)`).should('be.visible');
2828
});
29+
30+
it('renders with missing MCP metadata', () => {
31+
const mcp = {
32+
metadata: {
33+
name: 'my-control-plane',
34+
creationTimestamp: '2024-04-15T10:30:00.000Z',
35+
},
36+
} as ControlPlaneType; // missing annotations
37+
38+
cy.clock(new Date('2024-04-17T10:30:00.000Z').getTime()); // 2 days after MCP creation date
39+
const creationDateAsString = new Date('2024-04-15T10:30:00.000Z').toLocaleDateString(undefined, {
40+
day: 'numeric',
41+
month: 'long',
42+
year: 'numeric',
43+
});
44+
45+
cy.mount(<McpHeader mcp={mcp} />);
46+
47+
cy.contains('span', 'my-control-plane').should('be.visible');
48+
cy.contains('span', `${creationDateAsString} (2 days ago)`).should('be.visible');
49+
});
2950
});

src/spaces/mcp/components/McpHeader.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.grid {
66
display: grid;
77
grid-template-columns: auto auto;
8-
gap: 6px 12px;
8+
gap: 0.375rem 0.75rem;
99
align-items: center;
1010
font-size: var(--sapFontSize);
1111
}

src/spaces/mcp/components/McpHeader.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ControlPlaneType } from '../../../lib/api/types/crate/controlPlanes.ts'
33
import styles from './McpHeader.module.css';
44
import { formatDateAsTimeAgo } from '../../../utils/i18n/timeAgo.ts';
55
import { useTranslation } from 'react-i18next';
6-
import { Button, Icon } from '@ui5/webcomponents-react';
76

87
export interface McpHeaderProps {
98
mcp: ControlPlaneType;
@@ -17,6 +16,9 @@ export function McpHeader({ mcp }: McpHeaderProps) {
1716
month: 'long',
1817
year: 'numeric',
1918
});
19+
20+
const createdBy = mcp.metadata.annotations?.['openmcp.cloud/created-by'];
21+
2022
return (
2123
<div className={styles.container}>
2224
<div className={styles.grid}>
@@ -28,8 +30,12 @@ export function McpHeader({ mcp }: McpHeaderProps) {
2830
{created} ({formatDateAsTimeAgo(mcp.metadata.creationTimestamp)})
2931
</span>
3032

31-
<span className={styles.label}>{t('McpHeader.createdByLabel')}</span>
32-
<span>{mcp.metadata.annotations['openmcp.cloud/created-by']}</span>
33+
{createdBy ? (
34+
<>
35+
<span className={styles.label}>{t('McpHeader.createdByLabel')}</span>
36+
<span>{createdBy}</span>
37+
</>
38+
) : null}
3339
</div>
3440
</div>
3541
);

0 commit comments

Comments
 (0)