Skip to content

Commit 5ebfb99

Browse files
authored
rename list (#24)
1 parent 1abbc84 commit 5ebfb99

File tree

15 files changed

+131
-24
lines changed

15 files changed

+131
-24
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Examples
2+
3+
```js
4+
<ConditionLabel
5+
message={'success'}
6+
reason={'ready'}
7+
status={'true'}
8+
type={'Ready'}
9+
/>
10+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react';
2+
3+
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
4+
5+
import { conditionsMock } from './tests/mocks';
6+
import { ConditionLabel } from './ConditionLabel';
7+
8+
afterEach(cleanup);
9+
10+
test('ConditionLabel', async () => {
11+
const { message, reason, status, type } = conditionsMock[0];
12+
const { asFragment, getByText } = render(
13+
<ConditionLabel message={message} reason={reason} status={status} type={type} />,
14+
);
15+
const firstRender = asFragment();
16+
17+
expect(firstRender).toMatchSnapshot();
18+
19+
// click on condition to open popover
20+
fireEvent.click(getByText(`${reason}=${status}`));
21+
22+
if (!message) return;
23+
24+
const popoverMessage = await screen.findByText(message);
25+
26+
expect(popoverMessage).toHaveTextContent(message);
27+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as React from 'react';
2+
3+
import { Label, Popover, PopoverPosition } from '@patternfly/react-core';
4+
5+
export interface k8sStatusConditions {
6+
type: string;
7+
status?: string;
8+
reason?: string;
9+
message?: string;
10+
}
11+
12+
/**
13+
* ConditionLabel renders a k8sStatusConditions
14+
*/
15+
export const ConditionLabel: React.FC<k8sStatusConditions> = React.memo((condition) => {
16+
const preventLabelLink = React.useCallback((e) => e.preventDefault(), []);
17+
18+
const getBodyContent = React.useCallback(
19+
() => <div>{condition?.message}</div>,
20+
[condition?.message],
21+
);
22+
23+
return (
24+
<Popover
25+
position={PopoverPosition.top}
26+
aria-label="Condition Popover"
27+
bodyContent={getBodyContent}
28+
>
29+
<Label color="grey" isTruncated href="#" onClick={preventLabelLink}>
30+
{condition?.reason}={condition?.status}
31+
</Label>
32+
</Popover>
33+
);
34+
});
35+
ConditionLabel.displayName = 'ConditionLabel';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ConditionLabel 1`] = `
4+
<DocumentFragment>
5+
<span
6+
class="pf-c-label"
7+
>
8+
<a
9+
class="pf-c-label__content"
10+
href="#"
11+
>
12+
<span
13+
class="pf-c-label__text"
14+
>
15+
no_vmi=true
16+
</span>
17+
</a>
18+
</span>
19+
</DocumentFragment>
20+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ConditionLabel';
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Examples
22

33
```js
4-
<VMStatusConditionLabelList conditions={[
4+
<ConditionLabelList conditions={[
55
{
66
message: 'no vmi found',
77
reason: 'no_vmi',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react';
2+
3+
import { cleanup, render } from '@testing-library/react';
4+
5+
import { conditionsMock } from './tests/mocks';
6+
import { ConditionLabelList } from './ConditionLabelList';
7+
8+
afterEach(cleanup);
9+
10+
test('Render ConditionLabelList', () => {
11+
const { asFragment } = render(<ConditionLabelList conditions={conditionsMock} />);
12+
expect(asFragment()).toMatchSnapshot();
13+
});
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import * as React from 'react';
22

3-
import { V1VirtualMachineCondition } from '@kubevirt-ui/kubevirt-api/kubevirt';
43
import { LabelGroup } from '@patternfly/react-core';
54

6-
import { ConditionLabel } from '../ConditionLabel';
5+
import { ConditionLabel, k8sStatusConditions } from '../ConditionLabel';
76

87
/**
98
* VirtualMachineCondition renders a list of a k8s resource conditions
109
* */
11-
export interface VMStatusConditionLabelListProps {
12-
conditions: V1VirtualMachineCondition[];
10+
export interface ConditionLabelListProps {
11+
conditions: k8sStatusConditions[];
1312
}
1413

15-
export const VMStatusConditionLabelList: React.FC<VMStatusConditionLabelListProps> = React.memo(
14+
export const ConditionLabelList: React.FC<ConditionLabelListProps> = React.memo(
1615
({ conditions }) => {
1716
return (
1817
<LabelGroup>
@@ -29,4 +28,4 @@ export const VMStatusConditionLabelList: React.FC<VMStatusConditionLabelListProp
2928
);
3029
},
3130
);
32-
VMStatusConditionLabelList.displayName = 'VMStatusConditionLabelList';
31+
ConditionLabelList.displayName = 'ConditionLabelList';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Render VMStatusConditionLabelList 1`] = `
3+
exports[`Render ConditionLabelList 1`] = `
44
<DocumentFragment>
55
<div
66
class="pf-c-label-group"

0 commit comments

Comments
 (0)