-
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.
feat(corel): doc and structure updates (#7039)
* docs(sanity): update comment on getAllVersionsOfDocument * fix(sanity): listing existing versions didn't account for published * chore(sanity): move latest version up (temp) * feat(sanity): update navigation of perspective + add "current badge" * feat(sanity): add global version navigation * refactor(sanity): hide document version picker, update the document icon * feat(sanity): update studio nav bar (reduce create button + spacing) * chore(sanity): general cleanup * feat(sanity): add version provider, hide only the version picker in document * chore(sanity): clean up version context * chore(sanity): clean up, move components & files to single folder * chore(sanity): clean up, move components & files to single folder * chore(sanity): add ready button to document footer * refactor(sanity): remove isVersion and add frontend guardrails * chore(sanity): clean duplicate component * chore(sanity): clean up missing dependencies * refactor(sanity): update button * refactor(sanity): clear up naming * chore(sanity): hide ready * chore(sanity): ready todos * feat(sanity): add bundle modal + update colours + remove add new version from doc * refactor(sanity): rename from release to bundle * refactor(sanity): clean up code for types (bundleform) * refactor(sanity): update method * refactor(sanity): update drafts name (draft -> drafts) in LATEST & context * refactor(sanity): use handleBundleChange instead of two separate methods * refactor(sanity): update title to use LATEST const * refactor(sanity): update draft filtering and checks (global and document level) * refactor(sanity): update context to rely on router & update query to match existing bundles (MOCK) * refactor(sanity): update handle methods to have callback * feat(sanity): add guardrails for title naming on bundle create * docs(sanity): update comments to potentially move things to plugin * refactor(sanity): merge version badges & icons * refactor(sanity): use speakingurl instead of toSlug
- Loading branch information
Showing
18 changed files
with
810 additions
and
258 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/sanity/src/_singletons/context/VersionContext.tsx
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,58 @@ | ||
// eslint-disable-next-line no-warning-comments | ||
/* TODO DO WE STILL NEED THIS AFTER THE STORES ARE SET UP? */ | ||
|
||
// 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 {useRouter} from '../../../router' | ||
|
||
export interface VersionContextValue { | ||
currentVersion: Version | ||
isDraft: boolean | ||
setCurrentVersion: (version: Version) => void | ||
} | ||
|
||
export const VersionContext = createContext<VersionContextValue>({ | ||
currentVersion: LATEST, | ||
isDraft: true, | ||
// eslint-disable-next-line no-empty-function | ||
setCurrentVersion: () => {}, | ||
}) | ||
|
||
interface VersionProviderProps { | ||
children: ReactElement | ||
} | ||
|
||
export function VersionProvider({children}: VersionProviderProps): JSX.Element { | ||
const router = useRouter() | ||
const setCurrentVersion = (version: Version) => { | ||
const {name} = version | ||
if (name === 'drafts') { | ||
router.navigateStickyParam('perspective', '') | ||
} else { | ||
router.navigateStickyParam('perspective', `bundle.${name}`) | ||
} | ||
} | ||
const selectedVersion = router.stickyParams?.perspective | ||
? BUNDLES.find((bundle) => { | ||
return ( | ||
`bundle.${bundle.name}`.toLocaleLowerCase() === | ||
router.stickyParams.perspective?.toLocaleLowerCase() | ||
) | ||
}) | ||
: LATEST | ||
|
||
const currentVersion = selectedVersion || LATEST | ||
|
||
const isDraft = currentVersion.name === 'drafts' | ||
|
||
const contextValue: VersionContextValue = { | ||
isDraft, | ||
setCurrentVersion, | ||
currentVersion, | ||
} | ||
|
||
return <VersionContext.Provider value={contextValue}>{children}</VersionContext.Provider> | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.