diff --git a/packages/sanity/src/core/index.ts b/packages/sanity/src/core/index.ts index 78e87ca8c41..24882c7d1d6 100644 --- a/packages/sanity/src/core/index.ts +++ b/packages/sanity/src/core/index.ts @@ -37,7 +37,6 @@ export { ReleaseAvatar, ReleaseBadge, ReleaseForm, - ReleasesMenu, useDocumentVersions, usePerspective, useVersionOperations, diff --git a/packages/sanity/src/core/releases/components/ReleasesMenu.tsx b/packages/sanity/src/core/releases/components/ReleasesMenu.tsx deleted file mode 100644 index e9afcda7046..00000000000 --- a/packages/sanity/src/core/releases/components/ReleasesMenu.tsx +++ /dev/null @@ -1,148 +0,0 @@ -import {CheckmarkIcon} from '@sanity/icons' -// eslint-disable-next-line no-restricted-imports -- MenuItem requires props, only supported by @sanity/ui -import {Box, Flex, Menu, MenuDivider, MenuItem, Spinner, Text} from '@sanity/ui' -import {memo, type ReactElement, useCallback, useMemo} from 'react' -import {styled} from 'styled-components' - -import {MenuButton, Tooltip} from '../../../ui-components' -import {useTranslation} from '../../i18n' -import {type ReleaseDocument} from '../../store/release/types' -import {usePerspective} from '../hooks' -import {LATEST} from '../util/const' -import {ReleaseBadge} from './ReleaseBadge' - -const StyledMenu = styled(Menu)` - min-width: 200px; -` - -const StyledBox = styled(Box)` - overflow: auto; - max-height: 200px; -` - -interface BundleListProps { - button: ReactElement - releases: ReleaseDocument[] | null - loading: boolean - actions?: ReactElement -} - -/** - * @internal - */ -export const ReleasesMenu = memo(function ReleasesMenu(props: BundleListProps): ReactElement { - const {releases, loading, actions, button} = props - const {currentGlobalBundle, setPerspectiveFromRelease} = usePerspective() - const {t} = useTranslation() - - const sortedBundlesToDisplay = useMemo(() => { - if (!releases) return [] - - return releases.filter(({state}) => state !== 'archived') - }, [releases]) - const hasBundles = sortedBundlesToDisplay.length > 0 - - const handleReleaseChange = useCallback( - (releaseId: string) => () => { - setPerspectiveFromRelease(releaseId) - }, - [setPerspectiveFromRelease], - ) - - return ( - <> - - {loading ? ( - - - - ) : ( - <> - - ) : undefined - } - onClick={handleReleaseChange('drafts')} - pressed={false} - text={LATEST.metadata.title} - data-testid="latest-menu-item" - /> - {hasBundles && ( - <> - - - {sortedBundlesToDisplay.map((release) => ( - - - - - - - - {release.metadata.title} - - - - {/* - - {release.publishAt ? ( - - ) : ( - 'No target date' - )} - - */} - - - - - - - - - - ))} - - - )} - - {actions && ( - <> - - {actions} - - )} - - )} - - } - popover={{ - placement: 'bottom-start', - portal: true, - zOffset: 3000, - }} - /> - - ) -}) diff --git a/packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx b/packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx deleted file mode 100644 index 7dd1bac1ac0..00000000000 --- a/packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx +++ /dev/null @@ -1,263 +0,0 @@ -import {fireEvent, render, screen, within} from '@testing-library/react' -import userEvent from '@testing-library/user-event' -import {act} from 'react' -import {beforeEach, describe, expect, it, type Mock, vi} from 'vitest' - -import {createTestProvider} from '../../../../../test/testUtils/TestProvider' -import {Button} from '../../../../ui-components' -import {type ReleaseDocument, useReleases} from '../../../store' -import {RELEASE_DOCUMENT_TYPE} from '../../../store/release/constants' -import {usePerspective} from '../../hooks/usePerspective' -import {LATEST} from '../../util/const' -import {ReleasesMenu} from '../ReleasesMenu' - -vi.mock('../../hooks/usePerspective', () => ({ - usePerspective: vi.fn().mockReturnValue({ - currentGlobalBundle: {}, - setPerspectiveFromRelease: vi.fn(), - }), -})) - -vi.mock('../../util/util', () => ({ - isDraftOrPublished: vi.fn(), -})) - -vi.mock('../../../store/release/useReleases', () => ({ - useReleases: vi.fn().mockReturnValue({}), -})) - -const mockUseReleases = useReleases as Mock - -const TEST_RELEASE: ReleaseDocument = { - _id: 'some-id', - _type: RELEASE_DOCUMENT_TYPE, - // yesterday - _createdAt: '2024-10-22T13:18:59.207Z', - _updatedAt: '2024-10-22T13:18:59.207Z', - name: 'Release Foo', - state: 'active', - finalDocumentStates: [], - createdBy: 'User 1', - metadata: { - icon: 'drop', - description: '', - title: '', - releaseType: 'asap', - hue: 'magenta', - }, -} - -describe('ReleasesMenu', () => { - const mockUsePerspective = usePerspective as Mock - const ButtonTest =