From cbc385c1ca9168bba7590ccff9ec7a9d6b829895 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Fri, 5 Jul 2024 10:19:26 +0200 Subject: [PATCH] feat(COREL): update types to bundle + add create bundle functionality (#7047) * refactor(sanity): update types to bundle * feat(sanity): add ability to create releases from dialog + update types * feat(sanity): update list on global and document to use store * feat(sanity): update types, add icon and hue picker to bundles, update uis * feat(sanity): add date picker to bundleform * refactor(sanity): update publishAt fields in menus * refactor(sanity): update type in dummyGetter * chore(sanity): remove BUNDLES const * chore(sanity): update LATEST type to Partial * chore(sanity): update validation for bundle date creation * chore(sanity): clean up code * refactor(sanity): add archived filter * refactor(sanity): make single bundle menu + clean up * chore(sanity): add missing properties * feat(sanity): add loading & remove unused code * feat(sanity): add loading to document version, update filter * chore(sanity): rename VersionBadge to BundleBadge * chore(sanity): clean up methods and style * chore(sanity): remove unused import * refactor(sanity): use Bundle provider instead of store * chore(sanity): update bundleRow to use the new name for badge * chore(sanity): clean up code * refactor(sanity): re-add oncancel and oncreate props in dialog * refactor(sanity): add scroll to bundle menu * refactor(sanity): move from archived to archivedAt * refactor(sanity): only show the list of bundles if it has more than published / drafts * chore(sanity): remove warnings comments --- .eslintrc.cjs | 2 +- .../_singletons/context/VersionContext.tsx | 30 ++- .../components/BundlesTable/BundleRow.tsx | 4 +- .../__workshop__/BundlesStoreStory.tsx | 4 +- .../bundles/__workshop__/ReleaseForm.tsx | 133 ---------- .../sanity/src/core/store/bundles/types.ts | 4 +- .../sanity/src/core/studio/StudioProvider.tsx | 15 +- .../{VersionBadge.tsx => BundleBadge.tsx} | 20 +- .../core/versions/components/BundleMenu.tsx | 132 ++++++++++ .../versions/components/GlobalBundleMenu.tsx | 112 ++------ .../versions/components/dialog/BundleForm.tsx | 193 ++++++++------ .../dialog/BundleIconEditorPicker.tsx | 119 +++++++++ .../components/dialog/CreateBundleDialog.tsx | 88 ++++--- .../components/panes/BundleActions.tsx | 83 +++--- .../components/panes/DocumentVersionMenu.tsx | 248 ++---------------- packages/sanity/src/core/versions/types.ts | 27 -- .../sanity/src/core/versions/util/const.ts | 35 +-- .../src/core/versions/util/dummyGetters.ts | 18 +- .../header/DocumentHeaderTitle.tsx | 11 +- .../statusBar/DocumentStatusBarActions.tsx | 9 +- 20 files changed, 558 insertions(+), 729 deletions(-) delete mode 100644 packages/sanity/src/core/store/bundles/__workshop__/ReleaseForm.tsx rename packages/sanity/src/core/versions/components/{VersionBadge.tsx => BundleBadge.tsx} (50%) create mode 100644 packages/sanity/src/core/versions/components/BundleMenu.tsx create mode 100644 packages/sanity/src/core/versions/components/dialog/BundleIconEditorPicker.tsx delete mode 100644 packages/sanity/src/core/versions/types.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 89685003ac60..1b2be812bbda 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -164,7 +164,7 @@ const config = { // Ignore i18n in releases files. TODO: Remove this before moving releases to GA. { - files: ['**/*/core/releases/**/*'], + files: ['**/*/core/releases/**/*', '**/*/core/versions/**/*'], rules: { 'i18next/no-literal-string': 'off', '@sanity/i18n/no-attribute-string-literals': 'off', diff --git a/packages/sanity/src/_singletons/context/VersionContext.tsx b/packages/sanity/src/_singletons/context/VersionContext.tsx index 0c5347a12860..19e98b7376c3 100644 --- a/packages/sanity/src/_singletons/context/VersionContext.tsx +++ b/packages/sanity/src/_singletons/context/VersionContext.tsx @@ -4,14 +4,15 @@ // eslint-disable-next-line import/consistent-type-specifier-style import {createContext, type ReactElement} from 'react' -import type {Version} from '../../../core/versions/types' -import {BUNDLES, LATEST} from '../../../core/versions/util/const' +import {useBundlesStore} from '../../../core/store/bundles' +import type {BundleDocument} from '../../../core/store/bundles/types' +import {LATEST} from '../../../core/versions/util/const' import {useRouter} from '../../../router' export interface VersionContextValue { - currentVersion: Version + currentVersion: Partial isDraft: boolean - setCurrentVersion: (version: Version) => void + setCurrentVersion: (bundle: Partial) => void } export const VersionContext = createContext({ @@ -27,7 +28,9 @@ interface VersionProviderProps { export function VersionProvider({children}: VersionProviderProps): JSX.Element { const router = useRouter() - const setCurrentVersion = (version: Version) => { + const {data: bundles} = useBundlesStore() + + const setCurrentVersion = (version: Partial) => { const {name} = version if (name === 'drafts') { router.navigateStickyParam('perspective', '') @@ -35,14 +38,15 @@ export function VersionProvider({children}: VersionProviderProps): JSX.Element { router.navigateStickyParam('perspective', `bundle.${name}`) } } - const selectedVersion = router.stickyParams?.perspective - ? BUNDLES.find((bundle) => { - return ( - `bundle.${bundle.name}`.toLocaleLowerCase() === - router.stickyParams.perspective?.toLocaleLowerCase() - ) - }) - : LATEST + const selectedVersion = + router.stickyParams?.perspective && bundles + ? bundles.find((bundle) => { + return ( + `bundle.${bundle.name}`.toLocaleLowerCase() === + router.stickyParams.perspective?.toLocaleLowerCase() + ) + }) + : LATEST const currentVersion = selectedVersion || LATEST diff --git a/packages/sanity/src/core/releases/components/BundlesTable/BundleRow.tsx b/packages/sanity/src/core/releases/components/BundlesTable/BundleRow.tsx index 0d07558de412..149e13c720f5 100644 --- a/packages/sanity/src/core/releases/components/BundlesTable/BundleRow.tsx +++ b/packages/sanity/src/core/releases/components/BundlesTable/BundleRow.tsx @@ -3,7 +3,7 @@ import {RelativeTime} from 'sanity' import {useRouter} from 'sanity/router' import {type BundleDocument} from '../../../store/bundles/types' -import {VersionBadge} from '../../../versions/components/VersionBadge' +import {BundleBadge} from '../../../versions/components/BundleBadge' import {BundleMenuButton} from '../BundleMenuButton/BundleMenuButton' type Props = { @@ -26,7 +26,7 @@ export function BundleRow({bundle}: Props) { > - + diff --git a/packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx b/packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx index 8e482dda7d4c..240173ec6e7b 100644 --- a/packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx +++ b/packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx @@ -4,10 +4,10 @@ import {type ComponentType, type FormEvent, useCallback, useState} from 'react' import {Button} from '../../../../ui-components' import {LoadingBlock} from '../../../components/loadingBlock/LoadingBlock' import {AddonDatasetProvider} from '../../../studio/addonDataset/AddonDatasetProvider' +import {BundleForm} from '../../../versions/components/dialog/BundleForm' import {BundlesProvider, useBundles} from '../BundlesProvider' import {type BundleDocument} from '../types' import {useBundleOperations} from '../useBundleOperations' -import {ReleaseForm} from './ReleaseForm' const WithAddonDatasetProvider =

(Component: ComponentType

): React.FC

=> { const WrappedComponent: React.FC

= (props) => ( @@ -66,7 +66,7 @@ const BundlesStoreStory = () => {

Create a new release - +