-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(COREL): refactor version context & renaming (#7071)
* 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 * chore(sanity): update LATEST type to Partial * refactor(sanity): make single bundle menu + clean up * chore(sanity): remove warnings comments * refactor(sanity): move version provider to its own file + organise + add useVersion * refactor(sanity): remove provider + context, move logic to hook * chore(sanity): remove comments + change name from setCurrentVersion to setGlobalBundle * chore(sanity): rename useVersion to useBundle * chore(sanity): update comments * chore(sanity): Rename currentVersion * refactor(sanity): rename currentBudnle and setGlobalBundle * chore(sanity): rename versions to bundles in core directory * chore(sanity): rename to GlobalPerspectiveMenu and move to navbar directory * chore(sanity): rename to DocumentPerspectiveMenu and move to navbar directory * chore(sanity): remove isDraft from usePerspective, add new util * refactor(sanity): remove isDraft * refactor(sanity): use current global in the bundle badge
- Loading branch information
Showing
20 changed files
with
125 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
packages/sanity/src/_singletons/context/VersionContext.tsx
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {useRouter} from 'sanity/router' | ||
|
||
import {useBundlesStore} from '../../store/bundles' | ||
import {type BundleDocument} from '../../store/bundles/types' | ||
import {LATEST} from '../util/const' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface VersionContextValue { | ||
/* Return the current global bundle */ | ||
currentGlobalBundle: Partial<BundleDocument> | ||
/* Change the perspective in the studio based on the perspective name */ | ||
setPerspective: (name: string) => void | ||
} | ||
|
||
export function usePerspective(): VersionContextValue { | ||
const router = useRouter() | ||
const {data: bundles} = useBundlesStore() | ||
|
||
const setPerspective = (name: string | undefined) => { | ||
if (name === 'drafts') { | ||
router.navigateStickyParam('perspective', '') | ||
} else { | ||
router.navigateStickyParam('perspective', `bundle.${name}`) | ||
} | ||
} | ||
const selectedBundle = | ||
router.stickyParams?.perspective && bundles | ||
? bundles.find((bundle: Partial<BundleDocument>) => { | ||
return ( | ||
`bundle.${bundle.name}`.toLocaleLowerCase() === | ||
router.stickyParams.perspective?.toLocaleLowerCase() | ||
) | ||
}) | ||
: LATEST | ||
|
||
const currentGlobalBundle = selectedBundle || LATEST | ||
|
||
return { | ||
setPerspective, | ||
currentGlobalBundle, | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.