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

fix(structure): intent menu item nodes not rendering #5728

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions dev/test-studio/structure/resolveStructure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CodeIcon,
CogIcon,
EarthGlobeIcon,
ImagesIcon,
JoystickIcon,
Expand Down Expand Up @@ -48,6 +49,19 @@ export const structure: StructureResolver = (S, {schema, documentStore, i18n}) =
.child(
S.list()
.title('Untitled repro')
.menuItems([
S.menuItem()
.title('Edit GRRM')
.icon(CogIcon)
.showAsAction(true)
.intent({
type: 'edit',
params: {
id: 'grrm',
type: 'author',
},
}),
])
.items([
S.documentListItem().id('grrm').schemaType('author'),
S.listItem()
Expand Down
1 change: 1 addition & 0 deletions packages/sanity/src/core/components/StatusButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Button, type ButtonProps} from '../../ui-components'

/** @hidden @beta */
export type StatusButtonProps = ButtonProps & {
forwardedAs?: string
disabled?: boolean | {reason: ReactNode}
mode?: ButtonProps['mode']
iconRight?: undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {PaneMenuButtonItem} from './PaneMenuButtonItem'
import {type _PaneMenuGroup, type _PaneMenuItem} from './types'

function getDisabledReason(node: _PaneMenuItem) {
if (!node.disabled) {
return {disabledReason: undefined, ariaLabel: undefined, isDisabled: false}
}

/**
* This component supports receiving a `reason: string | react.ReactNode`.
* We are casting it as string, to avoid the ts error, as content will be rendered into the tooltip which only accepts string, but it won't crash if it's a ReactNode.
Expand Down Expand Up @@ -60,7 +64,7 @@ export function PaneHeaderMenuItemActionButton(props: PaneHeaderMenuItemActionBu

return (
<StatusButton
disabled={Boolean(node.disabled)}
disabled={isDisabled}
icon={node.icon}
// eslint-disable-next-line react/jsx-handler-names
onClick={node.onAction}
Expand Down Expand Up @@ -91,7 +95,7 @@ function PaneHeaderActionIntentButton(props: {intent: Intent; node: _PaneMenuIte

return (
<StatusButton
as="a"
forwardedAs="a"
disabled={isDisabled}
href={intentLink.href}
icon={node.icon}
Expand Down
2 changes: 2 additions & 0 deletions packages/sanity/src/structure/menuNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function resolveMenuNodes(params: {

hotkey: item.shortcut,
icon: item.icon,
intent: item.intent,
onAction: () => params.actionHandler(item),
renderAsButton: item.showAsAction ?? false,
selected: item.selected,
Expand All @@ -92,6 +93,7 @@ export function resolveMenuNodes(params: {

hotkey: item.shortcut,
icon: item.icon,
intent: item.intent,
onAction: () => params.actionHandler(item),
renderAsButton: item.showAsAction ?? false,
selected: item.selected,
Expand Down
Loading