Skip to content

Commit 8ae3839

Browse files
authored
Doc new style (#16)
1 parent 79a685b commit 8ae3839

27 files changed

+499
-65
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@types/jest": "^27.4.0",
3434
"@types/jsdom": "^16.2.14",
3535
"@types/react": "^17.0.38",
36+
"@types/webpack-env": "^1.16.3",
3637
"@typescript-eslint/eslint-plugin": "^5.9.1",
3738
"@typescript-eslint/parser": "^5.9.1",
3839
"babel-jest": "^27.4.6",
@@ -77,6 +78,7 @@
7778
],
7879
"types": "dist/index.d.ts",
7980
"dependencies": {
80-
"@kubevirt-ui/kubevirt-api": "^0.0.30"
81+
"@kubevirt-ui/kubevirt-api": "^0.0.30",
82+
"classnames": "^2.3.1"
8183
}
8284
}

src/components/Button/Button.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/components/Button/Button.test.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/components/Button/Button.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/Button/__snapshots__/Button.test.tsx.snap

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Examples
2+
3+
```js
4+
<VMStatusConditionLabel
5+
message={'success'}
6+
reason={'ready'}
7+
status={'true'}
8+
type={'Ready'}
9+
/>
10+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react';
2+
3+
import { V1VirtualMachineCondition } from '@kubevirt-ui/kubevirt-api/kubevirt';
4+
import { Label, Popover, PopoverPosition } from '@patternfly/react-core';
5+
6+
export const VMStatusConditionLabel: React.FC<V1VirtualMachineCondition> = React.memo(
7+
(condition) => {
8+
const preventLabelLink = React.useCallback((e) => e.preventDefault(), []);
9+
10+
const getBodyContent = React.useCallback(
11+
() => <div>{condition?.message}</div>,
12+
[condition?.message],
13+
);
14+
15+
return (
16+
<Popover
17+
position={PopoverPosition.top}
18+
aria-label="Condition Popover"
19+
bodyContent={getBodyContent}
20+
>
21+
<Label color="grey" isTruncated href="#" onClick={preventLabelLink}>
22+
{condition?.reason}={condition?.status}
23+
</Label>
24+
</Popover>
25+
);
26+
},
27+
);
28+
VMStatusConditionLabel.displayName = 'VMStatusConditionLabel';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react';
2+
3+
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
4+
5+
import { VMStatusConditionLabel } from '../VMStatusConditionLabel';
6+
7+
import { conditionsMock } from './mocks';
8+
9+
afterEach(cleanup);
10+
11+
test('VMStatusConditionLabel', async () => {
12+
const { message, reason, status, type } = conditionsMock[0];
13+
const { asFragment, getByText } = render(
14+
<VMStatusConditionLabel message={message} reason={reason} status={status} type={type} />,
15+
);
16+
const firstRender = asFragment();
17+
18+
expect(firstRender).toMatchSnapshot();
19+
20+
// click on condition to open popover
21+
fireEvent.click(getByText(`${reason}=${status}`));
22+
23+
if (!message) return;
24+
25+
const popoverMessage = await screen.findByText(message);
26+
27+
expect(popoverMessage).toHaveTextContent(message);
28+
});
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[`VMStatusConditionLabel 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { V1VirtualMachineCondition } from '@kubevirt-ui/kubevirt-api/kubevirt';
2+
3+
export const conditionsMock: V1VirtualMachineCondition[] = [
4+
{
5+
message: 'no vmi found',
6+
reason: 'no_vmi',
7+
status: 'true',
8+
type: 'Failure',
9+
},
10+
{
11+
message: 'success',
12+
reason: 'ready',
13+
status: 'true',
14+
type: 'Ready',
15+
},
16+
];

0 commit comments

Comments
 (0)