Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metrics UI] Refactor With* containers to hooks #59503

Merged
merged 27 commits into from Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b1bdb90
[Metrics UI] Refactor containers to hooks
simianhacker Mar 2, 2020
9f60ea5
clean up depends; move useInterval out of useWaffleTime;
simianhacker Mar 2, 2020
d5dcec1
converting WithWaffleFilters to useWaffleFilters
simianhacker Mar 4, 2020
c963028
Removing WithWaffleOptions
simianhacker Mar 5, 2020
3c82d0a
Refactor WithWaffleViewState to useWaffleViewState
simianhacker Mar 5, 2020
cb7f13f
Removing obsolete files
simianhacker Mar 6, 2020
fd1452a
Fixing race condition with complext state
simianhacker Mar 6, 2020
c1a8713
Adding undefined to RisonValue; unwinding changes trying to work arou…
simianhacker Mar 6, 2020
b64a837
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 6, 2020
2b5c7ea
Switching to context
simianhacker Mar 6, 2020
03a1e5f
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 6, 2020
1814b28
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 9, 2020
83297b2
Change assertion to ignore the length of the current URL
simianhacker Mar 9, 2020
11e9853
Fixing test frameork to accept urls longer then 230 characters
simianhacker Mar 9, 2020
3f5d6e1
Fixes #59395; Refactor WithMetricsTime to hook; Fixes brushing on met…
simianhacker Mar 9, 2020
57eb9e2
Fixing tests with adding timeRange
simianhacker Mar 10, 2020
c2d8345
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 10, 2020
178ae1a
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 12, 2020
049b767
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 13, 2020
f39feee
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 17, 2020
1fac263
Merge branch 'master' into refactor-containers
elasticmachine Mar 22, 2020
d565f9b
Merge branch 'master' of github.com:elastic/kibana into refactor-cont…
simianhacker Mar 25, 2020
d038e88
Merge branch 'master' into refactor-containers
elasticmachine Mar 30, 2020
29572d1
Merge branch 'master' into refactor-containers
elasticmachine Apr 1, 2020
00d24d9
Merge branch 'master' into refactor-containers
elasticmachine Apr 8, 2020
1ba5834
Merge branch 'master' into refactor-containers
elasticmachine Apr 9, 2020
128be61
Merge branch 'master' into refactor-containers
elasticmachine Apr 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 5 additions & 19 deletions test/functional/page_objects/common_page.ts
Expand Up @@ -287,25 +287,11 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's up with the changes in this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is was a test specific hack that Spencer is going to be cleaning up.


currentUrl = (await browser.getCurrentUrl()).replace(/\/\/\w+:\w+@/, '//');
const maxAdditionalLengthOnNavUrl = 230;

// On several test failures at the end of the TileMap test we try to navigate back to
// Visualize so we can create the next Vertical Bar Chart, but we can see from the
// logging and the screenshot that it's still on the TileMap page. Why didn't the "get"
// with a new timestamped URL go? I thought that sleep(700) between the get and the
// refresh would solve the problem but didn't seem to always work.
// So this hack fails the navSuccessful check if the currentUrl doesn't match the
// appUrl plus up to 230 other chars.
// Navigating to Settings when there is a default index pattern has a URL length of 196
// (from debug output). Some other tabs may also be long. But a rather simple configured
// visualization is about 1000 chars long. So at least we catch that case.

// Browsers don't show the ':port' if it's 80 or 443 so we have to
// remove that part so we can get a match in the tests.
const navSuccessful = new RegExp(
appUrl.replace(':80/', '/').replace(':443/', '/') +
`.{0,${maxAdditionalLengthOnNavUrl}}$`
).test(currentUrl);

const navSuccessful = currentUrl
.replace(':80/', '/')
.replace(':443/', '/')
.startsWith(appUrl);

