Skip to content

Commit

Permalink
Consolidate react-hooks/exhaustive-deps lint rules for O11y
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Jun 5, 2024
1 parent c4dbcf8 commit 50be82f
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 101 deletions.
27 changes: 12 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,6 @@ module.exports = {
},
],
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
'react-hooks/exhaustive-deps': [
'error',
{ additionalHooks: '^(useFetcher|useProgressiveFetcher|useBreadcrumb)$' },
],
},
},
{
Expand All @@ -931,6 +927,18 @@ module.exports = {
],
},
},
{
files: ['x-pack/plugins/observability_solution/**/*.{ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': [
'error',
{
additionalHooks:
'^(useAbortableAsync|useMemoWithAbortSignal|useFetcher|useProgressiveFetcher|useBreadcrumb|useAsync|useTimeRangeAsync|useAutoAbortedHttpClient)$',
},
],
},
},
{
files: [
'x-pack/plugins/aiops/**/*.tsx',
Expand Down Expand Up @@ -964,17 +972,6 @@ module.exports = {
],
},
},
// Profiling
{
files: ['x-pack/plugins/observability_solution/profiling/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
'react-hooks/exhaustive-deps': [
'error',
{ additionalHooks: '^(useAsync|useTimeRangeAsync|useAutoAbortedHttpClient)$' },
],
},
},
{
// disable imports from legacy uptime plugin
files: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const HostCharts = React.forwardRef<HTMLDivElement, Props>(
const { charts } = useHostCharts({
metric,
dataViewId: dataView?.id,
options: { overview },
overview,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const KubernetesNodeCharts = React.forwardRef<HTMLDivElement, MetricsChar
({ assetId, dataView, dateRange, onShowAll, overview }, ref) => {
const { charts } = useKubernetesCharts({
dataViewId: dataView?.id,
options: { overview },
overview,
});

const hasIntegration = useIntegrationCheck({ dependsOn: INTEGRATIONS.kubernetesNode });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const ContainerKpiCharts = ({
dateRange,
dataView,
filters,
options,
query,
searchSessionId,
loading = false,
Expand All @@ -45,7 +44,6 @@ export const ContainerKpiCharts = ({
dateRange={dateRange}
dataView={dataView}
filters={filters}
options={options}
query={query}
searchSessionId={searchSessionId}
loading={loading}
Expand All @@ -55,7 +53,6 @@ export const ContainerKpiCharts = ({
dateRange={dateRange}
dataView={dataView}
filters={filters}
options={options}
query={query}
searchSessionId={searchSessionId}
loading={loading}
Expand All @@ -67,18 +64,14 @@ const DockerKpiCharts = ({
dateRange,
dataView,
filters,
options,
query,
searchSessionId,
loading = false,
}: ContainerKpiChartsProps) => {
const { euiTheme } = useEuiTheme();
const charts = useDockerContainerKpiCharts({
dataViewId: dataView?.id,
options: {
getSubtitle: options?.getSubtitle,
seriesColor: euiTheme.colors.lightestShade,
},
seriesColor: euiTheme.colors.lightestShade,
});

return (
Expand Down Expand Up @@ -111,10 +104,7 @@ const KubernetesKpiCharts = ({
const { euiTheme } = useEuiTheme();
const charts = useK8sContainerKpiCharts({
dataViewId: dataView?.id,
options: {
getSubtitle: options?.getSubtitle,
seriesColor: euiTheme.colors.lightestShade,
},
seriesColor: euiTheme.colors.lightestShade,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,24 @@ export interface HostKpiChartsProps {
query?: Query;
filters?: Filter[];
searchSessionId?: string;
options?: {
getSubtitle?: (formulaValue: string) => string;
};
getSubtitle?: (formulaValue: string) => string;
loading?: boolean;
}

export const HostKpiCharts = ({
dateRange,
dataView,
filters,
options,
getSubtitle,
query,
searchSessionId,
loading = false,
}: HostKpiChartsProps) => {
const { euiTheme } = useEuiTheme();
const charts = useHostKpiCharts({
dataViewId: dataView?.id,
options: {
getSubtitle: options?.getSubtitle,
seriesColor: euiTheme.colors.lightestShade,
},
getSubtitle,
seriesColor: euiTheme.colors.lightestShade,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useDockerContainerPageViewMetricsCharts = ({
}),
};
});
}, [metricsDataViewId]);
}, [metricsDataViewId, metric]);

return { charts, error };
};
Expand Down Expand Up @@ -76,7 +76,7 @@ export const useK8sContainerPageViewMetricsCharts = ({
}),
};
});
}, [metricsDataViewId]);
}, [metricsDataViewId, metric]);

return { charts, error };
};
Expand All @@ -97,10 +97,10 @@ const getK8sContainerCharts = async (metric: ContainerMetricTypes) => {

export const useDockerContainerKpiCharts = ({
dataViewId,
options,
seriesColor,
}: {
dataViewId?: string;
options?: { seriesColor: string; getSubtitle?: (formulaValue: string) => string };
seriesColor?: string;
}) => {
const { value: charts = [] } = useAsync(async () => {
const model = findInventoryModel('container');
Expand All @@ -109,27 +109,26 @@ export const useDockerContainerKpiCharts = ({
return [cpu.metric.dockerContainerCpuUsage, memory.metric.dockerContainerMemoryUsage].map(
(chart) => ({
...chart,
seriesColor: options?.seriesColor,
seriesColor,
decimals: 1,
subtitle: getSubtitle(options, chart),
...(dataViewId && {
dataset: {
index: dataViewId,
},
}),
})
);
}, [dataViewId, options?.seriesColor, options?.getSubtitle]);
}, [dataViewId, seriesColor]);

return charts;
};

export const useK8sContainerKpiCharts = ({
dataViewId,
options,
seriesColor,
}: {
dataViewId?: string;
options?: { seriesColor: string; getSubtitle?: (formulaValue: string) => string };
seriesColor?: string;
}) => {
const { value: charts = [] } = useAsync(async () => {
const model = findInventoryModel('container');
Expand All @@ -138,26 +137,21 @@ export const useK8sContainerKpiCharts = ({
return [cpu.metric.k8sContainerCpuUsage, memory.metric.k8sContainerMemoryUsage].map(
(chart) => ({
...chart,
seriesColor: options?.seriesColor,
seriesColor,
decimals: 1,
subtitle: getSubtitle(options, chart),
subtitle: getSubtitle(chart),
...(dataViewId && {
dataset: {
index: dataViewId,
},
}),
})
);
}, [dataViewId, options?.seriesColor, options?.getSubtitle]);
}, [dataViewId, seriesColor]);

return charts;
};

function getSubtitle(
options: { getSubtitle?: ((formulaValue: string) => string) | undefined } | undefined,
chart: { value: string }
) {
return options?.getSubtitle
? options?.getSubtitle(chart.value)
: getSubtitleFromFormula(chart.value);
function getSubtitle(chart: { value: string }) {
return getSubtitleFromFormula(chart.value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const useDataViews = () => {

const { value: logsDataView, loading: logsDataViewLoading } = useAsync(
() => getLogsDataView(logViewReference),
[logViewReference]
[logViewReference, getLogsDataView]
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('useHostCharts', () => {
const expectedOrder = getHostChartsExpectedOrder(metric, true);

const { result, waitForNextUpdate } = renderHook(() =>
useHostCharts({ dataViewId, metric, options: { overview: true } })
useHostCharts({ dataViewId, metric, overview: true })
);
await waitForNextUpdate();

Expand All @@ -81,7 +81,7 @@ describe('useHostCharts', () => {
describe('useKubernetesCharts', () => {
it('should return an array of charts with correct order - overview', async () => {
const { result, waitForNextUpdate } = renderHook(() =>
useKubernetesCharts({ dataViewId, options: { overview: true } })
useKubernetesCharts({ dataViewId, overview: true })
);
await waitForNextUpdate();

Expand Down Expand Up @@ -141,7 +141,7 @@ describe('useHostKpiCharts', () => {
};

const { result, waitForNextUpdate } = renderHook(() =>
useHostKpiCharts({ dataViewId, options })
useHostKpiCharts({ dataViewId, ...options })
);
await waitForNextUpdate();

Expand Down
Loading

0 comments on commit 50be82f

Please sign in to comment.