From 0df65434df0bf43e168485b7e396e3092bf188d4 Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Thu, 19 Dec 2024 04:41:03 +0900 Subject: [PATCH] Move ErrorIndicator to separate file --- .../ErrorIndicator/ErrorIndicator.stories.tsx | 64 +++++++++++++++++++ .../ErrorIndicator/ErrorIndicator.tsx | 58 +++++++++++++++++ .../internal/container/Errors.tsx | 47 ++------------ 3 files changed, 129 insertions(+), 40 deletions(-) create mode 100644 packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.stories.tsx create mode 100644 packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.tsx diff --git a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.stories.tsx b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.stories.tsx new file mode 100644 index 00000000000000..a3aa2528e70e3e --- /dev/null +++ b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.stories.tsx @@ -0,0 +1,64 @@ +import type { Meta, StoryObj } from '@storybook/react' +import { ErrorIndicator } from './ErrorIndicator' +import { withShadowPortal } from '../../storybook/with-shadow-portal' + +const meta: Meta = { + title: 'ErrorIndicator', + component: ErrorIndicator, + parameters: { + layout: 'centered', + }, + decorators: [withShadowPortal], +} + +export default meta +type Story = StoryObj + +// Mock error for stories +const mockError = { + id: 1, + runtime: true as const, + error: new Error('Test error'), + frames: [ + { + error: true, + reason: null, + external: false, + ignored: false, + sourceStackFrame: { + file: 'test.js', + methodName: '', + arguments: [], + lineNumber: 1, + column: 1, + }, + }, + ], +} + +export const SingleError: Story = { + args: { + hasStaticIndicator: false, + readyErrors: [mockError], + fullscreen: () => console.log('Fullscreen clicked'), + hide: () => console.log('Hide clicked'), + }, +} + +export const MultipleErrors: Story = { + args: { + hasStaticIndicator: false, + readyErrors: [mockError, { ...mockError, id: 2 }, { ...mockError, id: 3 }], + fullscreen: () => console.log('Fullscreen clicked'), + hide: () => console.log('Hide clicked'), + }, +} + +export const WithStaticIndicator: Story = { + args: { + hasStaticIndicator: true, + readyErrors: [mockError], + fullscreen: () => console.log('Fullscreen clicked'), + hide: () => console.log('Hide clicked'), + }, +} diff --git a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.tsx b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.tsx new file mode 100644 index 00000000000000..a0a473f69e29c9 --- /dev/null +++ b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.tsx @@ -0,0 +1,58 @@ +import type { ReadyRuntimeError } from '../../helpers/get-error-by-type' +import { Toast } from '../Toast' +import { CloseIcon } from '../../icons/CloseIcon' + +type ErrorIndicatorProps = { + readyErrors: ReadyRuntimeError[] + fullscreen: () => void + hide: () => void + hasStaticIndicator?: boolean +} + +export function ErrorIndicator({ + hasStaticIndicator, + readyErrors, + fullscreen, + hide, +}: ErrorIndicatorProps) { + return ( + +
+ + + + + + + {readyErrors.length} issue{readyErrors.length > 1 ? 's' : ''} + + +
+
+ ) +} diff --git a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.tsx b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.tsx index 7afe03a9fb24fd..165b74fbf080d0 100644 --- a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.tsx +++ b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/Errors.tsx @@ -14,11 +14,9 @@ import { } from '../components/Dialog' import { LeftRightDialogHeader } from '../components/LeftRightDialogHeader' import { Overlay } from '../components/Overlay' -import { Toast } from '../components/Toast' import { getErrorByType } from '../helpers/get-error-by-type' import type { ReadyRuntimeError } from '../helpers/get-error-by-type' import { noop as css } from '../helpers/noop-template' -import { CloseIcon } from '../icons/CloseIcon' import { RuntimeError } from './RuntimeError' import { VersionStalenessInfo } from '../components/VersionStalenessInfo' import type { VersionInfo } from '../../../../../../server/dev/parse-version-info' @@ -36,6 +34,7 @@ import { isUnhandledConsoleOrRejection, } from '../helpers/console-error' import { extractNextErrorCode } from '../../../../../../lib/error-telemetry-utils' +import { ErrorIndicator } from '../components/ErrorIndicator/ErrorIndicator' export type SupportedErrorEvent = { id: number @@ -234,44 +233,12 @@ export function Errors({ if (displayState === 'minimized') { return ( - -
- - - - - - - {readyErrors.length} issue{readyErrors.length > 1 ? 's' : ''} - - -
-
+ ) }