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): new insert menu for arrays with filtering, type preview support #6853

Merged
merged 13 commits into from
Jun 17, 2024

Conversation

christianhg
Copy link
Member

@christianhg christianhg commented Jun 5, 2024

Description

Instead of using a MenuButton the "array of objects" now renders the insert
menu using the InsertMenu from the new @sanity/insert-menu package. This
insert menu allows more configuration in the form of InsertMenuOptions which
are exposed on the ArrayOptions interface.


These are the options available:

/** @alpha This API may change */
export interface InsertMenuOptions {
  /**
   * @defaultValue `'auto'`
   * `filter: 'auto'` automatically turns on filtering if there are more than 5
   * schema types added to the menu.
   */
  filter?: 'auto' | 'on' | 'off'
  groups?: Array<{name: string; title?: string; of?: Array<string>}>
  /** defaultValue `true` */
  showIcons?: boolean
  /** @defaultValue `[{name: 'list'}]` */
  views?: Array<
    {name: 'list'} | {name: 'grid'; previewImageUrl: (schemaTypeName: string) => string | undefined}
  >
}

And this if how they are made available:

/** @public */
export interface ArrayOptions<V = unknown> extends SearchConfiguration {
  // ...
  /** @alpha This API may change */
  insertMenu?: InsertMenuOptions
}

If you enable filter, add some groups and add grid and list views then you end up with something like this:

Screenshot 2024-06-05 at 14 30 45

Instead of the usual:

Screenshot 2024-06-05 at 14 32 10

(You can play around with the options in the page-building-studio)

The options still don't take effect in the context menu:
Screenshot 2024-06-05 at 14 57 10

This is implemented in #6921

What to review

What's most important is that no existing functionality breaks. We are releasing this as @alpha to try it out internally before start promoting the new options.

Testing

I could definitely look into writing some tests for this. Let me know if you think this is a blocker for merging. I just didn't want to spend the time until the API/behaviour was somewhat decided upon. This PR adds a test for the multi-type array field to make sure the existing insert menu still works 🎉

Notes for release

Copy link

vercel bot commented Jun 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2024 9:43am
performance-studio ✅ Ready (Inspect) Visit Preview Jun 17, 2024 9:43am
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2024 9:43am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2024 9:43am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2024 9:43am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jun 17, 2024 9:43am

Copy link
Contributor

github-actions bot commented Jun 5, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented Jun 5, 2024

Component Testing Report Updated Jun 17, 2024 9:47 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 39s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 25s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 31s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 51s 1 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 34s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 14s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 3s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 7s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 20s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 29s 12 0 0

@christianhg christianhg force-pushed the feat-full-insert-menu-take-2 branch from 2ead8c3 to 4354513 Compare June 6, 2024 08:46
popoverProps: {
placement: 'bottom',
fallbackPlacements: ['top'],
matchReferenceWidth: props.schemaType.options?.insertMenu?.filter === 'on',
Copy link
Member Author

Choose a reason for hiding this comment

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

@mariuslundgard, @rexxars , I think this logic is a tiny bit flawed now that we have auto-filtering. The original idea was to make the width of the menu match the button if filtering was turned on, but we can't infer from the outside that the menu decides to auto-enable filtering.

But now we might need

  1. An alternate way to infer full width
  2. A way for the menu to tell the call site that filtering is enabled

What do you think?


Array input with no insert menu options configured:
Screenshot 2024-06-17 at 11 39 19

Array input with filter: 'on':
Screenshot 2024-06-17 at 11 44 45

Array input with everything configured except filter:
Screenshot 2024-06-17 at 11 42 16

Copy link
Member

Choose a reason for hiding this comment

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

I'll defer to @mariuslundgard :)

@rexxars rexxars changed the title feat(core, types): support new, experimental array InsertMenuOptions feat(core): new insert menu for arrays with filtering, type preview support Jun 17, 2024
@rexxars rexxars merged commit 203f135 into next Jun 17, 2024
45 checks passed
@rexxars rexxars deleted the feat-full-insert-menu-take-2 branch June 17, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants