Skip to content

Commit 2ba01e1

Browse files
[Metrics UI] Refactor With* containers to hooks (#59503) (#63494)
* [Metrics UI] Refactor containers to hooks * clean up depends; move useInterval out of useWaffleTime; * converting WithWaffleFilters to useWaffleFilters * Removing WithWaffleOptions * Refactor WithWaffleViewState to useWaffleViewState * Removing obsolete files * Fixing race condition with complext state * Adding undefined to RisonValue; unwinding changes trying to work around bad type * Switching to context * Change assertion to ignore the length of the current URL * Fixing test frameork to accept urls longer then 230 characters * Fixes #59395; Refactor WithMetricsTime to hook; Fixes brushing on metric detail page; fixes refresh button on metric detail page * Fixing tests with adding timeRange Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent de2099e commit 2ba01e1

File tree

87 files changed

+1087
-2149
lines changed

Some content is hidden

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

87 files changed

+1087
-2149
lines changed

test/functional/page_objects/common_page.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,25 +247,11 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
247247
}
248248

249249
currentUrl = (await browser.getCurrentUrl()).replace(/\/\/\w+:\w+@/, '//');
250-
const maxAdditionalLengthOnNavUrl = 230;
251-
252-
// On several test failures at the end of the TileMap test we try to navigate back to
253-
// Visualize so we can create the next Vertical Bar Chart, but we can see from the
254-
// logging and the screenshot that it's still on the TileMap page. Why didn't the "get"
255-
// with a new timestamped URL go? I thought that sleep(700) between the get and the
256-
// refresh would solve the problem but didn't seem to always work.
257-
// So this hack fails the navSuccessful check if the currentUrl doesn't match the
258-
// appUrl plus up to 230 other chars.
259-
// Navigating to Settings when there is a default index pattern has a URL length of 196
260-
// (from debug output). Some other tabs may also be long. But a rather simple configured
261-
// visualization is about 1000 chars long. So at least we catch that case.
262-
263-
// Browsers don't show the ':port' if it's 80 or 443 so we have to
264-
// remove that part so we can get a match in the tests.
265-
const navSuccessful = new RegExp(
266-
appUrl.replace(':80/', '/').replace(':443/', '/') +
267-
`.{0,${maxAdditionalLengthOnNavUrl}}$`
268-
).test(currentUrl);
250+
251+
const navSuccessful = currentUrl
252+
.replace(':80/', '/')
253+
.replace(':443/', '/')
254+
.startsWith(appUrl);
269255

