diff --git a/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts b/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts new file mode 100644 index 00000000000..919100555af --- /dev/null +++ b/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts @@ -0,0 +1,34 @@ +import {createContext, useContext} from 'react' + +/** + * @internal + */ +export interface TableContextValue { + searchTerm: string | null + setSearchTerm: (searchTerm: string) => void + sort: {column: string; direction: 'asc' | 'desc'} | null + setSearchColumn: (column: string) => void +} + +const DEFAULT_TABLE_CONTEXT: TableContextValue = { + searchTerm: null, + setSearchTerm: () => null, + sort: null, + setSearchColumn: () => 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 13eef94f34f..2b8dd1caf58 100644 --- a/packages/sanity/src/_singletons/index.ts +++ b/packages/sanity/src/_singletons/index.ts @@ -26,6 +26,7 @@ export * from './core/form/studio/ValidationContext' export * from './core/i18n/LocaleContext' export * from './core/presence/FormFieldPresenceContext' export * from './core/releases/BundlesMetadataContext' +export * from './core/releases/ReleasesTableContext' export * from './core/schedulePublishing/DocumentActionPropsContext' export * from './core/schedulePublishing/tool/ScheduledPublishingEnabledContext' export * from './core/schedulePublishing/tool/SchedulePublishingUpsellContext' diff --git a/packages/sanity/src/core/bundles/components/BundleBadge.tsx b/packages/sanity/src/core/bundles/components/BundleBadge.tsx index d2926cc58dd..bcb6a3f763c 100644 --- a/packages/sanity/src/core/bundles/components/BundleBadge.tsx +++ b/packages/sanity/src/core/bundles/components/BundleBadge.tsx @@ -1,5 +1,5 @@ -import {hues} from '@sanity/color' -import {ChevronDownIcon, Icon} from '@sanity/icons' +import {type ColorHueKey, hues} from '@sanity/color' +import {ChevronDownIcon, Icon, type IconSymbol} from '@sanity/icons' // eslint-disable-next-line camelcase import {Box, Flex, rgba, Text, useTheme_v2} from '@sanity/ui' import {type CSSProperties} from 'react' @@ -10,7 +10,15 @@ import {type BundleDocument} from '../../store/bundles/types' * @internal */ export function BundleBadge( - props: Partial & {openButton?: boolean; padding?: number; title?: string}, + props: Partial< + BundleDocument & { + icon: IconSymbol + hue: ColorHueKey + openButton: boolean + padding: number + title: string + } + >, ): JSX.Element { const {hue = 'gray', icon, openButton, padding = 3, title} = props const {color} = useTheme_v2() diff --git a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx index 4f6bd007e3a..6306151daf4 100644 --- a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx +++ b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx @@ -98,6 +98,7 @@ export const BundleMenuButton = ({bundle, documentCount}: Props) => { padding={bundleHasDocuments} footer={{ confirmButton: { + text: 'Delete', tone: 'default', onClick: handleOnDeleteBundle, loading: discardStatus === 'discarding', diff --git a/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx b/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx index 79241eab7a2..55a58497a12 100644 --- a/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx +++ b/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx @@ -116,7 +116,7 @@ describe('BundleMenuButton', () => { screen.getByText('This will also delete 2 document versions', {exact: false}) await act(() => { - fireEvent.click(screen.getByText('Confirm')) + fireEvent.click(screen.getByText('Delete')) }) expect(useBundleOperations().deleteBundle).toHaveBeenCalledWith(activeBundle) @@ -149,7 +149,7 @@ describe('BundleMenuButton', () => { expect(screen.queryByTestId('confirm-delete-body')).toBeNull() await act(() => { - fireEvent.click(screen.getByText('Confirm')) + fireEvent.click(screen.getByText('Delete')) }) expect(useBundleOperations().deleteBundle).toHaveBeenCalledWith(activeEmptyBundle) diff --git a/packages/sanity/src/core/releases/components/ReleasesTable/ReleaseHeader.tsx b/packages/sanity/src/core/releases/components/ReleasesTable/ReleaseHeader.tsx deleted file mode 100644 index f2189840dee..00000000000 --- a/packages/sanity/src/core/releases/components/ReleasesTable/ReleaseHeader.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import {SearchIcon} from '@sanity/icons' -import {Box, Button, Card, Flex, Stack, Text, TextInput} from '@sanity/ui' - -/** - * @internal - */ -export interface ReleaseHeaderProps { - searchDisabled?: boolean - searchTerm?: string - setSearchTerm: (value?: string) => void -} - -export function ReleaseHeader({searchDisabled, searchTerm, setSearchTerm}: ReleaseHeaderProps) { - return ( - - - {/* Title */} - - setSearchTerm(event.currentTarget.value)} - onClear={() => setSearchTerm('')} - clearButton={!!searchTerm} - /> - - {/* Number of documents */} - - - - Documents - - - - {/* Created */} - -