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

feat(core): adds events based history #7922

Merged
merged 53 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c1fbfb3
feat(core): add beta events api flag
pedrobonamin Nov 11, 2024
7f71d3a
chore(structure): insert timeline through history provider, add suppo…
pedrobonamin Nov 11, 2024
a46511c
feat(core): wip implementation for events in publish view
pedrobonamin Nov 18, 2024
2bcb573
fix: disable server action flag
pedrobonamin Nov 19, 2024
a628b1d
wip implementation for edit events in verision docs
pedrobonamin Nov 19, 2024
1480f25
fix(events): add id and update events store for version documents
pedrobonamin Nov 19, 2024
776e91f
feat(core): support remote mutations in version events
pedrobonamin Nov 21, 2024
cacb000
feat(core): handle edit events history in version docs
pedrobonamin Nov 23, 2024
861a101
wip
pedrobonamin Nov 23, 2024
ee0dd64
feat(core): add DocumentVariantType to useEventsStore
pedrobonamin Nov 28, 2024
44613dd
chore(core): add useRemoteTransactions hook
pedrobonamin Nov 25, 2024
48f3f79
fix(structure): update document title to display correct version and …
pedrobonamin Nov 25, 2024
2a05d37
feat(structure): disable selection of publish events when inspecting …
pedrobonamin Nov 25, 2024
eccb88c
fix(structure): reset history params when perspective changes
pedrobonamin Nov 25, 2024
3057b0c
feat(core): update versions time traveling
pedrobonamin Nov 25, 2024
d62072b
feat(core): add loadMoreEvents acction to useEventsStore
pedrobonamin Nov 26, 2024
4f4e7f6
fix(structure): translate PublishedEventMenu and add published - draf…
pedrobonamin Nov 26, 2024
baf3f5d
feat(structure): when sleecitng the lastest event remove the rev
pedrobonamin Nov 27, 2024
dabf05b
feat(core): collapse create with publish events when applicable
pedrobonamin Nov 27, 2024
2d73c63
feat(core): add option to expand draft events
pedrobonamin Nov 27, 2024
295c7a2
fix(structure): update events ui and small fixes
pedrobonamin Nov 28, 2024
0ae9160
feat(core): add support for live edit events
pedrobonamin Nov 28, 2024
4401127
fix(core): remove fromTransactionId in edit event
pedrobonamin Nov 28, 2024
b19a1b7
chore(core): divide useEventsStore subscriptions
pedrobonamin Nov 29, 2024
ea7dc5d
fix(core): do not refetch transactions if to and from haven't changed
pedrobonamin Nov 29, 2024
b9adee0
feat(core): add createEventsStore
pedrobonamin Nov 29, 2024
ad0f63a
feat(structure): update inspector ui
pedrobonamin Nov 29, 2024
3e5f537
feat(structure): refactor documentPaneProvider to extract timeline store
pedrobonamin Nov 29, 2024
6650c6f
fix(core): update types to internal
pedrobonamin Nov 29, 2024
8e0dd86
fix(structure): remove unused imports DocumentPanelHeader
pedrobonamin Nov 29, 2024
f67a422
fix(core): update getEditEvents tests
pedrobonamin Nov 29, 2024
cb1e76d
feat(core): add tests for when it's a live edit event
pedrobonamin Nov 29, 2024
ddaf58d
fix(core): update tags
pedrobonamin Dec 2, 2024
b0eb2c3
fix(core): update return tye of useEventsStore
pedrobonamin Dec 2, 2024
a6008b7
fix: various fixes after PR review
pedrobonamin Dec 2, 2024
d9e6e65
fix(core): only return changesList if both documents exist
pedrobonamin Dec 2, 2024
043caf3
chore(core): add events readme
pedrobonamin Dec 2, 2024
bb1efbd
fix(core): enable events api when using releases plugin
pedrobonamin Dec 2, 2024
7e44a1d
fix(structure): fix bug with draft events not showing the expand button
pedrobonamin Dec 2, 2024
123d2aa
fix(structure): automatically expand parent event if children is sele…
pedrobonamin Dec 2, 2024
08c939f
fix(structure): infinite re render
pedrobonamin Dec 2, 2024
9341615
fix: update PR with review suggestions
pedrobonamin Dec 4, 2024
702eded
fix(core): add documentPaneProviderWrapper
pedrobonamin Dec 4, 2024
25a452c
fix(structure): updates after rebase
pedrobonamin Dec 4, 2024
c6d99c9
fix(test-studio): add _strengthenOnPublish to author
pedrobonamin Dec 4, 2024
f5caab6
fix(structure): update dcoumentPaneProvider after rebase
pedrobonamin Dec 5, 2024
e29d6dc
fix(structure): update DocumentPaneProvider props
pedrobonamin Dec 5, 2024
6bc57cf
fix(structure): rename onExpand for fetchEventChildren
pedrobonamin Dec 5, 2024
6aad3bb
fix(core): update configResolver for events api error message
pedrobonamin Dec 9, 2024
a920056
fix(core): make revisionId required in getDocumentAtRevision
pedrobonamin Dec 9, 2024
2761dbb
fix(core): update getDocumentAtRevision cache
pedrobonamin Dec 9, 2024
a0acceb
fix(core): rename getEffectState return value
pedrobonamin Dec 9, 2024
2842a1b
chore(core): do not enable by default the new events api
pedrobonamin Dec 9, 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
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const config = {
'status',
'group',
'textWeight',
'showChangesBy',
],
},
},
Expand Down
7 changes: 7 additions & 0 deletions dev/test-studio/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const defaultWorkspace = {
tasks: {
enabled: true,
},
beta: {eventsAPI: {enabled: true}},
}

