diff --git a/packages/sanity/src/_singletons/context/BundlesMetadataContext.ts b/packages/sanity/src/_singletons/context/BundlesMetadataContext.ts new file mode 100644 index 000000000000..f57635eda1db --- /dev/null +++ b/packages/sanity/src/_singletons/context/BundlesMetadataContext.ts @@ -0,0 +1,12 @@ +import {createContext} from 'sanity/_createContext' + +import type {BundlesMetadataContextValue} from '../../core/releases/contexts/BundlesMetadataProvider' + +/** + * @internal + * @hidden + */ +export const BundlesMetadataContext = createContext( + 'sanity/_singletons/context/bundles-metadata', + null, +) diff --git a/packages/sanity/src/_singletons/context/ReleasesTableContext.ts b/packages/sanity/src/_singletons/context/ReleasesTableContext.ts new file mode 100644 index 000000000000..8d35e73535b0 --- /dev/null +++ b/packages/sanity/src/_singletons/context/ReleasesTableContext.ts @@ -0,0 +1,11 @@ +import {createContext} from 'sanity/_createContext' + +import type {TableContextValue} from '../../core/releases/components/Table/TableProvider' + +/** + * @internal + */ +export const TableContext = createContext( + 'sanity/_singletons/context/releases-table', + null, +) diff --git a/packages/sanity/src/_singletons/core/releases/BundlesMetadataContext.ts b/packages/sanity/src/_singletons/core/releases/BundlesMetadataContext.ts deleted file mode 100644 index 09c2f0fc4c20..000000000000 --- a/packages/sanity/src/_singletons/core/releases/BundlesMetadataContext.ts +++ /dev/null @@ -1,18 +0,0 @@ -import {createContext} from 'react' - -import type {MetadataWrapper} from '../../../core/store/bundles/createBundlesMetadataAggregator' - -/** - * @internal - */ -export interface BundlesMetadataContextValue { - state: MetadataWrapper - addBundleSlugsToListener: (slugs: string[]) => void - removeBundleSlugsFromListener: (slugs: string[]) => void -} - -/** - * @internal - * @hidden - */ -export const BundlesMetadataContext = createContext(null) diff --git a/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts b/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts deleted file mode 100644 index 720d95dd8c2c..000000000000 --- a/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts +++ /dev/null @@ -1,36 +0,0 @@ -import {createContext, useContext} from 'react' - -import type {TableSort} from '../../../core/releases/components/Table/TableProvider' - -/** - * @internal - */ -export interface TableContextValue { - searchTerm: string | null - setSearchTerm: (searchTerm: string) => void - sort: TableSort | null - setSortColumn: (column: string) => void -} - -const DEFAULT_TABLE_CONTEXT: TableContextValue = { - searchTerm: null, - setSearchTerm: () => null, - sort: null, - setSortColumn: () => null, -} - -/** - * @internal - */ -export const TableContext = createContext(null) - -/** - * @internal - */ -export const useTableContext = (): TableContextValue => { - const context = useContext(TableContext) - if (!context) { - throw new Error('useTableContext must be used within a TableProvider') - } - return context || DEFAULT_TABLE_CONTEXT -} diff --git a/packages/sanity/src/_singletons/index.ts b/packages/sanity/src/_singletons/index.ts index 67575ae237e2..b61d32838f23 100644 --- a/packages/sanity/src/_singletons/index.ts +++ b/packages/sanity/src/_singletons/index.ts @@ -1,5 +1,6 @@ export * from './context/ActiveWorkspaceMatcherContext' export * from './context/AddonDatasetContext' +export * from './context/BundlesMetadataContext' export * from './context/CalendarContext' export * from './context/ChangeIndicatorTrackerContexts' export * from './context/ColorSchemeSetValueContext' @@ -43,6 +44,7 @@ export * from './context/PresenceTrackerContexts' export * from './context/PreviewCardContext' export * from './context/ReferenceInputOptionsContext' export * from './context/ReferenceItemRefContext' +export * from './context/ReleasesTableContext' export * from './context/ResourceCacheContext' export * from './context/ReviewChangesContext' export * from './context/RouterContext' @@ -66,5 +68,3 @@ export * from './context/VirtualizerScrollInstanceContext' export * from './context/WorkspaceContext' export * from './context/WorkspacesContext' export * from './context/ZIndexContext' -export * from './core/releases/BundlesMetadataContext' -export * from './core/releases/ReleasesTableContext' diff --git a/packages/sanity/src/core/releases/components/Table/Table.tsx b/packages/sanity/src/core/releases/components/Table/Table.tsx index 2b4073da0a0f..1265e6a69934 100644 --- a/packages/sanity/src/core/releases/components/Table/Table.tsx +++ b/packages/sanity/src/core/releases/components/Table/Table.tsx @@ -1,13 +1,12 @@ import {Box, Card, Flex, Stack, Text} from '@sanity/ui' import {get} from 'lodash' import {Fragment, useMemo} from 'react' -import {useTableContext} from 'sanity/_singletons' import {styled} from 'styled-components' import {TooltipDelayGroupProvider} from '../../../../ui-components' import {LoadingBlock} from '../../../components' import {TableHeader} from './TableHeader' -import {TableProvider, type TableSort} from './TableProvider' +import {TableProvider, type TableSort, useTableContext} from './TableProvider' import {type Column} from './types' type RowDatum = AdditionalRowTableData extends undefined diff --git a/packages/sanity/src/core/releases/components/Table/TableHeader.tsx b/packages/sanity/src/core/releases/components/Table/TableHeader.tsx index 22cfc8d0e91b..2ebc5c87e967 100644 --- a/packages/sanity/src/core/releases/components/Table/TableHeader.tsx +++ b/packages/sanity/src/core/releases/components/Table/TableHeader.tsx @@ -1,7 +1,7 @@ import {ArrowDownIcon, ArrowUpIcon, SearchIcon} from '@sanity/icons' import {Button, type ButtonProps, Card, Flex, Stack, TextInput} from '@sanity/ui' -import {useTableContext} from 'sanity/_singletons' +import {useTableContext} from './TableProvider' import {type HeaderProps, type TableHeaderProps} from './types' const SortHeaderButton = ({header, text}: ButtonProps & HeaderProps) => { diff --git a/packages/sanity/src/core/releases/components/Table/TableProvider.tsx b/packages/sanity/src/core/releases/components/Table/TableProvider.tsx index b2bbd05012c0..c11d365dded4 100644 --- a/packages/sanity/src/core/releases/components/Table/TableProvider.tsx +++ b/packages/sanity/src/core/releases/components/Table/TableProvider.tsx @@ -1,4 +1,4 @@ -import {type ComponentType, type PropsWithChildren, useCallback, useState} from 'react' +import {type ComponentType, type PropsWithChildren, useCallback, useContext, useState} from 'react' import {TableContext} from 'sanity/_singletons' export interface TableSort { @@ -6,6 +6,16 @@ export interface TableSort { direction: 'asc' | 'desc' } +/** + * @internal + */ +export interface TableContextValue { + searchTerm: string | null + setSearchTerm: (searchTerm: string) => void + sort: TableSort | null + setSortColumn: (column: string) => void +} + /** * @internal */ @@ -30,3 +40,14 @@ export const TableProvider: ComponentType{children} } + +/** + * @internal + */ +export const useTableContext = (): TableContextValue => { + const context = useContext(TableContext) + if (!context) { + throw new Error('useTableContext must be used within a TableProvider') + } + return context +} diff --git a/packages/sanity/src/core/releases/contexts/BundlesMetadataProvider.tsx b/packages/sanity/src/core/releases/contexts/BundlesMetadataProvider.tsx index cbd5a4dab86c..920c6971454f 100644 --- a/packages/sanity/src/core/releases/contexts/BundlesMetadataProvider.tsx +++ b/packages/sanity/src/core/releases/contexts/BundlesMetadataProvider.tsx @@ -6,6 +6,15 @@ import {BundlesMetadataContext} from 'sanity/_singletons' import {type MetadataWrapper} from '../../store/bundles/createBundlesMetadataAggregator' import {type BundlesMetadata} from '../tool/useBundlesMetadata' +/** + * @internal + */ +export interface BundlesMetadataContextValue { + state: MetadataWrapper + addBundleSlugsToListener: (slugs: string[]) => void + removeBundleSlugsFromListener: (slugs: string[]) => void +} + const DEFAULT_METADATA_STATE: MetadataWrapper = { data: null, error: null, @@ -91,7 +100,7 @@ export const BundlesMetadataProvider = ({children}: {children: React.ReactNode}) return {children} } -export const useBundlesMetadataProvider = () => { +export const useBundlesMetadataProvider = (): BundlesMetadataContextValue => { const contextValue = useContext(BundlesMetadataContext) return ( diff --git a/packages/sanity/src/core/releases/tool/detail/ReleaseSummary.tsx b/packages/sanity/src/core/releases/tool/detail/ReleaseSummary.tsx index dc3cec6d1ba4..f6a8f185a95f 100644 --- a/packages/sanity/src/core/releases/tool/detail/ReleaseSummary.tsx +++ b/packages/sanity/src/core/releases/tool/detail/ReleaseSummary.tsx @@ -2,7 +2,6 @@ import {DocumentsIcon} from '@sanity/icons' import {type SanityDocument} from '@sanity/types' import {AvatarStack, Box, Flex, Heading, Stack, Text, useToast} from '@sanity/ui' import {useCallback, useEffect, useMemo, useState} from 'react' -import {useTableContext} from 'sanity/_singletons' import { BundleIconEditorPicker, @@ -14,6 +13,7 @@ import {type BundleDocument} from '../../../store/bundles/types' import {useAddonDataset} from '../../../studio/addonDataset/useAddonDataset' import {Chip} from '../../components/Chip' import {Table, type TableProps} from '../../components/Table/Table' +import {useTableContext} from '../../components/Table/TableProvider' import {type DocumentValidationStatus} from './bundleDocumentsValidation' import {DocumentActions} from './documentTable/DocumentActions' import {getDocumentTableColumnDefs} from './documentTable/DocumentTableColumnDefs'