Skip to content

Commit

Permalink
Align action types
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 14, 2024
1 parent ffaa966 commit 3e98949
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 41 deletions.
9 changes: 3 additions & 6 deletions packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import type { IconType } from '@wordpress/components';

/**
* External dependencies
*/
Expand Down Expand Up @@ -183,8 +178,10 @@ interface ActionBase {

/**
* The icon of the action. (Either a string or an SVG element)
* This should be IconType from the components package
* but that import is breaking typescript build for the moment.
*/
icon?: IconType;
icon?: any;

/**
* Whether the action is disabled.
Expand Down
60 changes: 25 additions & 35 deletions packages/dataviews/src/view-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { moreVertical } from '@wordpress/icons';
*/
import { unlock } from './lock-unlock';
import type {
Action,
Data,
Item,
NormalizedField,
Expand All @@ -41,18 +42,6 @@ import type {

import { ActionsDropdownMenuGroup, ActionModal } from './item-actions';

interface Action {
callback: ( items: Item[] ) => void;
icon: any;
id: string;
isDestructive: boolean | undefined;
isEligible: ( item: Item ) => boolean | undefined;
isPrimary: boolean | undefined;
label: string;
modalHeader: string;
RenderModal: ( props: any ) => JSX.Element;
}

interface ListViewProps {
actions: Action[];
data: Data;
Expand Down Expand Up @@ -215,7 +204,7 @@ function ListItem( {
width: 'auto',
} }
>
{ primaryAction && !! primaryAction.RenderModal && (
{ primaryAction && 'RenderModal' in primaryAction && (
<div role="gridcell">
<CompositeItem
store={ store }
Expand Down Expand Up @@ -247,28 +236,29 @@ function ListItem( {
</CompositeItem>
</div>
) }
{ primaryAction && ! primaryAction.RenderModal && (
<div role="gridcell" key={ primaryAction.id }>
<CompositeItem
store={ store }
render={
<Button
label={ primaryAction.label }
icon={ primaryAction.icon }
isDestructive={
primaryAction.isDestructive
}
size="compact"
onClick={ () =>
primaryAction.callback( [
item,
] )
}
/>
}
/>
</div>
) }
{ primaryAction &&
! ( 'RenderModal' in primaryAction ) && (
<div role="gridcell" key={ primaryAction.id }>
<CompositeItem
store={ store }
render={
<Button
label={ primaryAction.label }
icon={ primaryAction.icon }
isDestructive={
primaryAction.isDestructive
}
size="compact"
onClick={ () =>
primaryAction.callback( [
item,
] )
}
/>
}
/>
</div>
) }
<div role="gridcell">
<DropdownMenu
trigger={
Expand Down

0 comments on commit 3e98949

Please sign in to comment.