Skip to content

Commit

Permalink
refactor(form): fix issue with hiding a field group that only have fi…
Browse files Browse the repository at this point in the history
…eldsets (#4477)

* chore(test-studio): add repro schema for field groups with only fieldsets inside

* refactor(form): tidy up field group logic and fix issue causing field group to be hidden if all fields are inside fieldsets

Fixes #4432

* fixup! refactor(form): tidy up field group logic and fix issue causing field group to be hidden if all fields are inside fieldsets

* fixup! fixup! refactor(form): tidy up field group logic and fix issue causing field group to be hidden if all fields are inside fieldsets

---------

Co-authored-by: Robin Pyon <[email protected]>
  • Loading branch information
bjoerge and robinpyon authored May 12, 2023
1 parent 1f444a8 commit cf4fc5c
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 123 deletions.
54 changes: 54 additions & 0 deletions dev/test-studio/schema/debug/fieldGroupsWithFieldsets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {CogIcon} from '@sanity/icons'

export default {
name: 'fieldGroupsWithFieldsets',
title: 'Field groups with all fields inside fieldsets',
type: 'document',
groups: [
{
name: 'group1',
title: 'Group 1',
icon: CogIcon,
},
{
name: 'group2',
title: 'Group 2',
},
],
fieldsets: [
{name: 'fieldset1', title: 'Fieldset 1', options: {collapsed: true}},
{name: 'fieldset2', title: 'Fieldset 2', options: {collapsed: true}},
],
fields: [
{
name: 'group1fieldset1',
type: 'string',
group: 'group1',
fieldset: 'fieldset1',
},
{
name: 'noGroupFieldset1',
type: 'string',
validation: (r) => r.required(),
fieldset: 'fieldset1',
},
{
name: 'group1fieldset2',
type: 'string',
group: 'group1',
fieldset: 'fieldset2',
},
{
name: 'group2fieldset1',
type: 'string',
group: 'group2',
fieldset: 'fieldset1',
},
{
name: 'group2fieldset2',
type: 'string',
group: 'group2',
fieldset: 'fieldset2',
},
],
}
2 changes: 2 additions & 0 deletions dev/test-studio/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import validationTest from './ci/validationCI'
import crossDatasetReference, {crossDatasetSubtype} from './standard/crossDatasetReference'
import {circularCrossDatasetReferenceTest} from './debug/circularCrossDatasetReference'
import {allNativeInputComponents} from './debug/allNativeInputComponents'
import fieldGroupsWithFieldsets from './debug/fieldGroupsWithFieldsets'

// @todo temporary, until code input is v3 compatible
const codeInputType = {
Expand Down Expand Up @@ -244,6 +245,7 @@ export const schemaTypes = [
fieldGroupsDefault,
fieldGroupsMany,
fieldGroupsWithValidation,
fieldGroupsWithFieldsets,
fieldGroupsWithFieldsetsAndValidation,
allNativeInputComponents,
...v3docs.types,
Expand Down
1 change: 1 addition & 0 deletions dev/test-studio/structure/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const DEBUG_FIELD_GROUP_TYPES = [
'fieldGroupsDefault',
'fieldGroupsMany',
'fieldGroupsWithValidation',
'fieldGroupsWithFieldsets',
'fieldGroupsWithFieldsetsAndValidation',
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ describe('basic examples', () => {
open: false,
collapsible: true,
key: 'first-field',
inSelectedGroup: false,
groups: [],
index: 0,
field: {
schemaType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ function setupTest(type: string, value: string | number | boolean | undefined) {
collapsed: false,
collapsible: false,
open: true,
groups: [],
inSelectedGroup: false,
field: {
id: 'id',
schemaType: {
Expand Down
Loading

2 comments on commit cf4fc5c

@vercel
Copy link

@vercel vercel bot commented on cf4fc5c May 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio-git-next.sanity.build
performance-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on cf4fc5c May 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.