From 1680f5248016b2a29192c2a5a0eaa0a83b742e42 Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Mon, 28 Oct 2024 15:53:42 +0100 Subject: [PATCH] fix(core): remove releases menu --- packages/sanity/src/core/index.ts | 1 - .../core/releases/components/ReleasesMenu.tsx | 148 ---------- .../__tests__/ReleasesMenu.test.tsx | 263 ------------------ .../src/core/releases/components/index.ts | 1 - .../detail/__tests__/ReleaseReview.test.tsx | 4 - .../detail/__tests__/ReleaseSummary.test.tsx | 4 - 6 files changed, 421 deletions(-) delete mode 100644 packages/sanity/src/core/releases/components/ReleasesMenu.tsx delete mode 100644 packages/sanity/src/core/releases/components/__tests__/ReleasesMenu.test.tsx 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 =