Skip to content

Commit 33ac13d

Browse files
tsemachhDanRibbens
andauthored
feat(ui): toggle showing only modified fields in version diff view (#10807)
## Description As an author reviewing the versions I have for a document , I would like to the ability to focus only on the differences I made and not see the entire document. [Screencast from 2024-09-05 16-38-40.webm](https://github.com/user-attachments/assets/25d44a51-bcac-47d5-a2ec-cadae4d108d4) A checkbox was added to the Version View allowing user to decide if he/she wants to see only modified fields or the entire documents. #7981 - mention this feature and also in discord - [v] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change <!-- Please delete options that are not relevant. --> - [v] New feature (non-breaking change which adds functionality) ## Checklist: - [ ] Existing test suite passes locally with my changes (Actually it's stuck on S3 upload test , note related to my code) One lat question - should we really translate text for all locales ? or we can leave it undefined for now ?(besides english) --------- Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
1 parent 989140b commit 33ac13d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+79
-6
lines changed

packages/next/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"@payloadcms/translations": "workspace:*",
8888
"@payloadcms/ui": "workspace:*",
8989
"busboy": "^1.6.0",
90+
"dequal": "2.0.3",
9091
"file-type": "19.3.0",
9192
"graphql-http": "^1.22.0",
9293
"graphql-playground-html": "1.6.30",

packages/next/src/views/Version/Default/index.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
margin: 0 0 0 var(--base);
4747
}
4848

