Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corel 178 3 #7613

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9bc46ae
test(sanity): update tests after merge
RitaDias Oct 17, 2024
91176c1
refactor(sanity): add publish chip on header, remove other decorators
RitaDias Oct 4, 2024
d44540b
refactor(sanity): add drafts button to header
RitaDias Oct 7, 2024
a5b20bc
refactor(sanity): add version list and update header with scrolling
RitaDias Oct 7, 2024
e89a712
refactor(sanity): add ability to switch perspectives in document pane…
RitaDias Oct 7, 2024
f7faac7
refactor(sanity): fix issue with tab header
RitaDias Oct 7, 2024
0b2e3e8
refactor(sanity): update click handler for draft chip
RitaDias Oct 7, 2024
6265f15
fix(sanity): fix selected issue on version chips
RitaDias Oct 14, 2024
d24a143
docs(sanity): add reminder to update tooltip text
RitaDias Oct 14, 2024
08ff82a
chore(sanity): remove unused imports
RitaDias Oct 14, 2024
a66eb75
chore(sanity): set up initial add version button
RitaDias Oct 14, 2024
f577eb8
test(sanity): update test for document header (chips), made all chips…
RitaDias Oct 14, 2024
50e52b5
fix(sanity): issue when changing to published perspective
RitaDias Oct 14, 2024
123947a
refactor(sanity): reduce gap
RitaDias Oct 14, 2024
29251fc
refactor(sanity): add open history to header
RitaDias Oct 14, 2024
30e2e02
fix(sanity): fix alignment with chips and actions
RitaDias Oct 14, 2024
6aa5428
refactor(sanity): move chip code to own component
RitaDias Oct 15, 2024
feafff9
feat(sanity): intial context menu for version badges
RitaDias Oct 16, 2024
9d867d1
feat(sanity): add popovermenu to draft and to published
RitaDias Oct 16, 2024
5208907
fix(sanity): issue with selected state on header
RitaDias Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/sanity/src/core/releases/hooks/usePerspective.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export function usePerspective(selectedPerspective?: string): PerspectiveValue {
const setPerspective = (bundleId: string | undefined) => {
if (bundleId === 'drafts') {
router.navigateStickyParam('perspective', '')
} else if (bundleId === 'published') {
router.navigateStickyParam('perspective', 'published')
} else {
router.navigateStickyParam('perspective', `bundle.${bundleId}`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const createVersion: OperationImpl<[baseDocumentId: string], 'NO_NEW_VERS
return snapshots.published || snapshots.draft ? false : 'NO_NEW_VERSION'
},
execute: ({schema, client, snapshots, typeName}, dupeId) => {
const source = snapshots.draft || snapshots.published
const source = snapshots.version || snapshots.draft || snapshots.published

if (!source) {
throw new Error('cannot execute on empty document')
Expand Down
23 changes: 11 additions & 12 deletions packages/sanity/src/structure/components/pane/PaneHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ export const PaneHeader = forwardRef(function PaneHeader(
>
<LegacyLayerProvider zOffset="paneHeader">
<Card data-collapsed={collapsed ? '' : undefined} tone="inherit">
<Layout
gap={1}
onClick={handleLayoutClick}
padding={3}
paddingBottom={collapsed ? 3 : 2}
sizing="border"
style={layoutStyle}
>
<Layout gap={1} onClick={handleLayoutClick} sizing="border" style={layoutStyle}>
{backButton && <Box flex="none">{backButton}</Box>}

<TitleCard
Expand All @@ -82,18 +75,24 @@ export const PaneHeader = forwardRef(function PaneHeader(
padding={2}
tabIndex={tabIndex}
>
{loading && <TitleTextSkeleton animated radius={1} size={1} />}
{loading && (
<Box padding={3}>
<TitleTextSkeleton animated radius={1} size={1} />
</Box>
)}
{!loading && (
<TitleText size={1} textOverflow="ellipsis" weight="semibold">
{title}
<Box flex={1} overflow="auto" padding={2}>
{title}
</Box>
</TitleText>
)}
</TitleCard>

{actions && (
<Flex align="center" hidden={collapsed}>
<Box hidden={collapsed} padding={3}>
<LegacyLayerProvider zOffset="paneHeader">{actions}</LegacyLayerProvider>
</Flex>
</Box>
)}
</Layout>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {render, screen} from '@testing-library/react'
import {render, screen, waitFor} from '@testing-library/react'
import {type BundleDocument, LATEST, useBundles, usePerspective} from 'sanity'
import {useDocumentPane} from 'sanity/structure'
import {describe, expect, it, type Mock, vi} from 'vitest'
Expand Down Expand Up @@ -85,16 +85,18 @@ describe('DeletedDocumentBanners', () => {
mockUsePerspective.mockReturnValue({currentGlobalBundle: LATEST} as ReturnType<
typeof usePerspective
>)

mockUseBundles.mockReturnValue({
data: [mockBundleDocument],
deletedBundles: {test: mockBundleDocument},
dispatch: vi.fn(),
loading: false,
})

mockUseDocumentPane.mockReturnValue({
isDeleted: true,
isDeleting: false,
documentId: 'versions.test-version.test-document',
documentId: 'test-document',
} as ReturnType<typeof useDocumentPane>)

await renderTest()
Expand All @@ -103,6 +105,10 @@ describe('DeletedDocumentBanners', () => {
const bundleBanner = screen.queryByTestId('deleted-bundle-banner')

expect(bundleBanner).toBeNull()
expect(fallbackBanner).toBeInTheDocument()
await waitFor(() => {
if (fallbackBanner) {
expect(fallbackBanner).toBeInTheDocument()
}
})
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {DocumentIcon} from '@sanity/icons'
import {Flex, Text} from '@sanity/ui'
import {createElement, memo, type ReactElement} from 'react'
import {memo, type ReactElement} from 'react'
import {unstable_useValuePreview as useValuePreview, useTranslation} from 'sanity'
import {styled} from 'styled-components'

Expand Down Expand Up @@ -47,24 +46,8 @@ export const DocumentHeaderTitle = memo(function DocumentHeaderTitle(): ReactEle
}

return (
<Flex flex={1} align="center" gap={3} paddingX={2}>
<Text size={1}>{createElement(schemaType?.options?.icon || DocumentIcon)}</Text>
<TitleContainer
muted={!value?.title}
size={1}
textOverflow="ellipsis"
weight={value?.title ? 'semibold' : undefined}
title={value?.title}
>
{value?.title || (
<span style={{color: 'var(--card-muted-fg-color)'}}>
{t('panes.document-header-title.untitled.text')}
</span>
)}
</TitleContainer>
<Flex flex="none" align="center" gap={1}>
<DocumentPerspectiveMenu />
</Flex>
<Flex flex={1} align="center" gap={1}>
<DocumentPerspectiveMenu />
</Flex>
)
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ArrowLeftIcon, CloseIcon, SplitVerticalIcon} from '@sanity/icons'
import {Flex} from '@sanity/ui'
import {ArrowLeftIcon, CloseIcon, RestoreIcon, SplitVerticalIcon} from '@sanity/icons'
import {Flex, Text} from '@sanity/ui'
import {
createElement,
type ForwardedRef,
Expand All @@ -10,14 +10,9 @@ import {
useMemo,
useState,
} from 'react'
import {
type DocumentActionDescription,
useFieldActions,
useTimelineSelector,
useTranslation,
} from 'sanity'
import {type DocumentActionDescription, useFieldActions, useTranslation} from 'sanity'

import {Button, TooltipDelayGroupProvider} from '../../../../../ui-components'
import {Button, Tooltip, TooltipDelayGroupProvider} from '../../../../../ui-components'
import {
PaneContextMenuButton,
PaneHeader,
Expand All @@ -33,7 +28,6 @@ import {type PaneMenuItem} from '../../../../types'
import {useStructureTool} from '../../../../useStructureTool'
import {ActionDialogWrapper, ActionMenuListItem} from '../../statusBar/ActionMenuButton'
import {isRestoreAction} from '../../statusBar/DocumentStatusBarActions'
import {TimelineMenu} from '../../timeline'
import {useDocumentPane} from '../../useDocumentPane'
import {DocumentHeaderTabs} from './DocumentHeaderTabs'
import {DocumentHeaderTitle} from './DocumentHeaderTitle'
Expand All @@ -59,10 +53,11 @@ export const DocumentPanelHeader = memo(
onPaneSplit,
menuItemGroups,
schemaType,
timelineStore,
connectionState,
views,
unstable_languageFilter,
onHistoryOpen,
inspector,
} = useDocumentPane()
const {features} = useStructureTool()
const {index, BackLink, hasGroupSiblings} = usePaneRouter()
Expand All @@ -86,9 +81,6 @@ export const DocumentPanelHeader = memo(
const contextMenuNodes = useMemo(() => menuNodes.filter(isNotMenuNodeButton), [menuNodes])
const showTabs = views.length > 1

// Subscribe to external timeline state changes
const rev = useTimelineSelector(timelineStore, (state) => state.revTime)

const {collapsed, isLast} = usePane()
// Prevent focus if this is the last (non-collapsed) pane.
const tabIndex = isLast && !collapsed ? -1 : 0
Expand Down Expand Up @@ -134,6 +126,10 @@ export const DocumentPanelHeader = memo(
[contextMenuNodes, referenceElement],
)

const handleHistoryOpen = useCallback(() => {
onHistoryOpen()
}, [onHistoryOpen])

return (
<TooltipDelayGroupProvider>
<PaneHeader
Expand Down Expand Up @@ -171,6 +167,18 @@ export const DocumentPanelHeader = memo(
{menuButtonNodes.map((item) => (
<PaneHeaderActionButton key={item.key} node={item} />
))}

{/* todo update translation */}
{/*eslint-disable-next-line i18next/no-literal-string*/}
<Tooltip content={<Text size={1}>History</Text>} placement="bottom" portal>
<Button
icon={RestoreIcon}
mode="bleed"
onClick={handleHistoryOpen}
padding={2}
selected={inspector?.name === 'sanity/structure/history'}
/>
</Tooltip>
{editState && (
<>
<RenderActionCollectionState
Expand All @@ -180,7 +188,6 @@ export const DocumentPanelHeader = memo(
>
{renderPaneActions}
</RenderActionCollectionState>
<TimelineMenu chunk={rev} mode="rev" placement="bottom-end" />
</>
)}

Expand Down
Loading
Loading