{
field: NormalizedField< Item >;
item: Item;
isItemClickable: ( item: Item ) => boolean;
- onClickItem: ( item: Item ) => void;
+ onClickItem?: ( item: Item ) => void;
}
interface TableColumnCombinedProps< Item > {
@@ -52,7 +52,7 @@ interface TableColumnCombinedProps< Item > {
item: Item;
view: ViewTableType;
isItemClickable: ( item: Item ) => boolean;
- onClickItem: ( item: Item ) => void;
+ onClickItem?: ( item: Item ) => void;
}
interface TableColumnProps< Item > {
@@ -62,7 +62,7 @@ interface TableColumnProps< Item > {
column: string;
view: ViewTableType;
isItemClickable: ( item: Item ) => boolean;
- onClickItem: ( item: Item ) => void;
+ onClickItem?: ( item: Item ) => void;
}
interface TableRowProps< Item > {
@@ -77,7 +77,7 @@ interface TableRowProps< Item > {
getItemId: ( item: Item ) => string;
onChangeSelection: SetSelection;
isItemClickable: ( item: Item ) => boolean;
- onClickItem: ( item: Item ) => void;
+ onClickItem?: ( item: Item ) => void;
}
function TableColumn< Item >( {
@@ -118,12 +118,12 @@ function TableColumnField< Item >( {
const isItemClickableField = ( i: Item ) =>
isItemClickable( i ) && isPrimaryField;
- const clickableProps = getClickableItemProps(
+ const clickableProps = getClickableItemProps( {
item,
- isItemClickableField,
+ isItemClickable: isItemClickableField,
onClickItem,
- 'dataviews-view-table__cell-content'
- );
+ className: 'dataviews-view-table__cell-content',
+ } );
return (
(
- item: Item,
- isItemClickable: ( item: Item ) => boolean,
- onClickItem: ( item: Item ) => void,
- className: string
-) {
- if ( ! isItemClickable( item ) ) {
+export default function getClickableItemProps< Item >( {
+ item,
+ isItemClickable,
+ onClickItem,
+ className,
+}: {
+ item: Item;
+ isItemClickable: ( item: Item ) => boolean;
+ onClickItem?: ( item: Item ) => void;
+ className: string;
+} ) {
+ if ( ! isItemClickable( item ) || ! onClickItem ) {
return { className };
}
diff --git a/packages/dataviews/src/types.ts b/packages/dataviews/src/types.ts
index 861dc53404f91..0bce8b8cf2c08 100644
--- a/packages/dataviews/src/types.ts
+++ b/packages/dataviews/src/types.ts
@@ -510,7 +510,7 @@ export interface ViewBaseProps< Item > {
onChangeSelection: SetSelection;
selection: string[];
setOpenedFilter: ( fieldId: string ) => void;
- onClickItem: ( item: Item ) => void;
+ onClickItem?: ( item: Item ) => void;
isItemClickable: ( item: Item ) => boolean;
view: View;
}