Skip to content

Commit

Permalink
Merge branch 'master' into move-status-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed May 4, 2020
2 parents cce528d + 4d19323 commit 51f4f6d
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/plugins/expressions/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export {
ReactExpressionRendererProps,
ReactExpressionRendererType,
} from './react_expression_renderer';
export { ExpressionRenderHandler } from './render';
export { ExpressionRenderHandler, ExpressionRendererEvent } from './render';
export {
AnyExpressionFunctionDefinition,
AnyExpressionTypeDefinition,
Expand Down
41 changes: 41 additions & 0 deletions src/plugins/expressions/public/react_expression_renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ExpressionLoader } from './loader';
import { mount } from 'enzyme';
import { EuiProgress } from '@elastic/eui';
import { RenderErrorHandlerFnType } from './types';
import { ExpressionRendererEvent } from './render';

jest.mock('./loader', () => {
return {
Expand Down Expand Up @@ -135,4 +136,44 @@ describe('ExpressionRenderer', () => {
expect(instance.find(EuiProgress)).toHaveLength(0);
expect(instance.find('[data-test-subj="custom-error"]')).toHaveLength(0);
});

it('should fire onEvent prop on every events$ observable emission in loader', () => {
const dataSubject = new Subject();
const data$ = dataSubject.asObservable().pipe(share());
const renderSubject = new Subject();
const render$ = renderSubject.asObservable().pipe(share());
const loadingSubject = new Subject();
const loading$ = loadingSubject.asObservable().pipe(share());
const eventsSubject = new Subject<ExpressionRendererEvent>();
const events$ = eventsSubject.asObservable().pipe(share());

const onEvent = jest.fn();
const event: ExpressionRendererEvent = {
name: 'foo',
data: {
bar: 'baz',
},
};

(ExpressionLoader as jest.Mock).mockImplementation(() => {
return {
render$,
data$,
loading$,
events$,
update: jest.fn(),
};
});

mount(<ReactExpressionRenderer expression="" onEvent={onEvent} />);

expect(onEvent).toHaveBeenCalledTimes(0);

act(() => {
eventsSubject.next(event);
});

expect(onEvent).toHaveBeenCalledTimes(1);
expect(onEvent.mock.calls[0][0]).toBe(event);
});
});
12 changes: 11 additions & 1 deletion src/plugins/expressions/public/react_expression_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import theme from '@elastic/eui/dist/eui_theme_light.json';
import { IExpressionLoaderParams, RenderError } from './types';
import { ExpressionAstExpression, IInterpreterRenderHandlers } from '../common';
import { ExpressionLoader } from './loader';
import { ExpressionRendererEvent } from './render';

// Accept all options of the runner as props except for the
// dom element which is provided by the component itself
Expand All @@ -36,6 +37,7 @@ export interface ReactExpressionRendererProps extends IExpressionLoaderParams {
expression: string | ExpressionAstExpression;
renderError?: (error?: string | null) => React.ReactElement | React.ReactElement[];
padding?: 'xs' | 's' | 'm' | 'l' | 'xl';
onEvent?: (event: ExpressionRendererEvent) => void;
}

export type ReactExpressionRendererType = React.ComponentType<ReactExpressionRendererProps>;
Expand All @@ -60,6 +62,7 @@ export const ReactExpressionRenderer = ({
padding,
renderError,
expression,
onEvent,
...expressionLoaderOptions
}: ReactExpressionRendererProps) => {
const mountpoint: React.MutableRefObject<null | HTMLDivElement> = useRef(null);
Expand Down Expand Up @@ -99,6 +102,13 @@ export const ReactExpressionRenderer = ({
}
: expressionLoaderOptions.onRenderError,
});
if (onEvent) {
subs.push(
expressionLoaderRef.current.events$.subscribe(event => {
onEvent(event);
})
);
}
subs.push(
expressionLoaderRef.current.loading$.subscribe(() => {
hasHandledErrorRef.current = false;
Expand All @@ -123,7 +133,7 @@ export const ReactExpressionRenderer = ({

errorRenderHandlerRef.current = null;
};
}, [hasCustomRenderErrorHandler]);
}, [hasCustomRenderErrorHandler, onEvent]);

// Re-fetch data automatically when the inputs change
useShallowCompareEffect(
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/expressions/public/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface ExpressionRenderHandlerParams {
onRenderError: RenderErrorHandlerFnType;
}

interface Event {
export interface ExpressionRendererEvent {
name: string;
data: any;
}
Expand All @@ -45,7 +45,7 @@ interface UpdateValue {
export class ExpressionRenderHandler {
render$: Observable<number>;
update$: Observable<UpdateValue | null>;
events$: Observable<Event>;
events$: Observable<ExpressionRendererEvent>;

private element: HTMLElement;
private destroyFn?: any;
Expand All @@ -63,7 +63,7 @@ export class ExpressionRenderHandler {
this.element = element;

this.eventsSubject = new Rx.Subject();
this.events$ = this.eventsSubject.asObservable() as Observable<Event>;
this.events$ = this.eventsSubject.asObservable() as Observable<ExpressionRendererEvent>;

this.onRenderError = onRenderError || defaultRenderErrorHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { render, wait } from '@testing-library/react';
import { render } from '@testing-library/react';
import React from 'react';
import { ApmIndices } from '.';
import * as hooks from '../../../../hooks/useFetcher';
import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext';

describe('ApmIndices', () => {
it('should not get stuck in infinite loop', async () => {
spyOn(hooks, 'useFetcher').and.returnValue({
it('should not get stuck in infinite loop', () => {
const spy = spyOn(hooks, 'useFetcher').and.returnValue({
data: undefined,
status: 'loading'
});
Expand All @@ -30,6 +30,6 @@ describe('ApmIndices', () => {
</h2>
`);

await wait();
expect(spy).toHaveBeenCalledTimes(2);
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/scripts/optimize-tsconfig/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
const path = require('path');

const xpackRoot = path.resolve(__dirname, '../../../../..');
const xpackRoot = path.resolve(__dirname, '../../../..');
const kibanaRoot = path.resolve(xpackRoot, '..');

const tsconfigTpl = path.resolve(__dirname, './tsconfig.json');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion x-pack/plugins/apm/server/lib/transaction_groups/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export function transactionGroupsFetcher(
sample: { top_hits: { size: 1, sort } },
avg: { avg: { field: TRANSACTION_DURATION } },
p95: {
percentiles: { field: TRANSACTION_DURATION, percents: [95] }
percentiles: {
field: TRANSACTION_DURATION,
percents: [95],
hdr: { number_of_significant_value_digits: 2 }
}
},
sum: { sum: { field: TRANSACTION_DURATION } }
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export function timeseriesFetcher({
aggs: {
avg: { avg: { field: TRANSACTION_DURATION } },
pct: {
percentiles: { field: TRANSACTION_DURATION, percents: [95, 99] }
percentiles: {
field: TRANSACTION_DURATION,
percents: [95, 99],
hdr: { number_of_significant_value_digits: 2 }
}
}
}
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/typings/elasticsearch/aggregations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface AggregationOptionsByType {
percentiles: {
field: string;
percents?: number[];
hdr?: { number_of_significant_value_digits: number };
};
extended_stats: {
field: string;
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export interface RegistryVarsEntry {
interface PackageAdditions {
title: string;
latestVersion: string;
installedVersion?: string;
assets: AssetsGroupedByServiceByType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ const Text = styled.span`
type HeaderProps = PackageInfo & { iconType?: IconType };

export function Header(props: HeaderProps) {
const { iconType, name, title, version, installedVersion, latestVersion } = props;
const { iconType, name, title, version, latestVersion } = props;

let installedVersion;
if ('savedObject' in props) {
installedVersion = props.savedObject.attributes.version;
}
const hasWriteCapabilites = useCapabilities().write;
const { toListView } = useLinks();
const ADD_DATASOURCE_URI = useLink(`${EPM_PATH}/${name}-${version}/add-datasource`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export function Detail() {
const packageInfo = response.data?.response;
const title = packageInfo?.title;
const name = packageInfo?.name;
const installedVersion = packageInfo?.installedVersion;
let installedVersion;
if (packageInfo && 'savedObject' in packageInfo) {
installedVersion = packageInfo.savedObject.attributes.version;
}
const status: InstallStatus = packageInfo?.status as any;

// track install status state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,34 @@ export function EPMHomePage() {
function InstalledPackages() {
const { data: allPackages, isLoading: isLoadingPackages } = useGetPackages();
const [selectedCategory, setSelectedCategory] = useState('');
const packages =
allPackages && allPackages.response && selectedCategory === ''
? allPackages.response.filter(pkg => pkg.status === 'installed')
: [];

const title = i18n.translate('xpack.ingestManager.epmList.installedTitle', {
defaultMessage: 'Installed integrations',
});

const allInstalledPackages =
allPackages && allPackages.response
? allPackages.response.filter(pkg => pkg.status === 'installed')
: [];

const updatablePackages = allInstalledPackages.filter(
item => 'savedObject' in item && item.version > item.savedObject.attributes.version
);

const categories = [
{
id: '',
title: i18n.translate('xpack.ingestManager.epmList.allFilterLinkText', {
defaultMessage: 'All',
}),
count: packages.length,
count: allInstalledPackages.length,
},
{
id: 'updates_available',
title: i18n.translate('xpack.ingestManager.epmList.updatesAvailableFilterLinkText', {
defaultMessage: 'Updates available',
}),
count: 0, // TODO: Update with real count when available
count: updatablePackages.length,
},
];

Expand All @@ -106,7 +111,7 @@ function InstalledPackages() {
isLoading={isLoadingPackages}
controls={controls}
title={title}
list={packages}
list={selectedCategory === 'updates_available' ? updatablePackages : allInstalledPackages}
/>
);
}
Expand Down Expand Up @@ -134,7 +139,6 @@ function AvailablePackages() {
},
...(categoriesRes ? categoriesRes.response : []),
];

const controls = categories ? (
<CategoryFacets
isLoading={isLoadingCategories}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ export {
DetailViewPanelName,
InstallStatus,
InstallationStatus,
Installable,
} from '../../../../common';
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export function createInstallableFrom<T>(
? {
...from,
status: InstallationStatus.installed,
installedVersion: savedObject.attributes.version,
savedObject,
}
: {
Expand Down

0 comments on commit 51f4f6d

Please sign in to comment.