From 11bc66a0e8b5a1bb0ce893665f0320088fab113d Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Wed, 8 Mar 2023 16:12:54 +0000 Subject: [PATCH] Chore: use `React.PropsWithChildren` to explicitly define the `children` prop (#64433) * use React.PropsWithChildren to explicitly define the children prop * fix ThemeDemo as well * provide empty generics --- .../src/components/ThemeDemos/ThemeDemo.tsx | 11 ++++++++--- .../components/SplitPaneWrapper/SplitPaneWrapper.tsx | 2 +- .../alerting/unified/components/PluginBridge.tsx | 9 +++++++-- .../features/alerting/unified/components/Strong.tsx | 6 ++++-- .../components/rule-editor/LabelsField.test.tsx | 2 +- .../query-and-alert-condition/AlertType.test.tsx | 2 +- .../unified/hooks/useAlertManagerSourceName.test.tsx | 12 ++++++------ .../unified/hooks/useExternalAMSelector.test.tsx | 12 ++++++------ .../unified/hooks/useIsRuleEditable.test.tsx | 2 +- 9 files changed, 35 insertions(+), 23 deletions(-) diff --git a/packages/grafana-ui/src/components/ThemeDemos/ThemeDemo.tsx b/packages/grafana-ui/src/components/ThemeDemos/ThemeDemo.tsx index d4b28d4f39c..03827b83006 100644 --- a/packages/grafana-ui/src/components/ThemeDemos/ThemeDemo.tsx +++ b/packages/grafana-ui/src/components/ThemeDemos/ThemeDemo.tsx @@ -1,5 +1,5 @@ import { css, cx } from '@emotion/css'; -import React, { FC, useState } from 'react'; +import React, { useState } from 'react'; import { GrafanaTheme2, ThemeRichColor } from '@grafana/data'; @@ -23,7 +23,7 @@ interface DemoBoxProps { textColor?: string; } -const DemoBox: FC = ({ bg, border, children }) => { +const DemoBox = ({ bg, border, children }: React.PropsWithChildren) => { const style = cx( css` padding: 16px; @@ -40,7 +40,12 @@ const DemoBox: FC = ({ bg, border, children }) => { return
{children}
; }; -const DemoText: FC<{ color?: string; bold?: boolean; size?: number }> = ({ color, bold, size, children }) => { +const DemoText = ({ + color, + bold, + size, + children, +}: React.PropsWithChildren<{ color?: string; bold?: boolean; size?: number }>) => { const style = css` padding: 4px; color: ${color ?? 'inherit'}; diff --git a/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx b/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx index dc8702752dd..bc7f3d13f91 100644 --- a/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx +++ b/public/app/core/components/SplitPaneWrapper/SplitPaneWrapper.tsx @@ -17,7 +17,7 @@ interface Props { secondaryPaneStyle?: React.CSSProperties; } -export class SplitPaneWrapper extends PureComponent { +export class SplitPaneWrapper extends PureComponent> { //requestAnimationFrame reference rafToken: MutableRefObject = createRef(); diff --git a/public/app/features/alerting/unified/components/PluginBridge.tsx b/public/app/features/alerting/unified/components/PluginBridge.tsx index 7003314e720..564231580f9 100644 --- a/public/app/features/alerting/unified/components/PluginBridge.tsx +++ b/public/app/features/alerting/unified/components/PluginBridge.tsx @@ -1,4 +1,4 @@ -import React, { FC, ReactElement } from 'react'; +import React, { ReactElement } from 'react'; import { usePluginBridge } from '../hooks/usePluginBridge'; import { SupportedPlugin } from '../types/pluginBridges'; @@ -13,7 +13,12 @@ export interface PluginBridgeProps { loadingComponent?: ReactElement; } -export const PluginBridge: FC = ({ children, plugin, loadingComponent, notInstalledFallback }) => { +export const PluginBridge = ({ + children, + plugin, + loadingComponent, + notInstalledFallback, +}: React.PropsWithChildren) => { const { loading, installed } = usePluginBridge(plugin); if (loading) { diff --git a/public/app/features/alerting/unified/components/Strong.tsx b/public/app/features/alerting/unified/components/Strong.tsx index 90a408819b7..99c6bcc42fc 100644 --- a/public/app/features/alerting/unified/components/Strong.tsx +++ b/public/app/features/alerting/unified/components/Strong.tsx @@ -1,8 +1,10 @@ -import React, { FC } from 'react'; +import React from 'react'; import { useTheme2 } from '@grafana/ui'; -const Strong: FC = ({ children }) => { +interface Props {} + +const Strong = ({ children }: React.PropsWithChildren) => { const theme = useTheme2(); return {children}; }; diff --git a/public/app/features/alerting/unified/components/rule-editor/LabelsField.test.tsx b/public/app/features/alerting/unified/components/rule-editor/LabelsField.test.tsx index 23d9e11ea18..2dd636d6187 100644 --- a/public/app/features/alerting/unified/components/rule-editor/LabelsField.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/LabelsField.test.tsx @@ -13,7 +13,7 @@ const labels = [ { key: 'key2', value: 'value2' }, ]; -const FormProviderWrapper: React.FC = ({ children }) => { +const FormProviderWrapper = ({ children }: React.PropsWithChildren<{}>) => { const methods = useForm({ defaultValues: { labels } }); return {children}; }; diff --git a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/AlertType.test.tsx b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/AlertType.test.tsx index 851e4dc79a8..dd1b173c071 100644 --- a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/AlertType.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/AlertType.test.tsx @@ -18,7 +18,7 @@ const ui = { }, }; -const FormProviderWrapper: React.FC = ({ children }) => { +const FormProviderWrapper = ({ children }: React.PropsWithChildren<{}>) => { const methods = useForm({}); return {children}; }; diff --git a/public/app/features/alerting/unified/hooks/useAlertManagerSourceName.test.tsx b/public/app/features/alerting/unified/hooks/useAlertManagerSourceName.test.tsx index aaf5a8a774c..95d8f4a29bf 100644 --- a/public/app/features/alerting/unified/hooks/useAlertManagerSourceName.test.tsx +++ b/public/app/features/alerting/unified/hooks/useAlertManagerSourceName.test.tsx @@ -27,7 +27,7 @@ const externalAmMimir: AlertManagerDataSource = { describe('useAlertManagerSourceName', () => { it('Should return undefined alert manager name when there are no available alert managers', () => { - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; const { result } = renderHook(() => useAlertManagerSourceName([]), { wrapper }); const [alertManager] = result.current; @@ -36,7 +36,7 @@ describe('useAlertManagerSourceName', () => { }); it('Should return Grafana AM when it is available and no alert manager query param exists', () => { - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; const availableAMs = [grafanaAm, externalAmProm, externalAmMimir]; const { result } = renderHook(() => useAlertManagerSourceName(availableAMs), { wrapper }); @@ -49,7 +49,7 @@ describe('useAlertManagerSourceName', () => { it('Should return alert manager included in the query param when available', () => { const history = createMemoryHistory(); history.push({ search: `alertmanager=${externalAmProm.name}` }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; const availableAMs = [grafanaAm, externalAmProm, externalAmMimir]; const { result } = renderHook(() => useAlertManagerSourceName(availableAMs), { wrapper }); @@ -62,7 +62,7 @@ describe('useAlertManagerSourceName', () => { it('Should return undefined if alert manager included in the query is not available', () => { const history = createMemoryHistory(); history.push({ search: `alertmanager=Not available external AM` }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; const availableAMs = [grafanaAm, externalAmProm, externalAmMimir]; @@ -74,7 +74,7 @@ describe('useAlertManagerSourceName', () => { }); it('Should return alert manager from store if available and query is empty', () => { - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; const availableAMs = [grafanaAm, externalAmProm, externalAmMimir]; store.set(ALERTMANAGER_NAME_LOCAL_STORAGE_KEY, externalAmProm.name); @@ -89,7 +89,7 @@ describe('useAlertManagerSourceName', () => { it('Should prioritize the alert manager from query over store', () => { const history = createMemoryHistory(); history.push({ search: `alertmanager=${externalAmProm.name}` }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; const availableAMs = [grafanaAm, externalAmProm, externalAmMimir]; store.set(ALERTMANAGER_NAME_LOCAL_STORAGE_KEY, externalAmMimir.name); diff --git a/public/app/features/alerting/unified/hooks/useExternalAMSelector.test.tsx b/public/app/features/alerting/unified/hooks/useExternalAMSelector.test.tsx index b5dc9e6a228..a18f8fe3c55 100644 --- a/public/app/features/alerting/unified/hooks/useExternalAMSelector.test.tsx +++ b/public/app/features/alerting/unified/hooks/useExternalAMSelector.test.tsx @@ -45,7 +45,7 @@ describe('useExternalDataSourceAlertmanagers', () => { mockAlertmanagersResponse(server, { data: { activeAlertManagers: [], droppedAlertManagers: [] } }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; // Act const { result, waitForNextUpdate } = renderHook(() => useExternalDataSourceAlertmanagers(), { wrapper }); @@ -78,7 +78,7 @@ describe('useExternalDataSourceAlertmanagers', () => { }, }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; // Act const { result, waitForValueToChange } = renderHook(() => useExternalDataSourceAlertmanagers(), { wrapper }); @@ -111,7 +111,7 @@ describe('useExternalDataSourceAlertmanagers', () => { }, }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; // Act const { result, waitForValueToChange } = renderHook(() => useExternalDataSourceAlertmanagers(), { wrapper }); @@ -144,7 +144,7 @@ describe('useExternalDataSourceAlertmanagers', () => { }, }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; // Act const { result, waitForNextUpdate } = renderHook(() => useExternalDataSourceAlertmanagers(), { wrapper }); @@ -177,7 +177,7 @@ describe('useExternalDataSourceAlertmanagers', () => { }, }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; // Act const { result, waitForValueToChange } = renderHook(() => useExternalDataSourceAlertmanagers(), { wrapper }); @@ -210,7 +210,7 @@ describe('useExternalDataSourceAlertmanagers', () => { state.dataSources.dataSources = [dsSettings]; }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; // Act const { result, waitForValueToChange } = renderHook(() => useExternalDataSourceAlertmanagers(), { diff --git a/public/app/features/alerting/unified/hooks/useIsRuleEditable.test.tsx b/public/app/features/alerting/unified/hooks/useIsRuleEditable.test.tsx index 369006b7026..ee0bf681b0c 100644 --- a/public/app/features/alerting/unified/hooks/useIsRuleEditable.test.tsx +++ b/public/app/features/alerting/unified/hooks/useIsRuleEditable.test.tsx @@ -173,7 +173,7 @@ function mockPermissions(grantedPermissions: AccessControlAction[]) { function getProviderWrapper() { const dataSources = getMockedDataSources(); const store = mockUnifiedAlertingStore({ dataSources }); - const wrapper: React.FC = ({ children }) => {children}; + const wrapper = ({ children }: React.PropsWithChildren<{}>) => {children}; return wrapper; }