Skip to content

Commit 2b79711

Browse files
Merge pull request #502 from zhuje/ou-848-jsx-pr2
OU-849: upgrade jsx pre-procesor to "react-jsx"
2 parents bf09741 + 77295f6 commit 2b79711

File tree

82 files changed

+524
-539
lines changed

Some content is hidden

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

82 files changed

+524
-539
lines changed

web/.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extends:
66
- plugin:react/recommended
77
- plugin:react-hooks/recommended
88
- plugin:@typescript-eslint/recommended
9+
- plugin:react/jsx-runtime
910
- prettier
1011
parser: '@typescript-eslint/parser'
1112
parserOptions:

web/cypress/dummy.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as React from 'react';
2-
31
export {
42
ActionServiceProvider,
53
BlueInfoCircleIcon,

web/src/components/Incidents/AlertsChart/AlertsChart.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { useState, useMemo, useEffect, useRef, useCallback } from 'react';
22

33
import {
44
Chart,
@@ -25,8 +25,8 @@ import { VictoryPortal } from 'victory';
2525

2626
const AlertsChart = ({ chartDays, theme }: { chartDays: number; theme: 'light' | 'dark' }) => {
2727
const dispatch = useDispatch();
28-
const [chartContainerHeight, setChartContainerHeight] = React.useState<number>();
29-
const [chartHeight, setChartHeight] = React.useState<number>();
28+
const [chartContainerHeight, setChartContainerHeight] = useState<number>();
29+
const [chartHeight, setChartHeight] = useState<number>();
3030
const alertsData = useSelector((state: MonitoringState) =>
3131
state.plugins.mcp.getIn(['incidentsData', 'alertsData']),
3232
);
@@ -40,34 +40,34 @@ const AlertsChart = ({ chartDays, theme }: { chartDays: number; theme: 'light' |
4040
state.plugins.mcp.getIn(['incidentsData', 'groupId']),
4141
);
4242

43-
const dateValues = React.useMemo(() => generateDateArray(chartDays), [chartDays]);
43+
const dateValues = useMemo(() => generateDateArray(chartDays), [chartDays]);
4444

45-
const chartData = React.useMemo(() => {
45+
const chartData = useMemo(() => {
4646
if (!Array.isArray(alertsData) || alertsData.length === 0) return [];
4747
return alertsData.map((alert) => createAlertsChartBars(alert, dateValues));
4848
}, [alertsData, dateValues]);
4949

50-
React.useEffect(() => {
50+
useEffect(() => {
5151
setChartContainerHeight(chartData?.length < 5 ? 300 : chartData?.length * 60);
5252
setChartHeight(chartData?.length < 5 ? 250 : chartData?.length * 55);
5353
}, [chartData]);
5454

55-
const selectedIncidentIsVisible = React.useMemo(() => {
55+
const selectedIncidentIsVisible = useMemo(() => {
5656
return filteredData.some((incident) => incident.group_id === incidentGroupId);
5757
}, [filteredData, incidentGroupId]);
5858

59-
React.useEffect(() => {
59+
useEffect(() => {
6060
dispatch(setAlertsAreLoading({ alertsAreLoading: !selectedIncidentIsVisible }));
6161
}, [dispatch, selectedIncidentIsVisible]);
6262

63-
const [width, setWidth] = React.useState(0);
64-
const containerRef = React.useRef(null);
65-
const handleResize = React.useCallback(() => {
63+
const [width, setWidth] = useState(0);
64+
const containerRef = useRef(null);
65+
const handleResize = useCallback(() => {
6666
if (containerRef.current && containerRef.current.clientWidth) {
6767
setWidth(containerRef.current.clientWidth);
6868
}
6969
}, []);
70-
React.useEffect(() => {
70+
useEffect(() => {
7171
const observer = getResizeObserver(containerRef.current, handleResize);
7272
handleResize();
7373
return () => observer();

web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { useState, useMemo, useEffect, useRef, useCallback } from 'react';
22

33
import {
44
Chart,
@@ -46,34 +46,34 @@ const IncidentsChart = ({
4646
theme: 'light' | 'dark';
4747
}) => {
4848
const dispatch = useDispatch();
49-
const [isLoading, setIsLoading] = React.useState(true);
50-
const [chartContainerHeight, setChartContainerHeight] = React.useState<number>();
51-
const [chartHeight, setChartHeight] = React.useState<number>();
52-
const dateValues = React.useMemo(() => generateDateArray(chartDays), [chartDays]);
49+
const [isLoading, setIsLoading] = useState(true);
50+
const [chartContainerHeight, setChartContainerHeight] = useState<number>();
51+
const [chartHeight, setChartHeight] = useState<number>();
52+
const dateValues = useMemo(() => generateDateArray(chartDays), [chartDays]);
5353

54-
const chartData = React.useMemo(() => {
54+
const chartData = useMemo(() => {
5555
if (!Array.isArray(incidentsData) || incidentsData.length === 0) return [];
5656
return incidentsData.map((incident) => createIncidentsChartBars(incident, dateValues));
5757
}, [incidentsData, dateValues]);
5858

59-
React.useEffect(() => {
59+
useEffect(() => {
6060
setIsLoading(false);
6161
}, [incidentsData]);
6262

63-
React.useEffect(() => {
63+
useEffect(() => {
6464
setChartContainerHeight(chartData?.length < 5 ? 300 : chartData?.length * 60);
6565
setChartHeight(chartData?.length < 5 ? 250 : chartData?.length * 55);
6666
}, [chartData]);
6767

68-
const [width, setWidth] = React.useState(0);
69-
const containerRef = React.useRef(null);
68+
const [width, setWidth] = useState(0);
69+
const containerRef = useRef(null);
7070

7171
const handleResize = () => {
7272
if (containerRef.current && containerRef.current.clientWidth) {
7373
setWidth(containerRef.current.clientWidth);
7474
}
7575
};
76-
React.useEffect(() => {
76+
useEffect(() => {
7777
const observer = getResizeObserver(containerRef.current, handleResize);
7878
handleResize();
7979
return () => observer();
@@ -86,7 +86,7 @@ const IncidentsChart = ({
8686
state.plugins.mcp.getIn(['incidentsData', 'incidentsActiveFilters']),
8787
);
8888

89-
const isHidden = React.useCallback(
89+
const isHidden = useCallback(
9090
(group_id) => selectedId !== '' && selectedId !== group_id,
9191
[selectedId],
9292
);
@@ -109,7 +109,7 @@ const IncidentsChart = ({
109109
}
110110
};
111111

112-
const getOpacity = React.useCallback(
112+
const getOpacity = useCallback(
113113
(datum) => (datum.fillOpacity = isHidden(datum.group_id) ? '0.3' : '1'),
114114
[isHidden],
115115
);

web/src/components/Incidents/IncidentsDetailsRowTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import { useRef, useState, useEffect } from 'react';
22
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
33
import {
44
GreenCheckCircleIcon,
@@ -28,7 +28,7 @@ import isEqual from 'lodash/isEqual';
2828
import { MonitoringState } from 'src/reducers/observe';
2929

3030
function useDeepCompareMemoize(value) {
31-
const ref = React.useRef();
31+
const ref = useRef();
3232

3333
if (!isEqual(value, ref.current)) {
3434
ref.current = value;
@@ -42,7 +42,7 @@ const IncidentsDetailsRowTable = ({ alerts }) => {
4242
const [namespace] = useActiveNamespace();
4343
useAlertsPoller();
4444
const { perspective, alertsKey } = usePerspective();
45-
const [alertsWithMatchedData, setAlertsWithMatchedData] = React.useState([]);
45+
const [alertsWithMatchedData, setAlertsWithMatchedData] = useState([]);
4646
const { t } = useTranslation(process.env.I18N_NAMESPACE);
4747

4848
const alertsWithLabels = useSelector((state: MonitoringState) =>
@@ -63,7 +63,7 @@ const IncidentsDetailsRowTable = ({ alerts }) => {
6363
}
6464
const memoizedAlerts = useDeepCompareMemoize(alerts);
6565

66-
React.useEffect(() => {
66+
useEffect(() => {
6767
setAlertsWithMatchedData(findMatchingAlertsWithId(memoizedAlerts, alertsWithLabels));
6868
}, [memoizedAlerts, alertsWithLabels]);
6969

web/src/components/Incidents/IncidentsPage.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react-hooks/exhaustive-deps */
2-
import * as React from 'react';
2+
import { useMemo, useState, useEffect } from 'react';
33
import { useSafeFetch } from '../console/utils/safe-fetch-hook';
44
import { createAlertsQuery, fetchDataForIncidentsAndAlerts } from './api';
55
import { useTranslation } from 'react-i18next';
@@ -63,24 +63,24 @@ const IncidentsPage = () => {
6363
const { t } = useTranslation(process.env.I18N_NAMESPACE);
6464
const dispatch = useDispatch();
6565
const location = useLocation();
66-
const urlParams = React.useMemo(() => parseUrlParams(location.search), [location.search]);
66+
const urlParams = useMemo(() => parseUrlParams(location.search), [location.search]);
6767
const { perspective } = usePerspective();
6868
const { theme } = usePatternFlyTheme();
6969
// loading states
70-
const [incidentsAreLoading, setIncidentsAreLoading] = React.useState(true);
70+
const [incidentsAreLoading, setIncidentsAreLoading] = useState(true);
7171
// days span is where we store the value for creating time ranges for
7272
// fetch incidents/alerts based on the length of time ranges
7373
// when days filter changes we set a new days span -> calculate new time range and fetch new data
74-
const [daysSpan, setDaysSpan] = React.useState<number>();
75-
const [timeRanges, setTimeRanges] = React.useState([]);
74+
const [daysSpan, setDaysSpan] = useState<number>();
75+
const [timeRanges, setTimeRanges] = useState([]);
7676
// data that is used for processing to serve it to the alerts table and chart
77-
const [incidentForAlertProcessing, setIncidentForAlertProcessing] = React.useState<
77+
const [incidentForAlertProcessing, setIncidentForAlertProcessing] = useState<
7878
Array<Partial<Incident>>
7979
>([]);
80-
const [hideCharts, setHideCharts] = React.useState(false);
80+
const [hideCharts, setHideCharts] = useState(false);
8181

82-
const [incidentFilterIsExpanded, setIncidentIsExpanded] = React.useState(false);
83-
const [daysFilterIsExpanded, setDaysFilterIsExpanded] = React.useState(false);
82+
const [incidentFilterIsExpanded, setIncidentIsExpanded] = useState(false);
83+
const [daysFilterIsExpanded, setDaysFilterIsExpanded] = useState(false);
8484

8585
const onIncidentFilterToggle = (ev) => {
8686
ev.stopPropagation();
@@ -115,7 +115,7 @@ const IncidentsPage = () => {
115115
const filteredData = useSelector((state: MonitoringState) =>
116116
state.plugins.mcp.getIn(['incidentsData', 'filteredIncidentsData']),
117117
);
118-
React.useEffect(() => {
118+
useEffect(() => {
119119
const hasUrlParams = Object.keys(urlParams).length > 0;
120120
if (hasUrlParams) {
121121
// If URL parameters exist, update incidentsActiveFilters based on them
@@ -147,11 +147,11 @@ const IncidentsPage = () => {
147147
}
148148
}, []);
149149

150-
React.useEffect(() => {
150+
useEffect(() => {
151151
updateBrowserUrl(incidentsActiveFilters, incidentGroupId);
152152
}, [incidentsActiveFilters]);
153153

154-
React.useEffect(() => {
154+
useEffect(() => {
155155
dispatch(
156156
setFilteredIncidentsData({
157157
filteredIncidentsData: filterIncident(incidentsActiveFilters, incidents),
@@ -163,11 +163,11 @@ const IncidentsPage = () => {
163163
const safeFetch = useSafeFetch();
164164
const title = t('Incidents');
165165

166-
React.useEffect(() => {
166+
useEffect(() => {
167167
setTimeRanges(getIncidentsTimeRanges(daysSpan, now));
168168
}, [daysSpan]);
169169

170-
React.useEffect(() => {
170+
useEffect(() => {
171171
setDaysSpan(
172172
parsePrometheusDuration(
173173
incidentsActiveFilters.days.length > 0
@@ -177,7 +177,7 @@ const IncidentsPage = () => {
177177
);
178178
}, [incidentsActiveFilters.days]);
179179

180-
React.useEffect(() => {
180+
useEffect(() => {
181181
(async () => {
182182
Promise.all(
183183
timeRanges.map(async (range) => {
@@ -206,15 +206,15 @@ const IncidentsPage = () => {
206206
})();
207207
}, [incidentForAlertProcessing]);
208208

209-
React.useEffect(() => {
209+
useEffect(() => {
210210
dispatch(
211211
setAlertsTableData({
212212
alertsTableData: groupAlertsForTable(alertsData),
213213
}),
214214
);
215215
}, [alertsData]);
216216

217-
React.useEffect(() => {
217+
useEffect(() => {
218218
(async () => {
219219
Promise.all(
220220
timeRanges.map(async (range) => {
@@ -251,7 +251,7 @@ const IncidentsPage = () => {
251251
})();
252252
}, [timeRanges]);
253253

254-
React.useEffect(() => {
254+
useEffect(() => {
255255
if (incidentGroupId) {
256256
Promise.all(
257257
timeRanges.map(async (range) => {

web/src/components/Incidents/IncidentsTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Bullseye, Card, CardBody, EmptyState, EmptyStateBody } from '@patternfl
33
import { SearchIcon } from '@patternfly/react-icons';
44
import { ExpandableRowContent, Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
55
import * as _ from 'lodash-es';
6-
import React from 'react';
6+
import { useState } from 'react';
77
import { useSelector } from 'react-redux';
88
import { MonitoringState } from 'src/reducers/observe';
99
import { AlertStateIcon, SeverityBadge } from '../alerting/AlertUtils';
@@ -17,7 +17,7 @@ export const IncidentsTable = () => {
1717
severity: 'Severity',
1818
state: 'State',
1919
};
20-
const [expandedAlerts, setExpandedAlerts] = React.useState([]);
20+
const [expandedAlerts, setExpandedAlerts] = useState([]);
2121
const setAlertExpanded = (alert: Alert, isExpanding = true) =>
2222
setExpandedAlerts((prevExpanded) => {
2323
const otherAlertExpanded = prevExpanded.filter((r) => r !== alert.component);

0 commit comments

Comments
 (0)