Skip to content

Commit

Permalink
fix(core): update GetHookCollectionState types
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Mar 10, 2024
1 parent 06cbce7 commit 0fbdbb2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ import {type ActionHook} from './types'

/** @internal */
export interface GetHookCollectionStateProps<T, K> {
/**
* Arguments that will be received by the action hooks, `onComplete` will be added by the HookStateContainer component.
*/
args: T
children: (props: {states: K[]}) => ReactNode
hooks: ActionHook<T, K>[]
hooks: ActionHook<T & {onComplete: () => void}, K>[]
onReset?: () => void
/**
* Name for the hook group. If provided, only hooks with the same group name will be included in the collection.
*/
group?: string
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Action<Args, Description> {
/** @internal */
export interface RenderActionCollectionProps {
actions: Action<DocumentActionProps, DocumentActionDescription>[]
actionProps: DocumentActionProps
actionProps: Omit<DocumentActionProps, 'onComplete'>
children: (props: {states: DocumentActionDescription[]}) => React.ReactNode
onActionComplete?: () => void
group?: DocumentActionGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,35 +134,36 @@ export const DocumentPanelHeader = memo(
{menuButtonNodes.map((item) => (
<PaneHeaderActionButton key={item.key} node={item} />
))}
{editState && (
<RenderActionCollectionState
actions={actions || []}
actionProps={editState}
group="paneActions"
>
{({states}) => (
<ActionDialogWrapper actionStates={states} referenceElement={referenceElement}>
{({handleAction}) => (
<div ref={setReferenceElement}>
<PaneContextMenuButton
nodes={contextMenuNodes}
key="context-menu"
actionsNodes={states?.map((actionState, actionIndex) => (
<ActionMenuListItem
key={actionState.label}
actionState={actionState}
disabled={Boolean(actionState.disabled)}
index={actionIndex}
onAction={handleAction}
/>
))}
/>
</div>
)}
</ActionDialogWrapper>
)}
</RenderActionCollectionState>
)}

<RenderActionCollectionState
actions={actions || []}
// @ts-expect-error TODO: fix the document actions
actionProps={editState}
group="paneActions"
>
{({states}) => (
<ActionDialogWrapper actionStates={states} referenceElement={referenceElement}>
{({handleAction}) => (
<div ref={setReferenceElement}>
<PaneContextMenuButton
nodes={contextMenuNodes}
key="context-menu"
actionsNodes={states?.map((actionState, actionIndex) => (
<ActionMenuListItem
key={actionState.label}
actionState={actionState}
disabled={Boolean(actionState.disabled)}
index={actionIndex}
onAction={handleAction}
/>
))}
/>
</div>
)}
</ActionDialogWrapper>
)}
</RenderActionCollectionState>
{showSplitPaneButton && (
<Button
aria-label={t('buttons.split-pane-button.aria-label')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Menu} from '@sanity/ui'
import {useCallback, useId, useMemo, useState} from 'react'
import {type ReactNode, useCallback, useId, useMemo, useState} from 'react'
import {
ContextMenuButton,
type DocumentActionDescription,
Expand All @@ -25,7 +25,7 @@ export function ActionDialogWrapper({
referenceElement,
}: {
actionStates: DocumentActionDescription[]
children: ({handleAction}: {handleAction: (idx: number) => void}) => React.ReactNode
children: ({handleAction}: {handleAction: (idx: number) => void}) => ReactNode
referenceElement?: HTMLElement | null
}) {
const [actionIndex, setActionIndex] = useState(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const DocumentStatusBarActions = memo(function DocumentStatusBarActions()
// component={}
// onActionComplete={handleActionComplete}
actions={actions}
// @ts-expect-error TODO: fix the document actions
actionProps={editState}
group="default"
>
Expand Down

0 comments on commit 0fbdbb2

Please sign in to comment.