From 08e269ecbbb3462b7e3ba61799bdbb5c203dd421 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 5 Sep 2024 10:36:08 +0200 Subject: [PATCH 01/16] refactor(sanity): update bundles metada to releases metadata --- .../_singletons/context/BundlesMetadataContext.ts | 12 ------------ .../_singletons/context/ReleasesMetadataContext.ts | 12 ++++++++++++ packages/sanity/src/_singletons/index.ts | 2 +- ...dataProvider.tsx => ReleasesMetadataProvider.tsx} | 12 ++++++------ .../core/releases/plugin/ReleasesStudioLayout.tsx | 2 +- .../src/core/releases/tool/useBundlesMetadata.ts | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 packages/sanity/src/_singletons/context/BundlesMetadataContext.ts create mode 100644 packages/sanity/src/_singletons/context/ReleasesMetadataContext.ts rename packages/sanity/src/core/releases/contexts/{BundlesMetadataProvider.tsx => ReleasesMetadataProvider.tsx} (89%) diff --git a/packages/sanity/src/_singletons/context/BundlesMetadataContext.ts b/packages/sanity/src/_singletons/context/BundlesMetadataContext.ts deleted file mode 100644 index f57635eda1d..00000000000 --- a/packages/sanity/src/_singletons/context/BundlesMetadataContext.ts +++ /dev/null @@ -1,12 +0,0 @@ -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/ReleasesMetadataContext.ts b/packages/sanity/src/_singletons/context/ReleasesMetadataContext.ts new file mode 100644 index 00000000000..cbe9a7b726e --- /dev/null +++ b/packages/sanity/src/_singletons/context/ReleasesMetadataContext.ts @@ -0,0 +1,12 @@ +import {createContext} from 'sanity/_createContext' + +import type {ReleasesMetadataContextValue} from '../../core/releases/contexts/ReleasesMetadataProvider' + +/** + * @internal + * @hidden + */ +export const ReleasesMetadataContext = createContext( + 'sanity/_singletons/context/releases-metadata', + null, +) diff --git a/packages/sanity/src/_singletons/index.ts b/packages/sanity/src/_singletons/index.ts index b61d32838f2..eef15b098d0 100644 --- a/packages/sanity/src/_singletons/index.ts +++ b/packages/sanity/src/_singletons/index.ts @@ -1,6 +1,5 @@ export * from './context/ActiveWorkspaceMatcherContext' export * from './context/AddonDatasetContext' -export * from './context/BundlesMetadataContext' export * from './context/CalendarContext' export * from './context/ChangeIndicatorTrackerContexts' export * from './context/ColorSchemeSetValueContext' @@ -44,6 +43,7 @@ export * from './context/PresenceTrackerContexts' export * from './context/PreviewCardContext' export * from './context/ReferenceInputOptionsContext' export * from './context/ReferenceItemRefContext' +export * from './context/ReleasesMetadataContext' export * from './context/ReleasesTableContext' export * from './context/ResourceCacheContext' export * from './context/ReviewChangesContext' diff --git a/packages/sanity/src/core/releases/contexts/BundlesMetadataProvider.tsx b/packages/sanity/src/core/releases/contexts/ReleasesMetadataProvider.tsx similarity index 89% rename from packages/sanity/src/core/releases/contexts/BundlesMetadataProvider.tsx rename to packages/sanity/src/core/releases/contexts/ReleasesMetadataProvider.tsx index f01fd7da60e..065d9f51fd8 100644 --- a/packages/sanity/src/core/releases/contexts/BundlesMetadataProvider.tsx +++ b/packages/sanity/src/core/releases/contexts/ReleasesMetadataProvider.tsx @@ -1,7 +1,7 @@ import {useCallback, useContext, useEffect, useMemo, useState} from 'react' import {useObservable} from 'react-rx' import {useBundlesStore} from 'sanity' -import {BundlesMetadataContext} from 'sanity/_singletons' +import {ReleasesMetadataContext} from 'sanity/_singletons' import {type MetadataWrapper} from '../../store/bundles/createBundlesMetadataAggregator' import {type BundlesMetadata} from '../tool/useBundlesMetadata' @@ -9,7 +9,7 @@ import {type BundlesMetadata} from '../tool/useBundlesMetadata' /** * @internal */ -export interface BundlesMetadataContextValue { +export interface ReleasesMetadataContextValue { state: MetadataWrapper addBundleIdsToListener: (slugs: string[]) => void removeBundleIdsFromListener: (slugs: string[]) => void @@ -88,20 +88,20 @@ const BundlesMetadataProviderInner = ({children}: {children: React.ReactNode}) = ) return ( - {children} + {children} ) } export const BundlesMetadataProvider = ({children}: {children: React.ReactNode}) => { - const context = useContext(BundlesMetadataContext) + const context = useContext(ReleasesMetadataContext) // Avoid mounting the provider if it's already provided by a parent if (context) return children return {children} } -export const useBundlesMetadataProvider = (): BundlesMetadataContextValue => { - const contextValue = useContext(BundlesMetadataContext) +export const useBundlesMetadataProvider = (): ReleasesMetadataContextValue => { + const contextValue = useContext(ReleasesMetadataContext) return ( contextValue || { diff --git a/packages/sanity/src/core/releases/plugin/ReleasesStudioLayout.tsx b/packages/sanity/src/core/releases/plugin/ReleasesStudioLayout.tsx index b946153f9c5..41abcbd8b91 100644 --- a/packages/sanity/src/core/releases/plugin/ReleasesStudioLayout.tsx +++ b/packages/sanity/src/core/releases/plugin/ReleasesStudioLayout.tsx @@ -1,6 +1,6 @@ import {type LayoutProps} from '../../config' import {AddonDatasetProvider} from '../../studio' -import {BundlesMetadataProvider} from '../contexts/BundlesMetadataProvider' +import {BundlesMetadataProvider} from '../contexts/ReleasesMetadataProvider' export function ReleasesStudioLayout(props: LayoutProps) { // TODO: Replace for useReleasesEnabled diff --git a/packages/sanity/src/core/releases/tool/useBundlesMetadata.ts b/packages/sanity/src/core/releases/tool/useBundlesMetadata.ts index cf4e9378690..318ce2eb560 100644 --- a/packages/sanity/src/core/releases/tool/useBundlesMetadata.ts +++ b/packages/sanity/src/core/releases/tool/useBundlesMetadata.ts @@ -1,6 +1,6 @@ import {useEffect, useState} from 'react' -import {useBundlesMetadataProvider} from '../contexts/BundlesMetadataProvider' +import {useBundlesMetadataProvider} from '../contexts/ReleasesMetadataProvider' export interface BundlesMetadata { /** From 9822704533d7e169a8ab458a9a98df3c19aa35d1 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 5 Sep 2024 10:47:55 +0200 Subject: [PATCH 02/16] refactor(sanity): rename bundlebadge to releasebadge --- .../core/bundles/components/BundlesMenu.tsx | 4 +-- .../{BundleBadge.tsx => ReleaseBadge.tsx} | 4 +-- .../dialog/BundleIconEditorPicker.tsx | 4 +-- .../dialog/__tests__/BundleForm.test.tsx | 26 +++++++++---------- .../src/core/bundles/components/index.ts | 2 +- packages/sanity/src/core/index.ts | 2 +- .../overview/ReleasesOverviewColumnDefs.tsx | 4 +-- .../perspective/GlobalPerspectiveMenu.tsx | 4 +-- .../perspective/DocumentPerspectiveMenu.tsx | 10 +++++-- 9 files changed, 33 insertions(+), 27 deletions(-) rename packages/sanity/src/core/bundles/components/{BundleBadge.tsx => ReleaseBadge.tsx} (96%) diff --git a/packages/sanity/src/core/bundles/components/BundlesMenu.tsx b/packages/sanity/src/core/bundles/components/BundlesMenu.tsx index 402c22e1b9c..bf44bf949c1 100644 --- a/packages/sanity/src/core/bundles/components/BundlesMenu.tsx +++ b/packages/sanity/src/core/bundles/components/BundlesMenu.tsx @@ -11,7 +11,7 @@ import {useBundles} from '../../store/bundles/useBundles' import {usePerspective} from '../hooks' import {LATEST} from '../util/const' import {isDraftOrPublished} from '../util/util' -import {BundleBadge} from './BundleBadge' +import {ReleaseBadge} from './ReleaseBadge' const StyledMenu = styled(Menu)` min-width: 200px; @@ -103,7 +103,7 @@ export const BundlesMenu = memo(function BundlesMenu(props: BundleListProps): Re placement="bottom-start" > - diff --git a/packages/sanity/src/core/bundles/components/dialog/BundleIconEditorPicker.tsx b/packages/sanity/src/core/bundles/components/dialog/BundleIconEditorPicker.tsx index 4288e580e59..aedf30befa0 100644 --- a/packages/sanity/src/core/bundles/components/dialog/BundleIconEditorPicker.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/BundleIconEditorPicker.tsx @@ -7,7 +7,7 @@ import {styled} from 'styled-components' import {Button, Popover, TooltipDelayGroupProvider} from '../../../../ui-components' import {type BundleDocument} from '../../../store/bundles/types' -import {BundleBadge} from '../BundleBadge' +import {ReleaseBadge} from '../ReleaseBadge' const StyledStack = styled(Stack)` border-top: 1px solid var(--card-border-color); @@ -134,7 +134,7 @@ export function BundleIconEditorPicker(props: { data-testid="icon-picker-button" > - + diff --git a/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx b/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx index 9339b53b7a5..04b978ebf52 100644 --- a/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx @@ -68,41 +68,41 @@ describe('BundleForm', () => { }) it('should render the form fields', () => { - expect(screen.getByTestId('bundle-form-title')).toBeInTheDocument() - expect(screen.getByTestId('bundle-form-description')).toBeInTheDocument() - //expect(screen.getByTestId('bundle-form-publish-at')).toBeInTheDocument() + expect(screen.getByTestId('release-form-title')).toBeInTheDocument() + expect(screen.getByTestId('release-form-description')).toBeInTheDocument() + //expect(screen.getByTestId('release-form-publish-at')).toBeInTheDocument() }) it('should call onChange when title input value changes', () => { - const titleInput = screen.getByTestId('bundle-form-title') + const titleInput = screen.getByTestId('release-form-title') fireEvent.change(titleInput, {target: {value: 'Bundle 1'}}) expect(onChangeMock).toHaveBeenCalledWith({...valueMock, title: 'Bundle 1'}) }) it('should call onChange when description textarea value changes', () => { - const descriptionTextarea = screen.getByTestId('bundle-form-description') + const descriptionTextarea = screen.getByTestId('release-form-description') fireEvent.change(descriptionTextarea, {target: {value: 'New Description'}}) expect(onChangeMock).toHaveBeenCalledWith({...valueMock, description: 'New Description'}) }) /*it('should call onChange when publishAt input value changes', () => { - const publishAtInput = screen.getByTestId('bundle-form-publish-at') + const publishAtInput = screen.getByTestId('release-form-publish-at') fireEvent.change(publishAtInput, {target: {value: '2022-01-01'}}) expect(onChangeMock).toHaveBeenCalledWith({...valueMock, publishAt: '2022-01-01'}) }) it('should call onChange with undefined when publishAt input value is empty', () => { - const publishAtInput = screen.getByTestId('bundle-form-publish-at') + const publishAtInput = screen.getByTestId('release-form-publish-at') fireEvent.change(publishAtInput, {target: {value: ' '}}) expect(onChangeMock).toHaveBeenCalledWith({...valueMock, publishAt: ''}) })*/ /*it('should show an error when the publishAt input value is invalid', () => { - const publishAtInput = screen.getByTestId('bundle-form-publish-at') + const publishAtInput = screen.getByTestId('release-form-publish-at') fireEvent.change(publishAtInput, {target: {value: 'invalid-date'}}) expect(screen.getByTestId('input-validation-icon-error')).toBeInTheDocument() @@ -155,7 +155,7 @@ describe('BundleForm', () => { }) it('should allow for any title to be used', async () => { - const titleInput = screen.getByTestId('bundle-form-title') + const titleInput = screen.getByTestId('release-form-title') expect(titleInput).toHaveValue(existingBundleValue.title) // the slug of this title already exists, // but the slug for the existing edited bundle will not be changed @@ -165,12 +165,12 @@ describe('BundleForm', () => { }) it('should populate the form with the existing bundle values', () => { - expect(screen.getByTestId('bundle-form-title')).toHaveValue(existingBundleValue.title) - expect(screen.getByTestId('bundle-form-description')).toHaveValue( + expect(screen.getByTestId('release-form-title')).toHaveValue(existingBundleValue.title) + expect(screen.getByTestId('release-form-description')).toHaveValue( existingBundleValue.description, ) - screen.getByTestId('bundle-badge-color-magenta') - screen.getByTestId('bundle-badge-icon-heart-filled') + screen.getByTestId('release-badge-color-magenta') + screen.getByTestId('release-badge-icon-heart-filled') }) }) }) diff --git a/packages/sanity/src/core/bundles/components/index.ts b/packages/sanity/src/core/bundles/components/index.ts index 1d65239d954..3e293e8c4f7 100644 --- a/packages/sanity/src/core/bundles/components/index.ts +++ b/packages/sanity/src/core/bundles/components/index.ts @@ -1,3 +1,3 @@ -export * from './BundleBadge' export * from './BundlesMenu' export * from './panes/BundleActions' +export * from './ReleaseBadge' diff --git a/packages/sanity/src/core/index.ts b/packages/sanity/src/core/index.ts index 1ad13634a2d..92ebe717704 100644 --- a/packages/sanity/src/core/index.ts +++ b/packages/sanity/src/core/index.ts @@ -1,9 +1,9 @@ export { BundleActions, - BundleBadge, BundlesMenu, getDocumentIsInPerspective, LATEST, + ReleaseBadge, useDocumentVersions, usePerspective, } from './bundles' diff --git a/packages/sanity/src/core/releases/tool/overview/ReleasesOverviewColumnDefs.tsx b/packages/sanity/src/core/releases/tool/overview/ReleasesOverviewColumnDefs.tsx index 1e09d6175cd..9bf6263c364 100644 --- a/packages/sanity/src/core/releases/tool/overview/ReleasesOverviewColumnDefs.tsx +++ b/packages/sanity/src/core/releases/tool/overview/ReleasesOverviewColumnDefs.tsx @@ -3,7 +3,7 @@ import {type TFunction, Translate, useTranslation} from 'sanity' import {useRouter} from 'sanity/router' import {Tooltip} from '../../../../ui-components' -import {BundleBadge} from '../../../bundles' +import {ReleaseBadge} from '../../../bundles' import {RelativeTime, UserAvatar} from '../../../components' import {type TableRowProps} from '../../components/Table/Table' import {Headers} from '../../components/Table/TableHeader' @@ -36,7 +36,7 @@ const ReleaseNameCell: Column['cell'] = ({cellProps, datum: bundle} - + diff --git a/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx b/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx index 04b1b88e138..b5667262f05 100644 --- a/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx +++ b/packages/sanity/src/core/studio/components/navbar/perspective/GlobalPerspectiveMenu.tsx @@ -5,9 +5,9 @@ import {useCallback, useMemo, useState} from 'react' import {useTranslation} from 'sanity' import {MenuItem} from '../../../../../ui-components' -import {BundleBadge} from '../../../../bundles/components/BundleBadge' import {BundlesMenu} from '../../../../bundles/components/BundlesMenu' import {BundleDetailsDialog} from '../../../../bundles/components/dialog/BundleDetailsDialog' +import {ReleaseBadge} from '../../../../bundles/components/ReleaseBadge' import {usePerspective} from '../../../../bundles/hooks/usePerspective' import {useBundles} from '../../../../store/bundles' @@ -37,7 +37,7 @@ export function GlobalPerspectiveMenu(): JSX.Element { const bundleMenuButton = useMemo( () => ( ), [hue, icon, title], diff --git a/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveMenu.tsx b/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveMenu.tsx index 4740a8fe26a..e742e2ad8ec 100644 --- a/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveMenu.tsx +++ b/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveMenu.tsx @@ -4,7 +4,13 @@ import {Box, Button} from '@sanity/ui' // eslint-disable-next-line camelcase import {getTheme_v2} from '@sanity/ui/theme' import {memo, useMemo} from 'react' -import {BundleBadge, type BundleDocument, BundlesMenu, usePerspective, useTranslation} from 'sanity' +import { + type BundleDocument, + BundlesMenu, + ReleaseBadge, + usePerspective, + useTranslation, +} from 'sanity' import {IntentLink} from 'sanity/router' import {css, styled} from 'styled-components' @@ -45,7 +51,7 @@ const ReleaseLink = ({release}: {release: Partial}) => { rel="noopener noreferrer" as={IntentLink} > - + ) } From bfc69d902ca1a68f585521c231a83faa4957b8a7 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 5 Sep 2024 10:59:24 +0200 Subject: [PATCH 03/16] refactor(sanity): rename bundlesMenu to ReleasesMenu --- .../{BundlesMenu.tsx => ReleasesMenu.tsx} | 6 ++--- ...lesMenu.test.tsx => ReleasesMenu.test.tsx} | 26 +++++++++---------- .../src/core/bundles/components/index.ts | 2 +- packages/sanity/src/core/index.ts | 2 +- .../BundleMenuButton/BundleMenuButton.tsx | 2 +- .../detail/__tests__/ReleaseReview.test.tsx | 4 +-- .../detail/__tests__/ReleaseSummary.test.tsx | 4 +-- .../perspective/GlobalPerspectiveMenu.tsx | 4 +-- .../perspective/DocumentPerspectiveMenu.tsx | 8 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) rename packages/sanity/src/core/bundles/components/{BundlesMenu.tsx => ReleasesMenu.tsx} (97%) rename packages/sanity/src/core/bundles/components/__tests__/{BundlesMenu.test.tsx => ReleasesMenu.test.tsx} (89%) diff --git a/packages/sanity/src/core/bundles/components/BundlesMenu.tsx b/packages/sanity/src/core/bundles/components/ReleasesMenu.tsx similarity index 97% rename from packages/sanity/src/core/bundles/components/BundlesMenu.tsx rename to packages/sanity/src/core/bundles/components/ReleasesMenu.tsx index bf44bf949c1..68028378941 100644 --- a/packages/sanity/src/core/bundles/components/BundlesMenu.tsx +++ b/packages/sanity/src/core/bundles/components/ReleasesMenu.tsx @@ -33,7 +33,7 @@ interface BundleListProps { /** * @internal */ -export const BundlesMenu = memo(function BundlesMenu(props: BundleListProps): ReactElement { +export const ReleasesMenu = memo(function ReleasesMenu(props: BundleListProps): ReactElement { const {bundles, loading, actions, button, perspective} = props const {deletedBundles} = useBundles() const {currentGlobalBundle, setPerspective} = usePerspective(perspective) @@ -64,9 +64,9 @@ export const BundlesMenu = memo(function BundlesMenu(props: BundleListProps): Re <> + {loading ? ( diff --git a/packages/sanity/src/core/bundles/components/__tests__/BundlesMenu.test.tsx b/packages/sanity/src/core/bundles/components/__tests__/ReleasesMenu.test.tsx similarity index 89% rename from packages/sanity/src/core/bundles/components/__tests__/BundlesMenu.test.tsx rename to packages/sanity/src/core/bundles/components/__tests__/ReleasesMenu.test.tsx index 87343ccce82..72c17a3b568 100644 --- a/packages/sanity/src/core/bundles/components/__tests__/BundlesMenu.test.tsx +++ b/packages/sanity/src/core/bundles/components/__tests__/ReleasesMenu.test.tsx @@ -8,7 +8,7 @@ import {createTestProvider} from '../../../../../test/testUtils/TestProvider' import {Button} from '../../../../ui-components' import {usePerspective} from '../../hooks/usePerspective' import {LATEST} from '../../util/const' -import {BundlesMenu} from '../BundlesMenu' +import {ReleasesMenu} from '../ReleasesMenu' jest.mock('../../hooks/usePerspective', () => ({ usePerspective: jest.fn().mockReturnValue({ @@ -27,7 +27,7 @@ jest.mock('../../../store/bundles/useBundles', () => ({ const mockUseBundles = useBundles as jest.Mock -describe('BundlesMenu', () => { +describe('ReleasesMenu', () => { const mockUsePerspective = usePerspective as jest.Mock const ButtonTest =