Skip to content

Commit 5e79523

Browse files
authored
Re-enable transaction duration alert story (#80187)
This was disabled in an earlier version of Storybook but works now.
1 parent fbe3418 commit 5e79523

File tree

1 file changed

+48
-32
lines changed
  • x-pack/plugins/apm/public/components/alerting/TransactionDurationAlertTrigger

1 file changed

+48
-32
lines changed

x-pack/plugins/apm/public/components/alerting/TransactionDurationAlertTrigger/index.stories.tsx

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
// import { storiesOf } from '@storybook/react';
6+
77
import { cloneDeep, merge } from 'lodash';
8-
import React from 'react';
8+
import React, { ComponentType } from 'react';
9+
import { MemoryRouter, Route } from 'react-router-dom';
910
import { TransactionDurationAlertTrigger } from '.';
1011
import { ApmPluginContextValue } from '../../../context/ApmPluginContext';
1112
import {
@@ -14,40 +15,55 @@ import {
1415
} from '../../../context/ApmPluginContext/MockApmPluginContext';
1516
import { MockUrlParamsContextProvider } from '../../../context/UrlParamsContext/MockUrlParamsContextProvider';
1617

17-
// Disabling this because we currently don't have a way to mock `useEnvironments`
18-
// which is used by this component. Using the fetch-mock module should work, but
19-
// our current storybook setup has core-js-related problems when trying to import
20-
// it.
21-
// storiesOf('app/TransactionDurationAlertTrigger', module).add('example',
22-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
23-
() => {
18+
export default {
19+
title: 'app/TransactionDurationAlertTrigger',
20+
component: TransactionDurationAlertTrigger,
21+
decorators: [
22+
(Story: ComponentType) => {
23+
const contextMock = (merge(cloneDeep(mockApmPluginContextValue), {
24+
core: {
25+
http: {
26+
get: (endpoint: string) => {
27+
if (endpoint === '/api/apm/ui_filters/environments') {
28+
return Promise.resolve(['production']);
29+
} else {
30+
return Promise.resolve({
31+
transactionTypes: ['request'],
32+
});
33+
}
34+
},
35+
},
36+
},
37+
}) as unknown) as ApmPluginContextValue;
38+
39+
return (
40+
<div style={{ width: 400 }}>
41+
<MemoryRouter initialEntries={['/transactions/test-service-name']}>
42+
<Route path="/transactions/:serviceName">
43+
<MockApmPluginContextWrapper value={contextMock}>
44+
<MockUrlParamsContextProvider>
45+
<Story />
46+
</MockUrlParamsContextProvider>
47+
</MockApmPluginContextWrapper>
48+
</Route>
49+
</MemoryRouter>
50+
</div>
51+
);
52+
},
53+
],
54+
};
55+
56+
export function Example() {
2457
const params = {
2558
threshold: 1500,
2659
aggregationType: 'avg' as const,
2760
window: '5m',
2861
};
29-
30-
const contextMock = (merge(cloneDeep(mockApmPluginContextValue), {
31-
core: {
32-
http: {
33-
get: () => {
34-
return Promise.resolve({ transactionTypes: ['request'] });
35-
},
36-
},
37-
},
38-
}) as unknown) as ApmPluginContextValue;
39-
4062
return (
41-
<div style={{ width: 400 }}>
42-
<MockApmPluginContextWrapper value={contextMock}>
43-
<MockUrlParamsContextProvider>
44-
<TransactionDurationAlertTrigger
45-
alertParams={params as any}
46-
setAlertParams={() => undefined}
47-
setAlertProperty={() => undefined}
48-
/>
49-
</MockUrlParamsContextProvider>
50-
</MockApmPluginContextWrapper>
51-
</div>
63+
<TransactionDurationAlertTrigger
64+
alertParams={params as any}
65+
setAlertParams={() => undefined}
66+
setAlertProperty={() => undefined}
67+
/>
5268
);
53-
};
69+
}

0 commit comments

Comments
 (0)