if (!navSuccessful) {
const msg = `App failed to load: ${appName} in ${defaultFindTimeout}ms appUrl=${appUrl} currentUrl=${currentUrl}`;
Expand Down
2 changes: 1 addition & 1 deletion test/typings/rison_node.d.ts
Expand Up @@ -18,7 +18,7 @@
*/

declare module 'rison-node' {
export type RisonValue = null | boolean | number | string | RisonObject | RisonArray;
export type RisonValue = undefined | null | boolean | number | string | RisonObject | RisonArray;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh rison

How was this wrong before, do you understand what happened? Or is this just rison-whack-a-mole :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rison-whack-a-mole ... undefined is totally valid for Rison values, whoever setup this up just never had a type with option values being set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I feel like we've edited various versions of this file in various places in Kibana at least 4-5 times since I started, let's just keep whacking this mole for now! 🔨 🔨 🔨


// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RisonArray extends Array<RisonValue> {}
Expand Down
2 changes: 1 addition & 1 deletion typings/rison_node.d.ts
Expand Up @@ -18,7 +18,7 @@
*/

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

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RisonArray extends Array<RisonValue> {}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/infra/common/http_api/metadata_api.ts
Expand Up @@ -11,6 +11,10 @@ export const InfraMetadataRequestRT = rt.type({
nodeId: rt.string,
nodeType: ItemTypeRT,
sourceId: rt.string,
timeRange: rt.type({
from: rt.number,
to: rt.number,
}),
});

export const InfraMetadataFeatureRT = rt.type({
Expand Down
Expand Up @@ -20,7 +20,7 @@ import { withTheme } from '../../../../observability/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, theme, onChangeRangeTime }: LayoutPropsWithTheme) => (
<React.Fragment>
<MetadataDetails
fields={[
Expand All @@ -42,6 +42,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection
id="awsEC2CpuUtilization"
Expand Down
Expand Up @@ -18,7 +18,7 @@ import { withTheme } from '../../../../observability/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<LayoutContent>
<Section
Expand All @@ -30,6 +30,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection
id="awsRDSCpuTotal"
Expand Down
Expand Up @@ -18,7 +18,7 @@ import { withTheme } from '../../../../observability/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<LayoutContent>
<Section
Expand All @@ -30,6 +30,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection
id="awsS3BucketSize"
Expand Down
Expand Up @@ -18,7 +18,7 @@ import { withTheme } from '../../../../observability/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<LayoutContent>
<Section
Expand All @@ -30,6 +30,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection
id="awsSQSMessagesVisible"
Expand Down
Expand Up @@ -22,7 +22,7 @@ import { LayoutContent } from '../../../public/pages/metrics/components/layout_c
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { MetadataDetails } from '../../../public/pages/metrics/components/metadata_details';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<MetadataDetails />
<LayoutContent>
Expand All @@ -40,6 +40,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection id="containerOverview">
<GaugesSectionVis
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/infra/common/inventory_models/host/layout.tsx
Expand Up @@ -24,7 +24,7 @@ import { MetadataDetails } from '../../../public/pages/metrics/components/metada
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<MetadataDetails
fields={[
Expand Down Expand Up @@ -52,6 +52,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection id="hostSystemOverview">
<GaugesSectionVis
Expand Down Expand Up @@ -242,6 +243,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection id="hostK8sOverview">
<GaugesSectionVis
Expand Down Expand Up @@ -371,8 +373,8 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
/>
</SubSection>
</Section>
<Aws.Layout metrics={metrics} />
<Ngnix.Layout metrics={metrics} />
<Aws.Layout metrics={metrics} onChangeRangeTime={onChangeRangeTime} />
<Ngnix.Layout metrics={metrics} onChangeRangeTime={onChangeRangeTime} />
</LayoutContent>
</React.Fragment>
));
5 changes: 3 additions & 2 deletions x-pack/plugins/infra/common/inventory_models/pod/layout.tsx
Expand Up @@ -23,7 +23,7 @@ import { MetadataDetails } from '../../../public/pages/metrics/components/metada
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LayoutContent } from '../../../public/pages/metrics/components/layout_content';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<MetadataDetails />
<LayoutContent>
Expand All @@ -38,6 +38,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection id="podOverview">
<GaugesSectionVis
Expand Down Expand Up @@ -161,7 +162,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
/>
</SubSection>
</Section>
<Nginx.Layout metrics={metrics} />
<Nginx.Layout metrics={metrics} onChangeRangeTime={onChangeRangeTime} />
</LayoutContent>
</React.Fragment>
));
Expand Up @@ -18,7 +18,7 @@ import { ChartSectionVis } from '../../../../public/pages/metrics/components/cha
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { withTheme } from '../../../../../observability/public';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<Section
navLabel="AWS"
Expand All @@ -29,6 +29,7 @@ export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
}
)}
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection id="awsOverview">
<GaugesSectionVis
Expand Down
Expand Up @@ -16,9 +16,14 @@ import { ChartSectionVis } from '../../../../public/pages/metrics/components/cha
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { withTheme } from '../../../../../observability/public';

