From 6dcf396f5cd6e264474ed1f0e9e4e49324e65dbd Mon Sep 17 00:00:00 2001 From: Nathan L Smith Date: Mon, 12 Apr 2021 10:54:40 -0500 Subject: [PATCH] Some more story fixes --- .../public/pages/alerts/alerts.stories.tsx | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/observability/public/pages/alerts/alerts.stories.tsx b/x-pack/plugins/observability/public/pages/alerts/alerts.stories.tsx index d5240f802ab03..33eec65c40dce 100644 --- a/x-pack/plugins/observability/public/pages/alerts/alerts.stories.tsx +++ b/x-pack/plugins/observability/public/pages/alerts/alerts.stories.tsx @@ -5,6 +5,7 @@ * 2.0. */ +import { StoryContext } from '@storybook/react'; import React, { ComponentType } from 'react'; import { IntlProvider } from 'react-intl'; import { MemoryRouter } from 'react-router-dom'; @@ -16,17 +17,32 @@ import { createObservabilityRuleRegistryMock } from '../../rules/observability_r import { createCallObservabilityApi } from '../../services/call_observability_api'; import type { ObservabilityAPIReturnType } from '../../services/call_observability_api/types'; import { AlertsFlyout } from './alerts_flyout'; +import { TopAlert } from './alerts_table'; import { apmAlertResponseExample, dynamicIndexPattern, flyoutItemExample } from './example_data'; -interface Args { +interface PageArgs { items: ObservabilityAPIReturnType<'GET /api/observability/rules/alerts/top'>; } +interface FlyoutArgs { + alert: TopAlert; +} + export default { title: 'app/Alerts', component: AlertsPage, decorators: [ - (Story: ComponentType) => { + (Story: ComponentType, { args: { items = [] } }: StoryContext) => { + createCallObservabilityApi(({ + get: async (endpoint: string) => { + if (endpoint === '/api/observability/rules/alerts/top') { + return items; + } else if (endpoint === '/api/observability/rules/alerts/dynamic_index_pattern') { + return dynamicIndexPattern; + } + }, + } as unknown) as HttpSetup); + return ( @@ -66,29 +82,21 @@ export default { ], }; -export function Example({ items }: Args) { - createCallObservabilityApi(({ - get: async (endpoint: string) => { - if (endpoint === '/api/observability/rules/alerts/top') { - return items; - } else if (endpoint === '/api/observability/rules/alerts/dynamic_index_pattern') { - return dynamicIndexPattern; - } - }, - } as unknown) as HttpSetup); - +export function Example(_args: PageArgs) { return ( ); } Example.args = { items: apmAlertResponseExample, -} as Args; +} as PageArgs; -export function EmptyState() { +export function EmptyState(_args: PageArgs) { return ; } +EmptyState.args = { items: [] } as PageArgs; -export function Flyout() { - return {}} />; +export function Flyout({ alert }: FlyoutArgs) { + return {}} />; } +Flyout.args = { alert: flyoutItemExample } as FlyoutArgs;