Date: Fri, 10 May 2024 11:33:44 +0200
Subject: [PATCH 27/32] Fix rebase
---
packages/dataviews/src/item-actions.js | 29 ++++++++++++++++++++------
packages/dataviews/src/view-list.tsx | 4 +++-
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/packages/dataviews/src/item-actions.js b/packages/dataviews/src/item-actions.js
index 7931d2e6853de..60a120a2b5c60 100644
--- a/packages/dataviews/src/item-actions.js
+++ b/packages/dataviews/src/item-actions.js
@@ -47,7 +47,13 @@ function DropdownMenuItemTrigger( { action, onClick } ) {
);
}
-export function ActionModal( { action, item, closeModal, onActionStart, onActionPerformed } ) {
+export function ActionModal( {
+ action,
+ items,
+ closeModal,
+ onActionStart,
+ onActionPerformed,
+} ) {
return (
-
+
);
}
-function ActionWithModal( { action, item, ActionTrigger, onActionStart, onActionPerformed, isBusy } ) {
+export function ActionWithModal( {
+ action,
+ items,
+ ActionTrigger,
+ onActionStart,
+ onActionPerformed,
+ isBusy,
+} ) {
const [ isModalOpen, setIsModalOpen ] = useState( false );
const actionTriggerProps = {
action,
@@ -79,10 +96,10 @@ function ActionWithModal( { action, item, ActionTrigger, onActionStart, onAction
{ isModalOpen && (
setIsModalOpen( false ) }
onActionStart={ onActionStart }
- onActionPerformed={ onActionPerformed}
+ onActionPerformed={ onActionPerformed }
/>
) }
>
diff --git a/packages/dataviews/src/view-list.tsx b/packages/dataviews/src/view-list.tsx
index 90c1a19583774..450b51025983d 100644
--- a/packages/dataviews/src/view-list.tsx
+++ b/packages/dataviews/src/view-list.tsx
@@ -234,10 +234,12 @@ function ListItem( {
{ isModalOpen && (
setIsModalOpen( false )
}
+ onActionStart={ () => {} }
+ onActionPerformed={ () => {} }
/>
) }
From 6afa65262b85ba581b18710e9313b2f8d8fc0eac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Maneiro?=
<583546+oandregal@users.noreply.github.com>
Date: Mon, 13 May 2024 15:14:41 +0200
Subject: [PATCH 28/32] Manage item removal
---
packages/dataviews/src/view-list.tsx | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/packages/dataviews/src/view-list.tsx b/packages/dataviews/src/view-list.tsx
index 450b51025983d..7673f0e98848a 100644
--- a/packages/dataviews/src/view-list.tsx
+++ b/packages/dataviews/src/view-list.tsx
@@ -343,6 +343,24 @@ export default function ViewList( props: ListViewProps ) {
defaultActiveId: getItemDomId( selectedItem ),
} );
+ // Manage focused item, when the active one is removed from the list.
+ const isActiveIdInList = store.useState(
+ ( state: { items: any[]; activeId: any } ) =>
+ state.items.some(
+ ( item: { id: any } ) => item.id === state.activeId
+ )
+ );
+ useEffect( () => {
+ if ( ! isActiveIdInList ) {
+ // Prefer going down, except if there is no item below (last item), then go up (last item in list).
+ if ( store.down() ) {
+ store.move( store.down() );
+ } else if ( store.up() ) {
+ store.move( store.up() );
+ }
+ }
+ }, [ isActiveIdInList ] );
+
const hasData = data?.length;
if ( ! hasData ) {
return (
From 7052fd2eecab0fada1fd93db8077f56097d77746 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Maneiro?=
<583546+oandregal@users.noreply.github.com>
Date: Mon, 13 May 2024 18:22:47 +0200
Subject: [PATCH 29/32] Prevent the default behaviour and move up/down
explicitely
---
packages/dataviews/src/view-list.tsx | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/packages/dataviews/src/view-list.tsx b/packages/dataviews/src/view-list.tsx
index 7673f0e98848a..888b088a43dca 100644
--- a/packages/dataviews/src/view-list.tsx
+++ b/packages/dataviews/src/view-list.tsx
@@ -279,6 +279,30 @@ function ListItem( {
label={ __( 'Actions' ) }
disabled={ ! actions.length }
className="dataviews-all-actions-button"
+ onKeyDown={ ( event: {
+ key: string;
+ preventDefault: () => any;
+ } ) => {
+ if (
+ event.key ===
+ 'ArrowDown'
+ ) {
+ // Prevent the default behaviour (open dropdown menu) and go down.
+ event.preventDefault();
+ store.move(
+ store.down()
+ );
+ }
+ if (
+ event.key === 'ArrowUp'
+ ) {
+ // Prevent the default behavior (open dropdown menu) and go up.
+ event.preventDefault();
+ store.move(
+ store.up()
+ );
+ }
+ } }
/>
}
/>
From 249d86e5cd4110e02e106a90874cf01ce2b3929d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Maneiro?=
<583546+oandregal@users.noreply.github.com>
Date: Mon, 13 May 2024 19:15:41 +0200
Subject: [PATCH 30/32] Primary actions + all actions share visibility logic
---
packages/dataviews/src/style.scss | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss
index 893f05968fa16..d8537a91764e7 100644
--- a/packages/dataviews/src/style.scss
+++ b/packages/dataviews/src/style.scss
@@ -412,14 +412,14 @@
}
}
- .dataviews-item-actions .components-button:not(.dataviews-all-actions-button) {
+ .dataviews-item-actions .components-button {
opacity: 0;
}
- &:focus-within,
+ &.is-selected,
&.is-hovered,
- &:hover {
- .dataviews-item-actions .components-button:not(.dataviews-all-actions-button) {
+ &:focus-within {
+ .dataviews-item-actions .components-button {
opacity: 1;
}
}
From adf56e27be8c119822aef60eea7a3a875b6952dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Maneiro?=
<583546+oandregal@users.noreply.github.com>
Date: Mon, 13 May 2024 19:56:44 +0200
Subject: [PATCH 31/32] Improve types
---
packages/dataviews/src/view-list.tsx | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/packages/dataviews/src/view-list.tsx b/packages/dataviews/src/view-list.tsx
index 888b088a43dca..169e18e944486 100644
--- a/packages/dataviews/src/view-list.tsx
+++ b/packages/dataviews/src/view-list.tsx
@@ -2,6 +2,9 @@
* External dependencies
*/
import clsx from 'clsx';
+// Import CompositeStore type, which is not exported from @wordpress/components.
+// eslint-disable-next-line no-restricted-imports
+import type { CompositeStore } from '@ariakit/react';
/**
* WordPress dependencies
@@ -40,15 +43,14 @@ import { ActionsDropdownMenuGroup, ActionModal } from './item-actions';
interface Action {
callback: ( items: Item[] ) => void;
- hideModalHeader: any;
icon: any;
id: string;
isDestructive: boolean | undefined;
- isEligible: any;
- isPrimary: boolean;
+ isEligible: ( item: Item ) => boolean | undefined;
+ isPrimary: boolean | undefined;
label: string;
modalHeader: string;
- RenderModal: any;
+ RenderModal: ( props: any ) => JSX.Element;
}
interface ListViewProps {
@@ -71,7 +73,7 @@ interface ListViewItemProps {
mediaField?: NormalizedField;
onSelect: ( item: Item ) => void;
primaryField?: NormalizedField;
- store: any;
+ store: CompositeStore;
visibleFields: NormalizedField[];
}
@@ -281,7 +283,7 @@ function ListItem( {
className="dataviews-all-actions-button"
onKeyDown={ ( event: {
key: string;
- preventDefault: () => any;
+ preventDefault: () => void;
} ) => {
if (
event.key ===
From 7d76a8e1baf1351e1b2b2524da2a68682b93866b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Maneiro?=
<583546+oandregal@users.noreply.github.com>
Date: Tue, 14 May 2024 10:19:29 +0200
Subject: [PATCH 32/32] Update classes
---
packages/dataviews/src/style.scss | 6 +++---
packages/dataviews/src/view-list.tsx | 3 +--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss
index d8537a91764e7..aa46489db6392 100644
--- a/packages/dataviews/src/style.scss
+++ b/packages/dataviews/src/style.scss
@@ -412,14 +412,14 @@
}
}
- .dataviews-item-actions .components-button {
+ .dataviews-view-list__item-actions .components-button {
opacity: 0;
}
&.is-selected,
&.is-hovered,
&:focus-within {
- .dataviews-item-actions .components-button {
+ .dataviews-view-list__item-actions .components-button {
opacity: 1;
}
}
@@ -527,7 +527,7 @@
}
}
- .dataviews-item-actions {
+ .dataviews-view-list__item-actions {
padding-top: $grid-unit-20;
padding-right: $grid-unit-40;
}
diff --git a/packages/dataviews/src/view-list.tsx b/packages/dataviews/src/view-list.tsx
index 169e18e944486..022e2a7222f77 100644
--- a/packages/dataviews/src/view-list.tsx
+++ b/packages/dataviews/src/view-list.tsx
@@ -209,7 +209,7 @@ function ListItem( {
void;