export default defineConfig([
Expand Down Expand Up @@ -220,6 +221,12 @@ export default defineConfig([
dataset: 'playground',
plugins: [sharedSettings()],
basePath: '/playground',
// eslint-disable-next-line camelcase
__internal_serverDocumentActions: {
// TODO: Switched off because Actions API doesn't support versions (yet).
enabled: false,
},
beta: {eventsAPI: {enabled: true}},
},
{
name: 'listener-events',
Expand Down
19 changes: 11 additions & 8 deletions dev/test-studio/schema/author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ export default defineType({
},
],

initialValue: () => ({
initialValue: {
name: 'Foo',
bestFriend: {_type: 'reference', _ref: 'foo-bar'},
image: {
_type: 'image',
asset: {
_ref: 'image-8dcc1391e06e4b4acbdc6bbf2e8c8588d537cbb8-4896x3264-jpg',
_type: 'reference',
bestFriend: {
_type: 'reference',
_ref: 'foo-bar',
_weak: true,
_strengthenOnPublish: {
type: 'author',
template: {
id: 'author',
},
},
},
}),
},
})
1 change: 1 addition & 0 deletions packages/sanity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
"tar-fs": "^2.1.1",
"tar-stream": "^3.1.7",
"use-device-pixel-ratio": "^1.1.0",
"use-effect-event": "^1.0.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already part of other packages installed with sanity, like @sanity/ui , portable-text etc.

➜  sanity git:(corel-history) ✗ pnpm why use-effect-event
Legend: production dependency, optional only, dev only

[email protected] /Users/pedrobonamin/code/sanity

devDependencies:
@sanity/tsdoc 1.0.134
└─┬ @sanity/ui 2.10.0-corel.0
  └── use-effect-event 1.0.2
@sanity/ui 2.10.0-corel.0
└── use-effect-event 1.0.2
sanity link:packages/sanity
├─┬ @portabletext/editor 1.11.3
│ └── use-effect-event 1.0.2
├─┬ @sanity/insert-menu 1.0.11-release.4
│ └─┬ @sanity/ui 2.10.0-corel.0
│   └── use-effect-event 1.0.2
├─┬ @sanity/presentation 1.17.8-release.4
│ ├─┬ @sanity/ui 2.10.0-corel.0
│ │ └── use-effect-event 1.0.2
│ └── use-effect-event 1.0.2
├─┬ @sanity/ui 2.10.0-corel.0
│ └── use-effect-event 1.0.2
├─┬ react-rx 4.1.7
│ └── use-effect-event 1.0.2
└── use-effect-event 1.0.2

"use-hot-module-reload": "^2.0.0",
"use-sync-external-store": "^1.2.0",
"vite": "^4.5.1",
Expand Down
11 changes: 11 additions & 0 deletions packages/sanity/src/_singletons/context/EventsContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {createContext} from 'sanity/_createContext'

import type {EventsStore} from '../../core/store/events/types'

/**
* @internal
*/
export const EventsContext = createContext<EventsStore | null>(
'sanity/_singletons/context/events',
null,
)
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export * from './context/DocumentFieldActionsContext'
export * from './context/DocumentIdContext'
export * from './context/DocumentPaneContext'
export * from './context/DocumentSheetListContext'
export * from './context/EventsContext'
export * from './context/FieldActionsContext'
export * from './context/FormBuilderContext'
export * from './context/FormCallbacksContext'
Expand Down
20 changes: 20 additions & 0 deletions packages/sanity/src/core/config/configPropertyReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,26 @@ export const internalTasksReducer = (opts: {
return result
}

export const eventsAPIReducer = (opts: {config: PluginOptions; initialValue: boolean}): boolean => {
const {config, initialValue} = opts
const flattenedConfig = flattenConfig(config, [])

const result = flattenedConfig.reduce((acc: boolean, {config: innerConfig}) => {
const enabled = innerConfig.beta?.eventsAPI?.enabled

if (typeof enabled === 'undefined') return acc
if (typeof enabled === 'boolean') return enabled

throw new Error(
`Expected \`beta.eventsAPI.enabled\` to be an object with footerAction, but received ${getPrintableType(
enabled,
)}`,
)
}, initialValue)

return result
}

export const partialIndexingEnabledReducer = (opts: {
config: PluginOptions
initialValue: boolean
Expand Down
4 changes: 4 additions & 0 deletions packages/sanity/src/core/config/prepareConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
documentCommentsEnabledReducer,
documentInspectorsReducer,
documentLanguageFilterReducer,
eventsAPIReducer,
fileAssetSourceResolver,
imageAssetSourceResolver,
initialDocumentActions,
Expand Down Expand Up @@ -655,6 +656,9 @@ function resolveSource({
},

beta: {
eventsAPI: {
enabled: eventsAPIReducer({config, initialValue: false}),
},
treeArrayEditing: {
// This beta feature is no longer available.
enabled: false,
Expand Down
10 changes: 10 additions & 0 deletions packages/sanity/src/core/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,4 +1007,14 @@ export interface BetaFeatures {
*/
fallbackStudioOrigin?: string
}
/**
* Config for the history events API .
*
* If enabled, it will use the new events API to fetch document history.
*
* If it is not enabled, it will continue using the legacy Timeline.
*/
eventsAPI?: {
enabled: boolean
}
}
22 changes: 22 additions & 0 deletions packages/sanity/src/core/field/diff/components/ChangesError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Card, Stack, Text} from '@sanity/ui'

import {useTranslation} from '../../../i18n'

/**
* @internal
* */
export function ChangesError() {
const {t} = useTranslation()
return (
<Card tone="caution" padding={3}>
<Stack space={3}>
<Text size={1} weight="medium" as="h3">
{t('changes.error-title')}
</Text>
<Text as="p" size={1} muted>
{t('changes.error-description')}
</Text>
</Stack>
</Card>
)
}
52 changes: 31 additions & 21 deletions packages/sanity/src/core/field/diff/components/DiffTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type Path} from '@sanity/types'
import {Flex, Inline, Stack, Text} from '@sanity/ui'
import {Card, Flex, Inline, Stack, Text} from '@sanity/ui'
import {type ReactElement, type ReactNode} from 'react'

import {Tooltip, type TooltipProps} from '../../../../ui-components'
Expand All @@ -9,6 +9,7 @@ import {useTranslation} from '../../../i18n'
import {useUser} from '../../../store'
import {type AnnotationDetails, type Diff} from '../../types'
import {getAnnotationAtPath, useAnnotationColor} from '../annotations'
import {Event} from '../components/Event'

/** @internal */
export interface DiffTooltipProps extends TooltipProps {
Expand Down Expand Up @@ -46,7 +47,7 @@ function DiffTooltipWithAnnotation(props: DiffTooltipWithAnnotationsProps) {
}

const content = (
<Stack space={2}>
<Stack space={2} style={{minWidth: '240px'}} paddingTop={1}>
<Text muted size={1} weight="medium">
{description || t('changes.changed-label')}
</Text>
Expand Down Expand Up @@ -75,26 +76,35 @@ function AnnotationItem({annotation}: {annotation: AnnotationDetails}) {
const {t} = useTranslation()

return (
<Inline space={2}>
<Flex
align="center"
paddingRight={3}
style={{
backgroundColor: color.background,
color: color.text,
borderRadius: 'calc(23px / 2)',
}}
>
<UserAvatar user={author} />
<Inline paddingLeft={2}>
<Text muted size={1} style={{color: color.text}}>
{user ? user.displayName : t('changes.loading-author')}
<>
{annotation.event ? (
<>
<Card borderBottom marginBottom={2} />
<Event event={annotation.event} showChangesBy="inline" />
</>
) : (
<Inline space={2}>
<Flex
align="center"
paddingRight={3}
style={{
backgroundColor: color.background,
color: color.text,
borderRadius: 'calc(23px / 2)',
RitaDias marked this conversation as resolved.
Show resolved Hide resolved
}}
>
<UserAvatar user={author} />
<Inline paddingLeft={2}>
<Text muted size={1} style={{color: color.text}}>
{user ? user.displayName : t('changes.loading-author')}
</Text>
</Inline>
</Flex>
<Text as="time" muted size={1} dateTime={timestamp}>
{timeAgo}
</Text>
</Inline>
</Flex>
<Text as="time" muted size={1} dateTime={timestamp}>
{timeAgo}
</Text>
</Inline>
)}
</>
)
}
Loading
Loading