export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
export const Layout = withTheme(({ metrics, onChangeRangeTime, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<Section navLabel="Nginx" sectionLabel="Nginx" metrics={metrics}>
<Section
navLabel="Nginx"
sectionLabel="Nginx"
metrics={metrics}
onChangeRangeTime={onChangeRangeTime}
>
<SubSection
id="nginxHits"
label={i18n.translate(
Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/infra/common/saved_objects/inventory_view.ts
Expand Up @@ -7,7 +7,7 @@
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ElasticsearchMappingOf } from '../../server/utils/typed_elasticsearch_mappings';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { WaffleViewState } from '../../public/containers/waffle/with_waffle_view_state';
import { WaffleViewState } from '../../public/pages/inventory_view/hooks/use_waffle_view_state';

export const inventoryViewSavedObjectType = 'inventory-view';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand Down Expand Up @@ -102,7 +102,7 @@ export const inventoryViewSavedObjectMappings: {
type: 'boolean',
},
time: {
type: 'integer',
type: 'long',
},
autoReload: {
type: 'boolean',
Expand All @@ -117,6 +117,12 @@ export const inventoryViewSavedObjectMappings: {
},
},
},
accountId: {
type: 'keyword',
},
region: {
type: 'keyword',
},
},
},
};
33 changes: 9 additions & 24 deletions x-pack/plugins/infra/public/apps/start_app.tsx
Expand Up @@ -8,18 +8,13 @@ import { createBrowserHistory } from 'history';
import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloProvider } from 'react-apollo';
import { Provider as ReduxStoreProvider } from 'react-redux';
import { BehaviorSubject } from 'rxjs';
import { pluck } from 'rxjs/operators';
import { CoreStart, AppMountParameters } from 'kibana/public';

// TODO use theme provided from parentApp when kibana supports it
import { EuiErrorBoundary } from '@elastic/eui';
import { EuiThemeProvider } from '../../../observability/public';
import { InfraFrontendLibs } from '../lib/lib';
import { createStore } from '../store';
import { ApolloClientContext } from '../utils/apollo_context';
import { ReduxStateContextProvider } from '../utils/redux_context';
import { HistoryContext } from '../utils/history_context';
import {
useUiSetting$,
Expand All @@ -39,31 +34,21 @@ export async function startApp(
) {
const { element, appBasePath } = params;
const history = createBrowserHistory({ basename: appBasePath });
const libs$ = new BehaviorSubject(libs);
const store = createStore({
apolloClient: libs$.pipe(pluck('apolloClient')),
observableApi: libs$.pipe(pluck('observableApi')),
});

const InfraPluginRoot: React.FunctionComponent = () => {
const [darkMode] = useUiSetting$<boolean>('theme:darkMode');

return (
<core.i18n.Context>
<EuiErrorBoundary>
<ReduxStoreProvider store={store}>
<ReduxStateContextProvider>
<ApolloProvider client={libs.apolloClient}>
<ApolloClientContext.Provider value={libs.apolloClient}>
<EuiThemeProvider darkMode={darkMode}>
<HistoryContext.Provider value={history}>
<Router history={history} />
</HistoryContext.Provider>
</EuiThemeProvider>
</ApolloClientContext.Provider>
</ApolloProvider>
</ReduxStateContextProvider>
</ReduxStoreProvider>
<ApolloProvider client={libs.apolloClient}>
<ApolloClientContext.Provider value={libs.apolloClient}>
<EuiThemeProvider darkMode={darkMode}>
<HistoryContext.Provider value={history}>
<Router history={history} />
</HistoryContext.Provider>
</EuiThemeProvider>
</ApolloClientContext.Provider>
</ApolloProvider>
</EuiErrorBoundary>
</core.i18n.Context>
);
Expand Down