Skip to content

Commit

Permalink
Fix conditional hook usage
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Dec 9, 2019
1 parent 24270c8 commit 13b7e90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ interface Props {
isAutoReloading: boolean;
refreshInterval: number;
sideNav: NavItem[];
metadata: InfraMetadata | null;
metadata: InfraMetadata;
addNavItem(item: NavItem): void;
setRefreshInterval(refreshInterval: number): void;
setAutoReload(isAutoReloading: boolean): void;
triggerRefresh(): void;
setTimeRange(timeRange: MetricsTimeInput): void;
}
export const NodeDetailsPage = (props: Props) => {
if (!props.metadata) {
return null;
}

const { parsedTimeRange } = props;
const { metrics, loading, makeRequest, error } = useNodeDetails(
props.requiredMetrics,
Expand All @@ -65,11 +61,11 @@ export const NodeDetailsPage = (props: Props) => {

const refetch = useCallback(() => {
makeRequest();
}, []);
}, [makeRequest]);

useEffect(() => {
makeRequest();
}, [parsedTimeRange]);
}, [makeRequest, parsedTimeRange]);

if (error) {
return <PageError error={error} name={props.name} />;
Expand Down
42 changes: 22 additions & 20 deletions x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,28 @@ export const MetricDetail = withMetricPageProviders(
})}
/>
<DetailPageContent data-test-subj="infraMetricsPage">
<NodeDetailsPage
name={name}
requiredMetrics={filteredRequiredMetrics}
sourceId={sourceId}
timeRange={timeRange}
parsedTimeRange={parsedTimeRange}
nodeType={nodeType}
nodeId={nodeId}
cloudId={cloudId}
metadataLoading={metadataLoading}
isAutoReloading={isAutoReloading}
refreshInterval={refreshInterval}
sideNav={sideNav}
metadata={metadata}
addNavItem={addNavItem}
setRefreshInterval={setRefreshInterval}
setAutoReload={setAutoReload}
triggerRefresh={triggerRefresh}
setTimeRange={setTimeRange}
/>
{metadata ? (
<NodeDetailsPage
name={name}
requiredMetrics={filteredRequiredMetrics}
sourceId={sourceId}
timeRange={timeRange}
parsedTimeRange={parsedTimeRange}
nodeType={nodeType}
nodeId={nodeId}
cloudId={cloudId}
metadataLoading={metadataLoading}
isAutoReloading={isAutoReloading}
refreshInterval={refreshInterval}
sideNav={sideNav}
metadata={metadata}
addNavItem={addNavItem}
setRefreshInterval={setRefreshInterval}
setAutoReload={setAutoReload}
triggerRefresh={triggerRefresh}
setTimeRange={setTimeRange}
/>
) : null}
</DetailPageContent>
</ColumnarPage>
)}
Expand Down

0 comments on commit 13b7e90

Please sign in to comment.