Skip to content

Commit

Permalink
Editor: Add loading state to the 'PostAuthorCombobox' component (#68991)
Browse files Browse the repository at this point in the history
* Add loading indicator to author selector

* Only show "No items found" when isLoading is false

* Remove unitended change

* Update packages/components/src/combobox-control/types.ts

Co-authored-by: Marco Ciampini <[email protected]>

* Revert "Only show "No items found" when isLoading is false"

This reverts commit 76488c1.

* Only show the suggestion list when the component isn’t loading data

* Document `isLoading` prop in readme

* Add is loading to Combobox storybook

* Match readme description to type.js description

* Revert combobox changes

---------

Co-authored-by: Marco Ciampini <[email protected]>
  • Loading branch information
adamsilverstein and ciampo authored Feb 6, 2025
1 parent 96b12e5 commit e850c68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/editor/src/components/post-author/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default function PostAuthorCombobox() {
const [ fieldValue, setFieldValue ] = useState();

const { editPost } = useDispatch( editorStore );
const { authorId, authorOptions } = useAuthorsQuery( fieldValue );
const { authorId, authorOptions, isLoading } =
useAuthorsQuery( fieldValue );

/**
* Handle author selection.
Expand Down Expand Up @@ -51,6 +52,7 @@ export default function PostAuthorCombobox() {
onChange={ handleSelect }
allowReset={ false }
hideLabelFromVision
isLoading={ isLoading }
/>
);
}
7 changes: 4 additions & 3 deletions packages/editor/src/components/post-author/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { store as editorStore } from '../../store';
import { AUTHORS_QUERY, BASE_QUERY } from './constants';

export function useAuthorsQuery( search ) {
const { authorId, authors, postAuthor } = useSelect(
const { authorId, authors, postAuthor, isLoading } = useSelect(
( select ) => {
const { getUser, getUsers } = select( coreStore );
const { getUser, getUsers, isResolving } = select( coreStore );
const { getEditedPostAttribute } = select( editorStore );
const _authorId = getEditedPostAttribute( 'author' );
const query = { ...AUTHORS_QUERY };
Expand All @@ -30,6 +30,7 @@ export function useAuthorsQuery( search ) {
authorId: _authorId,
authors: getUsers( query ),
postAuthor: getUser( _authorId, BASE_QUERY ),
isLoading: isResolving( 'getUsers', [ query ] ),
};
},
[ search ]
Expand Down Expand Up @@ -68,5 +69,5 @@ export function useAuthorsQuery( search ) {
return [ ...currentAuthor, ...fetchedAuthors ];
}, [ authors, postAuthor ] );

return { authorId, authorOptions, postAuthor };
return { authorId, authorOptions, postAuthor, isLoading };
}

1 comment on commit e850c68

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e850c68.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13181883570
📝 Reported issues:

Please sign in to comment.