mirror of https://github.com/grafana/grafana
Alerting: Storybook integration (#107024)
parent
0356e1302a
commit
092249b772
@ -0,0 +1,13 @@ |
||||
# @grafana/alerting |
||||
|
||||
This is the alerting package for Grafana. It provides components and utilities for creating and managing alerts within Grafana. |
||||
|
||||
It is designed to be used in conjunction with Grafana's alerting system, allowing developers to create custom alerting solutions. |
||||
|
||||
## Installation |
||||
|
||||
To install the package: |
||||
|
||||
```bash |
||||
npm install @grafana/alerting |
||||
``` |
@ -0,0 +1,6 @@ |
||||
import { ArgTypes } from '@storybook/blocks'; |
||||
import { ContactPointSelector } from './ContactPointSelector'; |
||||
|
||||
# ContactPointSelector |
||||
|
||||
A component for selecting contact points in Grafana. Only works with the built-in Grafana Alertmanager. |
@ -0,0 +1,37 @@ |
||||
import type { Meta, StoryObj } from '@storybook/react'; |
||||
|
||||
import { defaultDecorators } from '../../../../../tests/story-utils'; |
||||
|
||||
import { ContactPointSelector } from './ContactPointSelector'; |
||||
import mdx from './ContactPointSelector.mdx'; |
||||
import { simpleContactPointsListScenario, withErrorScenario } from './ContactPointSelector.test.scenario'; |
||||
|
||||
const meta: Meta<typeof ContactPointSelector> = { |
||||
component: ContactPointSelector, |
||||
title: 'ContactPointSelector', |
||||
decorators: defaultDecorators, |
||||
parameters: { |
||||
docs: { |
||||
page: mdx, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
export default meta; |
||||
type Story = StoryObj<typeof ContactPointSelector>; |
||||
|
||||
export const Basic: Story = { |
||||
parameters: { |
||||
msw: { |
||||
handlers: simpleContactPointsListScenario, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
export const WithError: Story = { |
||||
parameters: { |
||||
msw: { |
||||
handlers: withErrorScenario, |
||||
}, |
||||
}, |
||||
}; |
@ -0,0 +1,41 @@ |
||||
import { configureStore } from '@reduxjs/toolkit'; |
||||
import { useEffect } from 'react'; |
||||
import { Provider } from 'react-redux'; |
||||
|
||||
import { alertingAPIv0alpha1 } from '../src/unstable'; |
||||
|
||||
// create an empty store
|
||||
export const store = configureStore({ |
||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(alertingAPIv0alpha1.middleware), |
||||
reducer: { |
||||
[alertingAPIv0alpha1.reducerPath]: alertingAPIv0alpha1.reducer, |
||||
}, |
||||
}); |
||||
|
||||
/** |
||||
* Get a wrapper component that implements all of the providers that components |
||||
* within the app will need |
||||
*/ |
||||
export const getDefaultWrapper = () => { |
||||
/** |
||||
* Returns a wrapper that should (eventually?) match the main `AppWrapper`, so any tests are rendering |
||||
* in mostly the same providers as a "real" hierarchy |
||||
*/ |
||||
return function Wrapper({ children }: React.PropsWithChildren) { |
||||
useResetQueryCacheAfterUnmount(); |
||||
return <Provider store={store}>{children}</Provider>; |
||||
}; |
||||
}; |
||||
|
||||
/** |
||||
* Whenever the test wrapper unmounts, we also want to clear the RTKQ cache entirely. |
||||
* if we don't then we won't be able to test components / stories with different responses for the same endpoint since |
||||
* the responses will be cached between renders / components / stories. |
||||
*/ |
||||
function useResetQueryCacheAfterUnmount() { |
||||
useEffect(() => { |
||||
return () => { |
||||
store.dispatch(alertingAPIv0alpha1.util.resetApiState()); |
||||
}; |
||||
}, []); |
||||
} |
@ -0,0 +1,13 @@ |
||||
import type { Meta } from '@storybook/react'; |
||||
|
||||
import { getDefaultWrapper } from './provider'; |
||||
|
||||
const Wrapper = getDefaultWrapper(); |
||||
|
||||
export const defaultDecorators: Meta['decorators'] = [ |
||||
(Story) => ( |
||||
<Wrapper> |
||||
<Story /> |
||||
</Wrapper> |
||||
), |
||||
]; |
Loading…
Reference in new issue