49+
&__modifiedCheckBox {
50+
margin: 0 0 0 var(--base);
51+
}
52+
4953
@include mid-break {
5054
&__intro,
5155
&__header {
@@ -57,6 +61,7 @@
5761
gap: calc(var(--base) / 4);
5862
}
5963

64+
6065
&__restore {
6166
margin: calc(var(--base) * 0.5) 0 0 0;
6267
}

packages/next/src/views/Version/Default/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use client'
22
import type { OptionObject } from 'payload'
33

4-
import { Gutter, useConfig, useDocumentInfo, usePayloadAPI, useTranslation } from '@payloadcms/ui'
4+
import {
5+
CheckboxInput,
6+
Gutter,
7+
useConfig, useDocumentInfo, usePayloadAPI, useTranslation } from '@payloadcms/ui'
58
import { formatDate } from '@payloadcms/ui/shared'
69
import React, { useState } from 'react'
710

@@ -38,7 +41,10 @@ export const DefaultVersionView: React.FC<DefaultVersionsViewProps> = ({
3841
const [locales, setLocales] = useState<OptionObject[]>(localeOptions)
3942

4043
const [compareValue, setCompareValue] = useState<CompareOption>()
41-
44+
const [modifiedOnly, setModifiedOnly] = useState(false)
45+
function onToggleModifiedOnly() {
46+
setModifiedOnly(!modifiedOnly)
47+
}
4248
const {
4349
admin: { dateFormat },
4450
localization,
@@ -101,6 +107,14 @@ export const DefaultVersionView: React.FC<DefaultVersionsViewProps> = ({
101107
versionID={versionID}
102108
/>
103109
)}
110+
<span className={`${baseClass}__modifiedCheckBox`}>
111+
<CheckboxInput
112+
checked={modifiedOnly}
113+
id={'modifiedOnly'}
114+
label={i18n.t('version:modifiedOnly')}
115+
onToggle={onToggleModifiedOnly}
116+
/>
117+
</span>
104118
</header>
105119
</div>
106120
<div className={`${baseClass}__controls`}>
@@ -126,6 +140,7 @@ export const DefaultVersionView: React.FC<DefaultVersionsViewProps> = ({
126140
fields={(collectionConfig || globalConfig)?.fields}
127141
i18n={i18n}
128142
locales={localeValues}
143+
modifiedOnly={modifiedOnly}
129144
version={
130145
globalConfig
131146
? {

packages/next/src/views/Version/RenderFieldsToDiff/fields/Iterable/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const Iterable: React.FC<DiffComponentProps> = ({
2222
i18n,
2323
locale,
2424
locales,
25+
modifiedOnly,
2526
version,
2627
}) => {
2728
const versionRowCount = Array.isArray(version) ? version.length : 0
@@ -82,9 +83,9 @@ export const Iterable: React.FC<DiffComponentProps> = ({
8283
fields={fields}
8384
i18n={i18n}
8485
locales={locales}
85-
version={versionRow}
86-
/>
87-
</DiffCollapser>
86+
modifiedOnly
87+
version={versionRow}
88+
/></DiffCollapser>
8889
</div>
8990
)
9091
})}

packages/next/src/views/Version/RenderFieldsToDiff/fields/Tabs/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const Tab: React.FC<TabProps> = ({
6767
i18n,
6868
locale,
6969
locales,
70+
modifiedOnly,
7071
tab,
7172
version,
7273
}) => {
@@ -94,6 +95,7 @@ const Tab: React.FC<TabProps> = ({
9495
fields={tab.fields}
9596
i18n={i18n}
9697
locales={locales}
98+
modifiedOnly={modifiedOnly}
9799
version={version}
98100
/>
99101
</DiffCollapser>

packages/next/src/views/Version/RenderFieldsToDiff/fields/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export type DiffComponentProps<TField extends ClientField = ClientField> = {
2020
readonly isRichText?: boolean
2121
readonly locale?: string
2222
readonly locales?: string[]
23+
readonly modifiedOnly?: boolean
2324
readonly version: any
2425
}

packages/next/src/views/Version/RenderFieldsToDiff/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use client'
22
import type { DiffMethod } from 'react-diff-viewer-continued'
33

4-
import { ShimmerEffect, StaggeredShimmers } from '@payloadcms/ui'
4+
import { ShimmerEffect } from '@payloadcms/ui'
5+
import { dequal } from 'dequal/lite'
56
import { fieldAffectsData, fieldIsID } from 'payload/shared'
67
import React, { Fragment, useEffect } from 'react'
78

@@ -20,6 +21,7 @@ export const RenderFieldsToDiff: React.FC<Props> = ({
2021
fields,
2122
i18n,
2223
locales,
24+
modifiedOnly,
2325
version,
2426
}) => {
2527
// typing it as `as typeof _diffComponents` here ensures the TField generics of DiffComponentProps are respected.
@@ -65,6 +67,10 @@ export const RenderFieldsToDiff: React.FC<Props> = ({
6567
? JSON.stringify(comparison?.[fieldName])
6668
: comparison?.[fieldName]
6769

70+
if (modifiedOnly && dequal(versionValue, comparisonValue)) {
71+
return null
72+
}
73+
6874
const hasPermission =
6975
fieldPermissions === true ||
7076
fieldPermissions?.[fieldName] === true ||
@@ -89,6 +95,7 @@ export const RenderFieldsToDiff: React.FC<Props> = ({
8995
i18n,
9096
isRichText,
9197
locales,
98+
modifiedOnly,
9299
version: versionValue,
93100
}
94101

packages/next/src/views/Version/RenderFieldsToDiff/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type Props = {
1515
readonly fields: ClientField[]
1616
readonly i18n: I18nClient
1717
readonly locales: string[]
18+
readonly modifiedOnly?: boolean
1819
readonly version: Record<string, any>
1920
}
2021

packages/translations/src/clientKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ export const clientTranslationKeys = createClientTranslationKeys([
363363
'version:draft',
364364
'version:draftSavedSuccessfully',
365365
'version:lastSavedAgo',
366+
'version:modifiedOnly',
366367
'version:noFurtherVersionsFound',
367368
'version:noRowsFound',
368369
'version:noRowsSelected',

packages/translations/src/languages/ar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ export const arTranslations: DefaultTranslationsObject = {
448448
draft: 'مسودّة',
449449
draftSavedSuccessfully: 'تمّ حفظ المسودّة بنجاح.',
450450
lastSavedAgo: 'تم الحفظ آخر مرة قبل {{distance}}',
451+
modifiedOnly: 'تم التعديل فقط',
451452
noFurtherVersionsFound: 'لم يتمّ العثور على نسخات أخرى',
452453
noRowsFound: 'لم يتمّ العثور على {{label}}',
453454
noRowsSelected: 'لم يتم اختيار {{label}}',

0 commit comments

Comments
 (0)