Skip to content

Commit

Permalink
feat(corel): doc and structure updates (#7039)
Browse files Browse the repository at this point in the history
* 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
RitaDias authored and juice49 committed Oct 7, 2024
1 parent 034ab4a commit 1f79630
Show file tree
Hide file tree
Showing 18 changed files with 810 additions and 258 deletions.
58 changes: 58 additions & 0 deletions packages/sanity/src/_singletons/context/VersionContext.tsx
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>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {omit} from 'lodash'

import {getDraftId} from '../../../../../util'
import {isLiveEditEnabled} from '../utils/isLiveEditEnabled'
import {type OperationImpl} from './types'

const omitProps = ['_createdAt', '_updatedAt']
Expand All @@ -20,7 +18,9 @@ export const newVersion: OperationImpl<[baseDocumentId: string], 'NO_NEW_VERSION
return client.observable.create(
{
...omit(source, omitProps),
_id: isLiveEditEnabled(schema, typeName) ? dupeId : getDraftId(dupeId),
// we don't need to get a draft id or check live editing, we'll always want to create a new version based on the dupeId
// we have guardrails for this on the front
_id: dupeId,
_type: source._type,
_version: {},
},
Expand Down
18 changes: 12 additions & 6 deletions packages/sanity/src/core/studio/StudioProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import json from 'refractor/lang/json.js'
import jsx from 'refractor/lang/jsx.js'
import typescript from 'refractor/lang/typescript.js'

import {VersionProvider} from '../../_singletons/core/form/VersionContext'
import {LoadingBlock} from '../components/loadingBlock'
import {ErrorLogger} from '../error/ErrorLogger'
import {errorReporter} from '../error/errorReporter'
Expand Down Expand Up @@ -63,17 +64,22 @@ export function StudioProvider({
// mounted React component that is shared across embedded and standalone studios.
errorReporter.initialize()

// eslint-disable-next-line no-warning-comments
/* TODO REMOVE VERSION PROVIDER ONCE STORES ARE SET UP */

const _children = useMemo(
() => (
<WorkspaceLoader LoadingComponent={LoadingBlock} ConfigErrorsComponent={ConfigErrorsScreen}>
<StudioTelemetryProvider config={config}>
<LocaleProvider>
<PackageVersionStatusProvider>
<MaybeEnableErrorReporting errorReporter={errorReporter} />
<ResourceCacheProvider>
<StudioAnnouncementsProvider>{children}</StudioAnnouncementsProvider>
</ResourceCacheProvider>
</PackageVersionStatusProvider>
<VersionProvider>
<PackageVersionStatusProvider>
<MaybeEnableErrorReporting errorReporter={errorReporter} />
<ResourceCacheProvider>
<StudioAnnouncementsProvider>{children}</StudioAnnouncementsProvider>
</ResourceCacheProvider>
</PackageVersionStatusProvider>
</VersionProvider>
</LocaleProvider>
</StudioTelemetryProvider>
</WorkspaceLoader>
Expand Down
54 changes: 14 additions & 40 deletions packages/sanity/src/core/studio/components/navbar/StudioNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ import {
Layer,
LayerProvider,
PortalProvider,
Select,
useMediaIndex,
} from '@sanity/ui'
import {
type ChangeEvent,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from 'react'
import {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'
import {NavbarContext} from 'sanity/_singletons'
import {type RouterState, useRouter, useRouterState} from 'sanity/router'
import {styled} from 'styled-components'
Expand All @@ -28,6 +19,7 @@ import {Button, TooltipDelayGroupProvider} from '../../../../ui-components'
import {type NavbarProps} from '../../../config/studio/types'
import {isDev} from '../../../environment'
import {useTranslation} from '../../../i18n'
import {GlobalBundleMenu} from '../../../versions/components/GlobalBundleMenu'
import {useToolMenuComponent} from '../../studio-components-hooks'
import {useWorkspace} from '../../workspace'
import {ConfigIssuesButton} from './configIssues/ConfigIssuesButton'
Expand Down Expand Up @@ -170,13 +162,6 @@ export function StudioNavbar(props: Omit<NavbarProps, 'renderDefault'>) {

const perspective = useMemo(() => router.stickyParams.perspective, [router.stickyParams])

const handleReleaseChange = useCallback(
(element: ChangeEvent<HTMLSelectElement>) => {
router.navigateStickyParam('perspective', element.currentTarget.value || '')
},
[router],
)

const actionNodes = useMemo(() => {
if (!shouldRender.tools) return null

Expand Down Expand Up @@ -228,29 +213,18 @@ export function StudioNavbar(props: Omit<NavbarProps, 'renderDefault'>) {
<WorkspaceMenuButton />
</Flex>
</Flex>
{/* New document button */}
<NewDocumentButton
{...newDocumentOptions}
modal={shouldRender.newDocumentFullscreen ? 'dialog' : 'popover'}
/>
{/* Search button (desktop) */}
{!shouldRender.searchFullscreen && (
<SearchButton onClick={handleOpenSearch} ref={setSearchOpenButtonEl} />
)}
<Flex>
{/* TODO: Fix */}
<Select value={perspective} onChange={handleReleaseChange}>
{/* eslint-disable-next-line i18next/no-literal-string */}
<option value="">Published + Drafts</option>
{/* eslint-disable-next-line i18next/no-literal-string */}
<option value="previewDrafts">Preview drafts</option>
{/* eslint-disable-next-line i18next/no-literal-string */}
<option value="published">Published</option>
{/* eslint-disable-next-line i18next/no-literal-string */}
<option value="bundle.summerDrop">Summer Drop</option>
{/* eslint-disable-next-line i18next/no-literal-string */}
<option value="bundle.autumnDrop">Autumn Drop</option>
</Select>
{/* Versions button */}
<Flex gap={2}>
<GlobalBundleMenu />
{/* New document button */}
<NewDocumentButton
{...newDocumentOptions}
modal={shouldRender.newDocumentFullscreen ? 'dialog' : 'popover'}
/>
{/* Search button (desktop) */}
{!shouldRender.searchFullscreen && (
<SearchButton onClick={handleOpenSearch} ref={setSearchOpenButtonEl} />
)}
</Flex>
</Flex>
</TooltipDelayGroupProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ export function NewDocumentButton(props: NewDocumentButtonProps) {
'data-testid': 'new-document-button',
'disabled': disabled || loading,
'icon': AddIcon,
'text': t('new-document.button'),
'mode': 'ghost',
'text': '',
'mode': 'bleed',
'onClick': handleToggleOpen,
'ref': setButtonElement,
'selected': open,
}),
[disabled, handleToggleOpen, loading, open, openDialogAriaLabel, t],
[disabled, handleToggleOpen, loading, open, openDialogAriaLabel],
)

// Tooltip content for the open button
Expand Down
83 changes: 0 additions & 83 deletions packages/sanity/src/core/util/versions/util.ts

This file was deleted.

Loading

0 comments on commit 1f79630

Please sign in to comment.