From a8200ce721ac791c4145bd5ffec8b1c976a60338 Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 18 Sep 2024 14:43:09 +0100 Subject: [PATCH 1/6] chore(sanity): add return type to `StudioErrorBoundary` component --- packages/sanity/src/core/studio/StudioErrorBoundary.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx index b82524c5422..18e0c2401d5 100644 --- a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx +++ b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx @@ -9,7 +9,7 @@ import { Heading, Stack, } from '@sanity/ui' -import {type ErrorInfo, type ReactNode, useCallback, useState} from 'react' +import {type ComponentType, type ErrorInfo, type ReactNode, useCallback, useState} from 'react' import {useHotModuleReload} from 'use-hot-module-reload' import {Button} from '../../ui-components' @@ -42,10 +42,10 @@ const INITIAL_STATE = { eventId: null, } satisfies ErrorBoundaryState -export function StudioErrorBoundary({ +export const StudioErrorBoundary: ComponentType = ({ children, heading = 'An error occured', -}: StudioErrorBoundaryProps) { +}) => { const [{error, eventId}, setError] = useState(INITIAL_STATE) const message = isRecord(error) && typeof error.message === 'string' && error.message From 01cff096d7ee2acec297d58d89b418fb8cc3ada8 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 24 Sep 2024 09:26:51 +0100 Subject: [PATCH 2/6] chore: fix spelling mistake --- packages/@sanity/types/src/transactionLog/types.ts | 4 ++-- .../@sanity/vision/src/containers/VisionErrorBoundary.tsx | 2 +- packages/sanity/src/core/studio/StudioErrorBoundary.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@sanity/types/src/transactionLog/types.ts b/packages/@sanity/types/src/transactionLog/types.ts index 5a003eba75f..bea66a05033 100644 --- a/packages/@sanity/types/src/transactionLog/types.ts +++ b/packages/@sanity/types/src/transactionLog/types.ts @@ -51,7 +51,7 @@ export interface TransactionLogEventWithEffects extends TransactionLogEvent { */ export interface TransactionLogEventWithMutations extends TransactionLogEvent { /** - * Array of mutations that occured in this transaction. Note that the transaction + * Array of mutations that occurred in this transaction. Note that the transaction * log has an additional mutation type not typically seen in other APIs; * `createSquashed` ({@link CreateSquashedMutation}). */ @@ -83,7 +83,7 @@ export interface CreateSquashedMutation { createdAt: string /** - * The document as it exists after squashing has occured + * The document as it exists after squashing has occurred */ document: { _id: string diff --git a/packages/@sanity/vision/src/containers/VisionErrorBoundary.tsx b/packages/@sanity/vision/src/containers/VisionErrorBoundary.tsx index a82ae4bf7ab..383be049414 100644 --- a/packages/@sanity/vision/src/containers/VisionErrorBoundary.tsx +++ b/packages/@sanity/vision/src/containers/VisionErrorBoundary.tsx @@ -69,7 +69,7 @@ export class VisionErrorBoundary extends Component< /> - An error occured + An error occurred diff --git a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx index 18e0c2401d5..724a7cfc5ec 100644 --- a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx +++ b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx @@ -44,7 +44,7 @@ const INITIAL_STATE = { export const StudioErrorBoundary: ComponentType = ({ children, - heading = 'An error occured', + heading = 'An error occurred', }) => { const [{error, eventId}, setError] = useState(INITIAL_STATE) From 5e8d38d17c56fb6c07acc7fbc4c8a907be2d05fb Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 18 Sep 2024 21:45:15 +0100 Subject: [PATCH 3/6] chore(sanity): remove unused parameter from `onRetry` function signature --- .../structure/panes/documentList/DocumentListPaneContent.tsx | 2 +- packages/sanity/src/structure/panes/documentList/types.ts | 2 +- .../sanity/src/structure/panes/documentList/useDocumentList.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sanity/src/structure/panes/documentList/DocumentListPaneContent.tsx b/packages/sanity/src/structure/panes/documentList/DocumentListPaneContent.tsx index 4e670294c7b..b3e81cabc11 100644 --- a/packages/sanity/src/structure/panes/documentList/DocumentListPaneContent.tsx +++ b/packages/sanity/src/structure/panes/documentList/DocumentListPaneContent.tsx @@ -46,7 +46,7 @@ interface DocumentListPaneContentProps { layout?: GeneralPreviewLayoutKey loadingVariant?: LoadingVariant onListChange: () => void - onRetry?: (event: unknown) => void + onRetry?: () => void paneTitle: string searchInputElement: HTMLInputElement | null showIcons: boolean diff --git a/packages/sanity/src/structure/panes/documentList/types.ts b/packages/sanity/src/structure/panes/documentList/types.ts index 381556cff4e..fe6fbaa6023 100644 --- a/packages/sanity/src/structure/panes/documentList/types.ts +++ b/packages/sanity/src/structure/panes/documentList/types.ts @@ -13,7 +13,7 @@ export type SortOrder = { export interface QueryResult { error: {message: string} | null - onRetry?: (event: unknown) => void + onRetry?: () => void result: {documents: SanityDocumentLike[]} | null } diff --git a/packages/sanity/src/structure/panes/documentList/useDocumentList.ts b/packages/sanity/src/structure/panes/documentList/useDocumentList.ts index fb055fe9e9a..11a10c9d4f2 100644 --- a/packages/sanity/src/structure/panes/documentList/useDocumentList.ts +++ b/packages/sanity/src/structure/panes/documentList/useDocumentList.ts @@ -38,7 +38,7 @@ interface DocumentListState { isSearchReady: boolean items: DocumentListPaneItem[] onListChange: () => void - onRetry?: (event: unknown) => void + onRetry?: () => void } const INITIAL_QUERY_RESULTS: QueryResult = { From 0e8763cb585b02a4a86dc62531c80ba02f0149ae Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 18 Sep 2024 14:39:24 +0100 Subject: [PATCH 4/6] feat(sanity): add `ErrorActions` component --- .../components/errorActions/ErrorActions.tsx | 47 ++++++++++++++ .../src/core/components/errorActions/index.ts | 3 + .../core/components/errorActions/strings.ts | 10 +++ .../src/core/components/errorActions/types.ts | 7 ++ .../errorActions/useCopyErrorDetails.test.ts | 59 +++++++++++++++++ .../errorActions/useCopyErrorDetails.ts | 64 +++++++++++++++++++ packages/sanity/src/core/components/index.ts | 1 + 7 files changed, 191 insertions(+) create mode 100644 packages/sanity/src/core/components/errorActions/ErrorActions.tsx create mode 100644 packages/sanity/src/core/components/errorActions/index.ts create mode 100644 packages/sanity/src/core/components/errorActions/strings.ts create mode 100644 packages/sanity/src/core/components/errorActions/types.ts create mode 100644 packages/sanity/src/core/components/errorActions/useCopyErrorDetails.test.ts create mode 100644 packages/sanity/src/core/components/errorActions/useCopyErrorDetails.ts diff --git a/packages/sanity/src/core/components/errorActions/ErrorActions.tsx b/packages/sanity/src/core/components/errorActions/ErrorActions.tsx new file mode 100644 index 00000000000..60b0593f5e8 --- /dev/null +++ b/packages/sanity/src/core/components/errorActions/ErrorActions.tsx @@ -0,0 +1,47 @@ +import {CopyIcon, SyncIcon} from '@sanity/icons' +import {Inline} from '@sanity/ui' +import {type ComponentProps, type ComponentType} from 'react' + +import {Button, Tooltip} from '../../../ui-components' +import {strings} from './strings' +import {useCopyErrorDetails} from './useCopyErrorDetails' + +/** + * @internal + */ +export interface ErrorActionsProps extends Pick, 'size'> { + error: unknown + eventId: string | null + onRetry?: () => void +} + +/** + * @internal + */ +export const ErrorActions: ComponentType = ({error, eventId, onRetry, size}) => { + const copyErrorDetails = useCopyErrorDetails(error, eventId) + + return ( + + {onRetry && ( +