Skip to content

Commit 8702480

Browse files
committed
feat(ver): update for react 19 support
1 parent 64c4864 commit 8702480

File tree

77 files changed

+333
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+333
-387
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"eslint:recommended",
1010
"plugin:@typescript-eslint/recommended",
1111
"plugin:react/recommended",
12+
"plugin:react/jsx-runtime",
1213
"plugin:react-hooks/recommended"
1314
],
1415
"parser": "@typescript-eslint/parser",

packages/dev/src/App.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
1+
import { createRoot } from 'react-dom';
32
import App from './AppContext';
43

54
it('renders without crashing', () => {
65
const div = document.createElement('div');
7-
ReactDOM.render(<App />, div);
8-
ReactDOM.unmountComponentAtNode(div);
6+
const root = createRoot(div);
7+
root.render(<App />);
8+
const root = createRoot(div);
9+
root.unmount();
910
});

packages/module/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
},
4747
"peerDependencies": {
4848
"@patternfly/react-core": "^6.0.0",
49-
"react": "^17 || ^18",
50-
"react-dom": "^17 || ^18",
49+
"react": "^17 || ^18 || ^19",
50+
"react-dom": "^17 || ^18 || ^19",
5151
"marked": "^15.0.6"
5252
},
5353
"dependencies": {
@@ -88,7 +88,6 @@
8888
"react-axe": "^3.5.4",
8989
"react-docgen-typescript-loader": "^3.7.2",
9090
"react-dom": "^18.2.0",
91-
"react-monaco-editor": "0.51.0",
9291
"regenerator-runtime": "^0.13.7",
9392
"rimraf": "^3.0.2",
9493
"rollup": "^2.79.2",

packages/module/src/ConsoleInternal/components/markdown-view.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { FC, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
22
import { css } from '@patternfly/react-styles';
33
import { marked } from 'marked';
44
import { useForceRender } from '@console/shared';
@@ -121,7 +121,7 @@ type InnerSyncMarkdownProps = Pick<SyncMarkdownProps, 'renderExtension' | 'exact
121121
className?: string;
122122
};
123123

124-
export const SyncMarkdownView: React.FC<SyncMarkdownProps> = ({
124+
export const SyncMarkdownView: FC<SyncMarkdownProps> = ({
125125
content,
126126
emptyMsg,
127127
extensions,
@@ -130,10 +130,10 @@ export const SyncMarkdownView: React.FC<SyncMarkdownProps> = ({
130130
inline,
131131
className,
132132
}) => {
133-
const { getResource } = React.useContext<QuickStartContextValues>(QuickStartContext);
134-
const [markup, setMarkup] = React.useState<string>('');
133+
const { getResource } = useContext<QuickStartContextValues>(QuickStartContext);
134+
const [markup, setMarkup] = useState<string>('');
135135

136-
React.useEffect(() => {
136+
useEffect(() => {
137137
async function getMd() {
138138
const md = await markdownConvert(
139139
content || emptyMsg || getResource('Not available'),
@@ -176,8 +176,8 @@ const RenderExtension: React.FC<RenderExtensionProps> = ({
176176
docContext,
177177
}) => {
178178
const forceRender = useForceRender();
179-
const markupRef = React.useRef<string>(null);
180-
const shouldRenderExtension = React.useCallback(() => {
179+
const markupRef = useRef<string>(null);
180+
const shouldRenderExtension = useCallback(() => {
181181
if (markupRef.current === markup) {
182182
return true;
183183
}
@@ -190,7 +190,7 @@ const RenderExtension: React.FC<RenderExtensionProps> = ({
190190
* which causes the component rendered by renderExtension to receive old copy of document
191191
* use forceRender to delay the rendering of extension by one render cycle
192192
*/
193-
React.useEffect(() => {
193+
useEffect(() => {
194194
if (renderExtension) {
195195
forceRender();
196196
}
@@ -201,13 +201,13 @@ const RenderExtension: React.FC<RenderExtensionProps> = ({
201201
);
202202
};
203203

204-
const InlineMarkdownView: React.FC<InnerSyncMarkdownProps> = ({
204+
const InlineMarkdownView: FC<InnerSyncMarkdownProps> = ({
205205
markup,
206206
isEmpty,
207207
renderExtension,
208208
className,
209209
}) => {
210-
const id = React.useMemo(() => uniqueId('markdown'), []);
210+
const id = useMemo(() => uniqueId('markdown'), []);
211211
return (
212212
<div className={css({ 'is-empty': isEmpty } as any, className)} id={id}>
213213
<div dangerouslySetInnerHTML={{ __html: markup }} />
@@ -218,18 +218,18 @@ const InlineMarkdownView: React.FC<InnerSyncMarkdownProps> = ({
218218
);
219219
};
220220

221-
const IFrameMarkdownView: React.FC<InnerSyncMarkdownProps> = ({
221+
const IFrameMarkdownView: FC<InnerSyncMarkdownProps> = ({
222222
exactHeight,
223223
markup,
224224
isEmpty,
225225
renderExtension,
226226
className,
227227
}) => {
228-
const [frame, setFrame] = React.useState<HTMLIFrameElement>();
229-
const [loaded, setLoaded] = React.useState(false);
230-
const updateTimeoutHandle = React.useRef<NodeJS.Timeout>();
228+
const [frame, setFrame] = useState<HTMLIFrameElement>();
229+
const [loaded, setLoaded] = useState(false);
230+
const updateTimeoutHandle = useRef<NodeJS.Timeout>(null);
231231

232-
const updateDimensions = React.useCallback(() => {
232+
const updateDimensions = useCallback(() => {
233233
if (!frame?.contentWindow?.document.body.firstChild) {
234234
return;
235235
}
@@ -248,14 +248,14 @@ const IFrameMarkdownView: React.FC<InnerSyncMarkdownProps> = ({
248248
});
249249
}, [frame, exactHeight]);
250250

251-
React.useEffect(
251+
useEffect(
252252
() => () => {
253253
clearTimeout(updateTimeoutHandle.current);
254254
},
255255
[],
256256
);
257257

258-
const onLoad = React.useCallback(() => {
258+
const onLoad = useCallback(() => {
259259
updateDimensions();
260260
setLoaded(true);
261261
}, [updateDimensions]);
@@ -302,7 +302,9 @@ const IFrameMarkdownView: React.FC<InnerSyncMarkdownProps> = ({
302302
sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin"
303303
srcDoc={contents}
304304
style={{ border: '0px', display: 'block', width: '100%', height: '0' }}
305-
ref={(r) => setFrame(r)}
305+
ref={(r) => {
306+
setFrame(r);
307+
}}
306308
onLoad={() => onLoad()}
307309
className={className}
308310
/>

packages/module/src/ConsoleInternal/components/utils/camel-case-wrap.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { Fragment } from 'react';
22

33
const MEMO = {};
44

@@ -16,10 +16,10 @@ export const CamelCaseWrap: React.FC<CamelCaseWrapProps> = ({ value, dataTest })
1616
const rendered = (
1717
<span data-test={dataTest}>
1818
{words.map((word, i) => (
19-
<React.Fragment key={i}>
19+
<Fragment key={i}>
2020
{word}
2121
{i !== words.length - 1 && <wbr />}
22-
</React.Fragment>
22+
</Fragment>
2323
))}
2424
</span>
2525
);

packages/module/src/ConsoleInternal/components/utils/status-box.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as React from 'react';
1+
import { FC, useContext } from 'react';
22
import { css } from '@patternfly/react-styles';
33
import { QuickStartContext, QuickStartContextValues } from '../../../utils/quick-start-context';
44

55
export const Box: React.FC<BoxProps> = ({ children, className }) => (
66
<div className={css('pfext-status-box', className)}>{children}</div>
77
);
88

9-
export const Loading: React.FC<LoadingProps> = ({ className }) => (
9+
export const Loading: FC<LoadingProps> = ({ className }) => (
1010
<div className={css('pfext-m-loader', className)}>
1111
<div className="pfext-m-loader-dot__one" />
1212
<div className="pfext-m-loader-dot__two" />
@@ -15,7 +15,7 @@ export const Loading: React.FC<LoadingProps> = ({ className }) => (
1515
);
1616
Loading.displayName = 'Loading';
1717

18-
export const LoadingBox: React.FC<LoadingBoxProps> = ({ className, message }) => (
18+
export const LoadingBox: FC<LoadingBoxProps> = ({ className, message }) => (
1919
<Box className={css('pfext-status-box--loading', className)}>
2020
<Loading />
2121
{message && <div className="pfext-status-box__loading-message">{message}</div>}
@@ -24,7 +24,7 @@ export const LoadingBox: React.FC<LoadingBoxProps> = ({ className, message }) =>
2424
LoadingBox.displayName = 'LoadingBox';
2525

2626
export const EmptyBox: React.FC<EmptyBoxProps> = ({ label }) => {
27-
const { getResource } = React.useContext<QuickStartContextValues>(QuickStartContext);
27+
const { getResource } = useContext<QuickStartContextValues>(QuickStartContext);
2828
return (
2929
<Box>
3030
<div data-test="empty-message" className="text-center">

packages/module/src/ConsoleShared/src/components/markdown-extensions/MarkdownCopyClipboard.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { FC, useCallback, useContext, useMemo, useState } from 'react';
22
import { Tooltip } from '@patternfly/react-core';
33
import { QuickStartContext, QuickStartContextValues } from '@quickstarts/utils/quick-start-context';
44
import { useEventListener } from '../../hooks';
@@ -10,14 +10,10 @@ interface CopyClipboardProps {
1010
docContext: Document;
1111
}
1212

13-
export const CopyClipboard: React.FC<CopyClipboardProps> = ({
14-
element,
15-
rootSelector,
16-
docContext,
17-
}) => {
18-
const { getResource } = React.useContext<QuickStartContextValues>(QuickStartContext);
19-
const [showSuccessContent, setShowSuccessContent] = React.useState<boolean>(false);
20-
const textToCopy = React.useMemo(() => {
13+
export const CopyClipboard: FC<CopyClipboardProps> = ({ element, rootSelector, docContext }) => {
14+
const { getResource } = useContext<QuickStartContextValues>(QuickStartContext);
15+
const [showSuccessContent, setShowSuccessContent] = useState<boolean>(false);
16+
const textToCopy = useMemo(() => {
2117
const copyTextId = element.getAttribute(MARKDOWN_COPY_BUTTON_ID);
2218
return (
2319
docContext.querySelector(
@@ -29,7 +25,7 @@ export const CopyClipboard: React.FC<CopyClipboardProps> = ({
2925
useEventListener(
3026
element,
3127
'click',
32-
React.useCallback(() => {
28+
useCallback(() => {
3329
navigator.clipboard
3430
.writeText(textToCopy.trim())
3531
.then(() => {
@@ -42,7 +38,7 @@ export const CopyClipboard: React.FC<CopyClipboardProps> = ({
4238
useEventListener(
4339
element,
4440
'mouseleave',
45-
React.useCallback(() => {
41+
useCallback(() => {
4642
setShowSuccessContent(false);
4743
}, []),
4844
);
@@ -70,10 +66,7 @@ interface MarkdownCopyClipboardProps {
7066
rootSelector: string;
7167
}
7268

73-
const MarkdownCopyClipboard: React.FC<MarkdownCopyClipboardProps> = ({
74-
docContext,
75-
rootSelector,
76-
}) => {
69+
const MarkdownCopyClipboard: FC<MarkdownCopyClipboardProps> = ({ docContext, rootSelector }) => {
7770
const elements = docContext.querySelectorAll(`${rootSelector} [${MARKDOWN_COPY_BUTTON_ID}]`);
7871
return elements.length > 0 ? (
7972
<>

packages/module/src/ConsoleShared/src/components/markdown-extensions/__tests__/MarkdownCopyClipboard.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { shallow } from 'enzyme';
32
import MarkdownCopyClipboard, { CopyClipboard } from '../MarkdownCopyClipboard';
43
import { htmlDocumentForCopyClipboard } from './test-data';

packages/module/src/ConsoleShared/src/components/markdown-extensions/accordion-extension.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { useMemo } from 'react';
22
import {
33
Accordion,
44
AccordionItem,
@@ -10,7 +10,7 @@ import { removeTemplateWhitespace } from './utils';
1010
import { ACCORDION_MARKDOWN_BUTTON_ID, ACCORDION_MARKDOWN_CONTENT_ID } from './const';
1111

1212
const useAccordionShowdownExtension = () =>
13-
React.useMemo(
13+
useMemo(
1414
() => ({
1515
type: 'lang',
1616
regex: /\[(.+)]{{(accordion) ("(.*?)")}}/g,

packages/module/src/ConsoleShared/src/components/markdown-extensions/accordion-render-extension.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { FC, useState } from 'react';
22
import { useEventListener } from '../../hooks';
33
import { ACCORDION_MARKDOWN_BUTTON_ID, ACCORDION_MARKDOWN_CONTENT_ID } from './const';
44

@@ -7,11 +7,11 @@ interface AccordionShowdownComponentProps {
77
contentElement: HTMLElement;
88
}
99

10-
const AccordionShowdownHandler: React.FC<AccordionShowdownComponentProps> = ({
10+
const AccordionShowdownHandler: FC<AccordionShowdownComponentProps> = ({
1111
buttonElement,
1212
contentElement,
1313
}) => {
14-
const [expanded, setExpanded] = React.useState<boolean>(false);
14+
const [expanded, setExpanded] = useState<boolean>(false);
1515

1616
const handleClick = () => {
1717
const expandedModifier = 'pf-m-expanded';
@@ -33,7 +33,7 @@ interface accordionRenderExtensionProps {
3333
docContext: Document;
3434
}
3535

36-
const AccordionRenderExtension: React.FC<accordionRenderExtensionProps> = ({ docContext }) => {
36+
const AccordionRenderExtension: FC<accordionRenderExtensionProps> = ({ docContext }) => {
3737
const buttonElements = docContext.querySelectorAll(`[id ^= ${ACCORDION_MARKDOWN_BUTTON_ID}]`);
3838
const contentElements = docContext.querySelectorAll(`[id ^= ${ACCORDION_MARKDOWN_CONTENT_ID}]`);
3939

0 commit comments

Comments
 (0)