270256
if (!navSuccessful) {
271257
const msg = `App failed to load: ${appName} in ${defaultFindTimeout}ms appUrl=${appUrl} currentUrl=${currentUrl}`;

test/typings/rison_node.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
declare module 'rison-node' {
21-
export type RisonValue = null | boolean | number | string | RisonObject | RisonArray;
21+
export type RisonValue = undefined | null | boolean | number | string | RisonObject | RisonArray;
2222

2323
// eslint-disable-next-line @typescript-eslint/no-empty-interface
2424
export interface RisonArray extends Array<RisonValue> {}

typings/rison_node.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
declare module 'rison-node' {
21-
export type RisonValue = null | boolean | number | string | RisonObject | RisonArray;
21+
export type RisonValue = undefined | null | boolean | number | string | RisonObject | RisonArray;
2222

2323
// eslint-disable-next-line @typescript-eslint/no-empty-interface
2424
export interface RisonArray extends Array<RisonValue> {}

x-pack/plugins/infra/common/http_api/metadata_api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const InfraMetadataRequestRT = rt.type({
1111
nodeId: rt.string,
1212
nodeType: ItemTypeRT,
1313
sourceId: rt.string,
14+
timeRange: rt.type({
15+
from: rt.number,
16+
to: rt.number,
17+
}),
1418
});
1519

1620
export const InfraMetadataFeatureRT = rt.type({

x-pack/plugins/infra/common/inventory_models/aws_ec2/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { withTheme } from '../../../../observability/public';
2020
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2121
import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details';
2222

23-
export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
23+
export const Layout = withTheme(({ metrics, theme, onChangeRangeTime }: LayoutPropsWithTheme) => (
2424
<React.Fragment>
2525
<MetadataDetails
2626
fields={[
@@ -42,6 +42,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
4242
}
4343
)}
4444
metrics={metrics}
45+
onChangeRangeTime={onChangeRangeTime}
4546
>
4647
<SubSection
4748
id="awsEC2CpuUtilization"

x-pack/plugins/infra/common/inventory_models/aws_rds/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { withTheme } from '../../../../observability/public';
1818
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1919
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';
2020

21-
export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
21+
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
2222
<React.Fragment>
2323
<LayoutContent>
2424
<Section
@@ -30,6 +30,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
3030
}
3131
)}
3232
metrics={metrics}
33+
onChangeRangeTime={onChangeRangeTime}
3334
>
3435
<SubSection
3536
id="awsRDSCpuTotal"

x-pack/plugins/infra/common/inventory_models/aws_s3/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { withTheme } from '../../../../observability/public';
1818
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1919
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';
2020

21-
export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
21+
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
2222
<React.Fragment>
2323
<LayoutContent>
2424
<Section
@@ -30,6 +30,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
3030
}
3131
)}
3232
metrics={metrics}
33+
onChangeRangeTime={onChangeRangeTime}
3334
>
3435
<SubSection
3536
id="awsS3BucketSize"

x-pack/plugins/infra/common/inventory_models/aws_sqs/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { withTheme } from '../../../../observability/public';
1818
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1919
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';
2020

21-
export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
21+
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
2222
<React.Fragment>
2323
<LayoutContent>
2424
<Section
@@ -30,6 +30,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
3030
}
3131
)}
3232
metrics={metrics}
33+
onChangeRangeTime={onChangeRangeTime}
3334
>
3435
<SubSection
3536
id="awsSQSMessagesVisible"

x-pack/plugins/infra/common/inventory_models/container/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { LayoutContent } from '../../../public/pages/metrics/components/layout_c
2222
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2323
import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details';
2424

25-
export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
25+
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
2626
<React.Fragment>
2727
<MetadataDetails />
2828
<LayoutContent>
@@ -40,6 +40,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
4040
}
4141
)}
4242
metrics={metrics}
43+
onChangeRangeTime={onChangeRangeTime}
4344
>
4445
<SubSection id="containerOverview">
4546
<GaugesSectionVis

x-pack/plugins/infra/common/inventory_models/host/layout.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { MetadataDetails } from '../../../public/pages/metrics/components/metada
2424
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2525
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';
2626

27-
export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
27+
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
2828
<React.Fragment>
2929
<MetadataDetails
3030
fields={[
@@ -52,6 +52,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
5252
}
5353
)}
5454
metrics={metrics}
55+
onChangeRangeTime={onChangeRangeTime}
5556
>
5657
<SubSection id="hostSystemOverview">
5758
<GaugesSectionVis
@@ -242,6 +243,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
242243
}
243244
)}
244245
metrics={metrics}
246+
onChangeRangeTime={onChangeRangeTime}
245247
>
246248
<SubSection id="hostK8sOverview">
247249
<GaugesSectionVis
@@ -371,8 +373,8 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
371373
/>
372374
</SubSection>
373375
</Section>
374-
<Aws.Layout metrics={metrics} />
375-
<Ngnix.Layout metrics={metrics} />
376+
<Aws.Layout metrics={metrics} onChangeRangeTime={onChangeRangeTime} />
377+
<Ngnix.Layout metrics={metrics} onChangeRangeTime={onChangeRangeTime} />
376378
</LayoutContent>
377379
</React.Fragment>
378380
));

0 commit comments

Comments
 (0)