Skip to content

Commit 4e05e23

Browse files
feat(payload): add field admin option: admin.hiddenInVersionView
This hides a field from the version view where different versions of the same document can be compared.
1 parent c333841 commit 4e05e23

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

Diff for: docs/fields/overview.mdx

+16-15
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,22 @@ Example:
173173

174174
In addition to each field's base configuration, you can define specific traits and properties for fields that only have effect on how they are rendered in the Admin panel. The following properties are available for all fields within the `admin` property:
175175

176-
| Option | Description |
177-
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
178-
| `condition` | You can programmatically show / hide fields based on what other fields are doing. [Click here](#conditional-logic) for more info. |
179-
| `components` | All field components can be completely and easily swapped out for custom components that you define. [Click here](#custom-components) for more info. |
180-
| `description` | Helper text to display with the field to provide more information for the editor user. [Click here](#description) for more info. |
181-
| `position` | Specify if the field should be rendered in the sidebar by defining `position: 'sidebar'`. |
182-
| `width` | Restrict the width of a field. you can pass any string-based value here, be it pixels, percentages, etc. This property is especially useful when fields are nested within a `Row` type where they can be organized horizontally. |
183-
| `style` | Attach raw CSS style properties to the root DOM element of a field. |
184-
| `className` | Attach a CSS class name to the root DOM element of a field. |
185-
| `readOnly` | Setting a field to `readOnly` has no effect on the API whatsoever but disables the admin component's editability to prevent editors from modifying the field's value. |
186-
| `disabled` | If a field is `disabled`, it is completely omitted from the Admin panel. |
187-
| `disableBulkEdit` | Set `disableBulkEdit` to `true` to prevent fields from appearing in the select options when making edits for multiple documents. |
188-
| `disableListColumn` | Set `disableListColumn` to `true` to prevent fields from appearing in the list view column selector. |
189-
| `disableListFilter` | Set `disableListFilter` to `true` to prevent fields from appearing in the list view filter options. |
190-
| `hidden` | Setting a field's `hidden` property on its `admin` config will transform it into a `hidden` input type. Its value will still submit with the Admin panel's requests, but the field itself will not be visible to editors. |
176+
| Option | Description |
177+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
178+
| `condition` | You can programmatically show / hide fields based on what other fields are doing. [Click here](#conditional-logic) for more info. |
179+
| `components` | All field components can be completely and easily swapped out for custom components that you define. [Click here](#custom-components) for more info. |
180+
| `description` | Helper text to display with the field to provide more information for the editor user. [Click here](#description) for more info. |
181+
| `position` | Specify if the field should be rendered in the sidebar by defining `position: 'sidebar'`. |
182+
| `width` | Restrict the width of a field. you can pass any string-based value here, be it pixels, percentages, etc. This property is especially useful when fields are nested within a `Row` type where they can be organized horizontally. |
183+
| `style` | Attach raw CSS style properties to the root DOM element of a field. |
184+
| `className` | Attach a CSS class name to the root DOM element of a field. |
185+
| `readOnly` | Setting a field to `readOnly` has no effect on the API whatsoever but disables the admin component's editability to prevent editors from modifying the field's value. |
186+
| `disabled` | If a field is `disabled`, it is completely omitted from the Admin panel. |
187+
| `disableBulkEdit` | Set `disableBulkEdit` to `true` to prevent fields from appearing in the select options when making edits for multiple documents. |
188+
| `disableListColumn` | Set `disableListColumn` to `true` to prevent fields from appearing in the list view column selector. |
189+
| `disableListFilter` | Set `disableListFilter` to `true` to prevent fields from appearing in the list view filter options. |
190+
| `hidden` | Setting a field's `hidden` property on its `admin` config will transform it into a `hidden` input type. Its value will still submit with the Admin panel's requests, but the field itself will not be visible to editors. |
191+
| `hiddenInVersionView` | Set `hiddenInVersionView` to `true` to prevent fields from appearing in the version view when comparing multiple versions of a document. |
191192

192193
### Custom components
193194

Diff for: packages/payload/src/admin/components/views/Version/RenderFieldsToDiff/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const RenderFieldsToDiff: React.FC<Props> = ({
2424
// Don't render hidden fields
2525
if ('hidden' in field && field.hidden) return null
2626

27+
// Don't render fields with admin.hiddenInVersionView
28+
if ('hiddenInVersionView' in field.admin && field.admin.hiddenInVersionView) return null
29+
2730
const Component = fieldComponents[field.type]
2831

2932
const isRichText = field.type === 'richText'

Diff for: packages/payload/src/fields/config/schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const baseAdminFields = joi.object().keys({
2323
disableListFilter: joi.boolean().default(false),
2424
disabled: joi.boolean().default(false),
2525
hidden: joi.boolean().default(false),
26+
hiddenInVersionView: joi.boolean().default(false),
2627
initCollapsed: joi.boolean().default(false),
2728
position: joi.string().valid('sidebar'),
2829
readOnly: joi.boolean().default(false),

Diff for: packages/payload/src/fields/config/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type Admin = {
117117
disableListFilter?: boolean
118118
disabled?: boolean
119119
hidden?: boolean // it could make sense to rename this option to hiddenInEditView
120+
hiddenInVersionView?: boolean
120121
position?: 'sidebar'
121122
readOnly?: boolean
122123
style?: CSSProperties

Diff for: test/fields/collections/Text/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ const TextFields: CollectionConfig = {
162162
hidden: true,
163163
},
164164
},
165+
{
166+
name: 'hiddenInVersionView',
167+
type: 'text',
168+
admin: {
169+
hiddenInVersionView: true,
170+
},
171+
},
165172
{
166173
name: 'disableListColumnText',
167174
type: 'text',

Diff for: test/fields/e2e.spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,34 @@ describe('fields', () => {
287287
await expect(page.locator('#field-adminHidden')).toBeHidden()
288288
})
289289
})
290+
291+
describe('admin.hiddenInVersionView', () => {
292+
test('should be hidden in the version view', async () => {
293+
const doc = await payload.create({
294+
collection: textFieldsSlug,
295+
data: textDoc,
296+
})
297+
const versions = await payload.findVersions({
298+
collection: textFieldsSlug,
299+
where: { parent: { equals: doc.id } },
300+
limit: 1,
301+
})
302+
303+
await page.goto(url.version(doc.id, versions.docs[0].id))
304+
305+
await expect(
306+
page.locator('.field-diff-label', {
307+
hasText: exactText('Text'),
308+
}),
309+
).toBeVisible()
310+
311+
await expect(
312+
page.locator('.field-diff-label', {
313+
hasText: exactText('Hidden In Version View'),
314+
}),
315+
).toBeHidden()
316+
})
317+
})
290318
})
291319

292320
describe('number', () => {

0 commit comments

Comments
 (0)