From a49fe20081f48630d169a534fa1dd58e0ea447c3 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 6 May 2024 11:34:46 +0100 Subject: [PATCH 1/4] DataViews: Type the ItemActions component --- .../src/{item-actions.js => item-actions.tsx} | 79 ++++++++++++++++--- packages/dataviews/src/types.ts | 78 ++++++++++++++++++ 2 files changed, 146 insertions(+), 11 deletions(-) rename packages/dataviews/src/{item-actions.js => item-actions.tsx} (72%) diff --git a/packages/dataviews/src/item-actions.js b/packages/dataviews/src/item-actions.tsx similarity index 72% rename from packages/dataviews/src/item-actions.js rename to packages/dataviews/src/item-actions.tsx index 60a120a2b5c60d..a4563a00d317cc 100644 --- a/packages/dataviews/src/item-actions.js +++ b/packages/dataviews/src/item-actions.tsx @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import type { MouseEventHandler } from 'react'; + /** * WordPress dependencies */ @@ -15,6 +20,7 @@ import { moreVertical } from '@wordpress/icons'; * Internal dependencies */ import { unlock } from './lock-unlock'; +import type { Action, ActionModal as ActionModalType, Item } from './types'; const { DropdownMenuV2: DropdownMenu, @@ -24,7 +30,48 @@ const { kebabCase, } = unlock( componentsPrivateApis ); -function ButtonTrigger( { action, onClick } ) { +interface ButtonTriggerProps { + action: Action; + onClick: MouseEventHandler; +} + +interface DropdownMenuItemTriggerProps { + action: Action; + onClick: MouseEventHandler; +} + +interface ActionModalProps { + action: ActionModalType; + items: Item[]; + closeModal?: () => void; + onActionStart?: ( items: Item[] ) => void; + onActionPerformed?: ( items: Item[] ) => void; +} + +interface ActionWithModalProps extends ActionModalProps { + ActionTrigger: ( + props: ButtonTriggerProps | DropdownMenuItemTriggerProps + ) => JSX.Element; + isBusy?: boolean; +} + +interface ActionsDropdownMenuGroupProps { + actions: Action[]; + item: Item; +} + +interface ItemActionsProps { + item: Item; + actions: Action[]; + isCompact: boolean; +} + +interface CompactItemActionsProps { + item: Item; + actions: Action[]; +} + +function ButtonTrigger( { action, onClick }: ButtonTriggerProps ) { return (