From bddabe4e7d4f359db2f9e6f968e6f0b2507be6b9 Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Wed, 6 Sep 2023 17:01:03 -0700 Subject: [PATCH] refactor: remove unused `useConditionalReadOnly` hook --- .../ConditionalReadOnlyContext.ts | 9 ------- .../ConditionalReadOnlyContextProvider.tsx | 26 ------------------- .../conditionalReadOnly/index.ts | 4 --- .../conditionalReadOnly/types.ts | 6 ----- .../useConditionalReadOnly.ts | 15 ----------- .../field/diff/components/FieldChange.tsx | 6 ++--- 6 files changed, 2 insertions(+), 64 deletions(-) delete mode 100644 packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContext.ts delete mode 100644 packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContextProvider.tsx delete mode 100644 packages/sanity/src/core/field/conditional-property/conditionalReadOnly/index.ts delete mode 100644 packages/sanity/src/core/field/conditional-property/conditionalReadOnly/types.ts delete mode 100644 packages/sanity/src/core/field/conditional-property/conditionalReadOnly/useConditionalReadOnly.ts diff --git a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContext.ts b/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContext.ts deleted file mode 100644 index 972ff8c7806..00000000000 --- a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContext.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {createContext} from 'react' -import {ConditionalReadOnlyContextValue} from './types' - -/** - * @internal - */ -export const ConditionalReadOnlyContext = createContext( - null, -) diff --git a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContextProvider.tsx b/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContextProvider.tsx deleted file mode 100644 index ea6cfde0feb..00000000000 --- a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/ConditionalReadOnlyContextProvider.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import React, {useMemo} from 'react' -import {ConditionalReadOnlyContext} from './ConditionalReadOnlyContext' -import {ConditionalReadOnlyContextValue} from './types' - -/** - * @internal - */ -export function ConditionalReadOnlyContextProvider(props: { - children?: React.ReactNode - readOnly?: boolean -}): React.ReactElement { - const {children, readOnly} = props - - const contextValue: ConditionalReadOnlyContextValue = useMemo( - () => ({ - readOnly, - }), - [readOnly], - ) - - return ( - - {children} - - ) -} diff --git a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/index.ts b/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/index.ts deleted file mode 100644 index aab653a321c..00000000000 --- a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './ConditionalReadOnlyContext' -export * from './ConditionalReadOnlyContextProvider' -export * from './types' -export * from './useConditionalReadOnly' diff --git a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/types.ts b/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/types.ts deleted file mode 100644 index 33afe845bf2..00000000000 --- a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @internal - */ -export interface ConditionalReadOnlyContextValue { - readOnly?: boolean -} diff --git a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/useConditionalReadOnly.ts b/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/useConditionalReadOnly.ts deleted file mode 100644 index c0952f5570e..00000000000 --- a/packages/sanity/src/core/field/conditional-property/conditionalReadOnly/useConditionalReadOnly.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {useContext} from 'react' -import {ConditionalReadOnlyContext} from './ConditionalReadOnlyContext' - -/** - * @internal - */ -export function useConditionalReadOnly(): boolean | null { - const context = useContext(ConditionalReadOnlyContext) - - if (!context) { - return null - } - - return context.readOnly || null -} diff --git a/packages/sanity/src/core/field/diff/components/FieldChange.tsx b/packages/sanity/src/core/field/diff/components/FieldChange.tsx index 32023523907..ec002d382c5 100644 --- a/packages/sanity/src/core/field/diff/components/FieldChange.tsx +++ b/packages/sanity/src/core/field/diff/components/FieldChange.tsx @@ -1,7 +1,6 @@ import React, {useCallback, useMemo, useState} from 'react' import {Stack, Box, Button, Text, Grid, useClickOutside} from '@sanity/ui' import {ObjectSchemaType} from '@sanity/types' -import {useConditionalReadOnly} from '../../conditional-property/conditionalReadOnly' import {useDocumentOperation} from '../../../hooks' import {FieldChangeNode, FieldOperationsAPI} from '../../types' import {undoChange} from '../changes/undoChange' @@ -25,7 +24,6 @@ export function FieldChange( } & React.HTMLAttributes, ) { const {change, hidden, readOnly} = props - const conditionalReadOnly = useConditionalReadOnly() ?? readOnly const DiffComponent = change.diffComponent || FallbackDiff const { documentId, @@ -131,7 +129,7 @@ export function FieldChange( onMouseEnter={handleRevertButtonMouseEnter} onMouseLeave={handleRevertButtonMouseLeave} selected={confirmRevertOpen} - disabled={conditionalReadOnly} + disabled={readOnly} data-testid={`single-change-revert-button-${change?.key}`} /> @@ -144,7 +142,7 @@ export function FieldChange( [ change, closeRevertChangesConfirmDialog, - conditionalReadOnly, + readOnly, confirmRevertOpen, DiffComponent, FieldWrapper,