Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post author selector with FormTokenField component. #25420

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
8fd66e5
Components: Implement a combobox control.
epiqueras Jan 15, 2020
c0bc82f
Components: Update Downshift.
epiqueras Feb 20, 2020
35ed682
Components: Update Downshift.
epiqueras May 18, 2020
e7dcb29
New post author selector, initial scaffolding.
adamsilverstein Jun 16, 2020
d4c149f
New post author selector, async work.
adamsilverstein Jun 17, 2020
1fe7700
Complete initial implementation.
adamsilverstein Jun 19, 2020
9061e9b
Cleanup.
adamsilverstein Jun 19, 2020
d679caa
Clean up user selection and search.
adamsilverstein Jun 19, 2020
c0ced2b
Update packages/editor/src/components/post-author/enhanced-post-autho…
adamsilverstein Jun 24, 2020
03ccfad
merge
adamsilverstein Jun 24, 2020
69e4626
Clean up checks, return a single value from selector.
adamsilverstein Jun 24, 2020
79a2523
Change element keys to author ids.
adamsilverstein Jun 24, 2020
a649ad6
Refresh the user list when the field value changes or the selection i…
adamsilverstein Jun 24, 2020
99a9f2d
Refresh the user list when the field value changes or the selection i…
adamsilverstein Jun 25, 2020
ed75df8
Remove ‘value’ from author objects.
adamsilverstein Jun 25, 2020
c467b5c
Remove unused id from ComboboxControl.
adamsilverstein Jun 25, 2020
ef19538
use unshift
adamsilverstein Jun 25, 2020
e1d688d
remove tracking of selectedAuthor
adamsilverstein Jun 25, 2020
465c9e5
merge
adamsilverstein Jun 26, 2020
70a9029
merge
adamsilverstein Jun 26, 2020
f44987d
merge
adamsilverstein Jun 26, 2020
33c3259
Simplify.
adamsilverstein Jun 26, 2020
4491740
Merge branch 'master' into add/7385-author-combobox-2
adamsilverstein Jul 3, 2020
e55d62e
Use state.users.byId in getAuthor.
adamsilverstein Jul 3, 2020
9024b22
Track isLoading and latest available authors: grey out existing list …
adamsilverstein Jul 3, 2020
828662a
Use stableKey from getQueryParts.
adamsilverstein Jul 3, 2020
a89919a
Add isLoading with useSelect..
adamsilverstein Jul 3, 2020
7f07fec
Add they grayed out style.
adamsilverstein Jul 3, 2020
6364458
add an is-loading class when cobocox data is loading.
adamsilverstein Jul 3, 2020
6630997
Add an is-loading class when loading
adamsilverstein Jul 3, 2020
94f07f8
Improve component import.
adamsilverstein Jul 3, 2020
bf0c15e
Merge branch 'master' into add/7385-author-combobox-2
adamsilverstein Jul 9, 2020
33f5cf8
Keys can be empty.
adamsilverstein Jul 9, 2020
a5c4ef2
Remove extraneous spread
adamsilverstein Jul 9, 2020
254c07a
Update naming to authorID, restore spread.
adamsilverstein Jul 9, 2020
d700436
Switch to `initialSelectedItem`; improve selected item matching with …
adamsilverstein Jul 9, 2020
f92239e
Revert changes to post-author check.
adamsilverstein Jul 9, 2020
2f48155
Remove latestAvailableAuthors and use spinner instead for load.
adamsilverstein Jul 9, 2020
a0bf0a2
cleanup
adamsilverstein Jul 9, 2020
a325579
Editor still loads if page or template type is not set
noahtallen Jul 7, 2020
a379413
Create homepage state reducer
noahtallen Jul 7, 2020
62b37d7
Remove initial state from PHP
noahtallen Jul 7, 2020
4af2c1c
Move home page resolution to client
noahtallen Jul 7, 2020
95124bf
Consolidate entityId logic
noahtallen Jul 9, 2020
9fe3fea
Consolidate activePage?.path
noahtallen Jul 9, 2020
e855102
Rework setupstate
noahtallen Jul 9, 2020
f9b2d52
Load home data over API
noahtallen Jul 9, 2020
6265ec3
Rename camelcase
noahtallen Jul 13, 2020
631e815
Remove templateId from setPage
noahtallen Jul 13, 2020
0d30cca
Naive cache results of findTemplate
noahtallen Jul 14, 2020
3a1da28
Rename cache variable
noahtallen Jul 14, 2020
7e6e1e3
Add text domain to setting translation
noahtallen Jul 14, 2020
f3d2b40
Fix existing JS unit tests
noahtallen Jul 14, 2020
821ced6
Fix e2e test
noahtallen Jul 15, 2020
24ef5c6
merge from origin/master
adamsilverstein Aug 14, 2020
fe3d31c
Merge branch 'master' into add/7385-author-combobox-2
adamsilverstein Aug 14, 2020
8a80e6a
update after merge from origin/master
adamsilverstein Aug 14, 2020
06a57c0
Merge branch 'master' into add/7385-author-combobox-2
adamsilverstein Aug 14, 2020
a7a79b5
Revert whitespace change.
adamsilverstein Aug 14, 2020
d97d175
Remove unnecessary spread.
adamsilverstein Aug 14, 2020
66f023c
Simplify to single useSelect.
adamsilverstein Aug 14, 2020
e3d043c
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Aug 14, 2020
cc5a78e
Merge branch 'master' into add/7385-author-combobox-2
adamsilverstein Aug 14, 2020
0134961
Fixes for js lint.
adamsilverstein Aug 14, 2020
2514345
Ensure the dropdown list is outlined when non-empty.
adamsilverstein Aug 14, 2020
7ff6bb6
Restore use of compose.
adamsilverstein Aug 14, 2020
ea2921f
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Aug 26, 2020
757aa02
Merge branch 'master' into add/7385-author-combobox-2
adamsilverstein Aug 26, 2020
40022d9
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 3, 2020
827111e
Merge remote-tracking branch 'origin/master' into add/7385-author-com…
youknowriad Sep 8, 2020
b00e636
Avoid getAuthor and getAuthors
youknowriad Sep 8, 2020
fb528ff
deprecate getAuthors
youknowriad Sep 8, 2020
41e87ae
Small refactoring
youknowriad Sep 8, 2020
5f52dd9
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 9, 2020
2383f1c
Polish.
jasmussen Sep 9, 2020
3c47fa8
Only set field value once postAuthor is available.
adamsilverstein Sep 10, 2020
f991486
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 11, 2020
f7c4c34
Merge branch 'master' of github.com:WordPress/gutenberg
adamsilverstein Sep 11, 2020
8760587
Merge branch 'master' into add/7385-author-combobox-2
adamsilverstein Sep 11, 2020
ce040ce
Merge branch 'master' into add/7384-author-picker-with-tag-autocomple…
adamsilverstein Sep 17, 2020
56ba101
Post author selector with FormTokenField component.
adamsilverstein Sep 17, 2020
20da426
Cleanup.
adamsilverstein Sep 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function PostAuthorEdit( { isSelected, context, attributes, setAttributes } ) {

const { authorId, authorDetails, authors } = useSelect(
( select ) => {
const { getEditedEntityRecord, getUser, getAuthors } = select(
const { getEditedEntityRecord, getUser, getUsers } = select(
'core'
);
const _authorId = getEditedEntityRecord(
Expand All @@ -35,7 +35,7 @@ function PostAuthorEdit( { isSelected, context, attributes, setAttributes } ) {
return {
authorId: _authorId,
authorDetails: _authorId ? getUser( _authorId ) : null,
authors: getAuthors(),
authors: getUsers( { who: 'authors' } ),
};
},
[ postType, postId ]
Expand Down
29 changes: 19 additions & 10 deletions packages/components/src/combobox-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
*/
import { useCombobox } from 'downshift';
import classnames from 'classnames';
import { isEqual } from 'lodash';

/**
* WordPress dependencies
*/
import { check, chevronDown } from '@wordpress/icons';

/**
* Internal dependencies
*/
import { Button, Dashicon } from '../';
import { Button, Icon, Spinner } from '../';

const itemToString = ( item ) => item && item.name;
export default function ComboboxControl( {
className,
hideLabelFromVision,
label,
isLoading,
options: items,
onInputValueChange: onInputValueChange,
onChange: onSelectedItemChange,
value: _selectedItem,
initialSelectedItem,
} ) {
const {
getLabelProps,
Expand All @@ -30,15 +37,16 @@ export default function ComboboxControl( {
highlightedIndex,
selectedItem,
} = useCombobox( {
initialSelectedItem: items[ 0 ],
initialSelectedItem,
items,
itemToString,
onInputValueChange,
onSelectedItemChange,
selectedItem: _selectedItem,
} );
const menuProps = getMenuProps( {
className: 'components-combobox-control__menu',
className: classnames( 'components-combobox-control__menu', {
'is-loading': isLoading,
} ),
} );
// We need this here, because the null active descendant is not
// fully ARIA compliant.
Expand Down Expand Up @@ -68,6 +76,7 @@ export default function ComboboxControl( {
>
{ label }
</label>
{ isLoading && <Spinner /> }
<div
{ ...getComboboxProps( {
className: 'components-combobox-control__button',
Expand All @@ -86,9 +95,9 @@ export default function ComboboxControl( {
className: 'components-combobox-control__button-button',
} ) }
>
<Dashicon
icon="arrow-down-alt2"
<Icon
className="components-combobox-control__button-icon"
icon={ chevronDown }
/>
</Button>
</div>
Expand All @@ -111,10 +120,10 @@ export default function ComboboxControl( {
style: item.style,
} ) }
>
{ item === selectedItem && (
<Dashicon
icon="saved"
{ isEqual( item, selectedItem ) && (
<Icon
className="components-combobox-control__item-icon"
icon={ check }
/>
) }
{ item.name }
Expand Down
54 changes: 31 additions & 23 deletions packages/components/src/combobox-control/style.scss
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
.components-combobox-control {
position: relative;
margin-bottom: $grid-unit-15;
}

.components-combobox-control__label {
display: block;
margin-bottom: 5px;
margin-bottom: $grid-unit-05;
}

.components-combobox-control__button {
border: 1px solid $gray-600;
border-radius: 4px;
display: inline-block;
min-height: 30px;
min-width: 130px;
min-height: $button-size-small;
min-width: 140px;
position: relative;
text-align: left;

&:focus {
border-color: var(--wp-admin-theme-color);
}

&-input {
border: none;
height: calc(100% - 2px);
left: 1px;
padding: 0 4px;
.components-combobox-control__button-input {
height: 100%;
width: 100%;
left: 0;
top: 0;
position: absolute;
top: 1px;
width: calc(100% - 2px);
}
margin: 0;

&-button:hover {
box-shadow: none !important;
@include input-control;
}

&-icon {
.components-combobox-control__button-icon {
height: 100%;
padding: 0 4px;
padding: 0;
position: absolute;
right: 0;
top: 0;
}

.components-combobox-control__button-button {
height: $button-size-small + $border-width + $border-width;

&:focus:not(:disabled) {
box-shadow: none;
}
}
}

.components-combobox-control__menu {
Expand All @@ -49,20 +51,26 @@
padding: 0;
position: absolute;
z-index: z-index(".components-popover");

&:not(:empty) {
margin: $grid-unit-15 0 0 0;
border-radius: $radius-block-ui;
border: $border-width solid $gray-900;
}
}

.components-combobox-control__item {
align-items: center;
display: flex;
list-style-type: none;
padding: 10px 5px 10px 25px;
padding: $grid-unit-10 $grid-unit-15 $grid-unit-10 ($button-size-small + $grid-unit-15);

&.is-highlighted {
background: $gray-200;
}

&-icon {
margin-left: -20px;
margin-right: 0;
.components-combobox-control__item-icon {
margin-left: -$button-size-small - $grid-unit-05;
margin-right: $grid-unit-05;
}
}
22 changes: 17 additions & 5 deletions packages/components/src/form-token-field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ class FormTokenField extends Component {
[ this.getIndexOfInput(), 0 ].concat( tokensToAdd )
);
this.props.onChange( newValue );
if ( this.props.blurAfterSelection ) {
this.onBlur();
}
}
}

Expand Down Expand Up @@ -620,6 +623,17 @@ class FormTokenField extends Component {
} );
}

let helpMessage;
if ( this.props.helpMessage !== false ) {
helpMessage = this.props.helpMessage;
} else {
helpMessage = this.props.tokenizeOnSpace
? __(
'Separate with commas, spaces, or the Enter key.'
)
: __( 'Separate with commas or the Enter key.' )
}

// Disable reason: There is no appropriate role which describes the
// input container intended accessible usability.
// TODO: Refactor click detection to use blur to stop propagation.
Expand Down Expand Up @@ -661,11 +675,7 @@ class FormTokenField extends Component {
id={ `components-form-token-suggestions-howto-${ instanceId }` }
className="components-form-token-field__help"
>
{ this.props.tokenizeOnSpace
? __(
'Separate with commas, spaces, or the Enter key.'
)
: __( 'Separate with commas or the Enter key.' ) }
{ helpMessage }
</p>
</div>
);
Expand All @@ -683,6 +693,8 @@ FormTokenField.defaultProps = {
onInputChange: () => {},
isBorderless: false,
disabled: false,
blurAfterSelection: false,
helpMessage: false,
tokenizeOnSpace: false,
messages: {
added: __( 'Item added.' ),
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/form-token-field/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
font-style: italic;
}

.components-form-token-field {
width: 100%;
}

.is-active.components-form-author_selector .components-form-token-field__token,
.components-form-author_selector .components-form-token-field__remove-token.components-button {
display: none;
}

.components-form-author_selector .components-form-token-field__token-text {
background: transparent;
}

// Tokens
.components-form-token-field__token {
font-size: $default-font-size;
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export { default as ClipboardButton } from './clipboard-button';
export { default as ColorIndicator } from './color-indicator';
export { default as ColorPalette } from './color-palette';
export { default as ColorPicker } from './color-picker';
export { default as ComboboxControl } from './combobox-control';
export { default as CustomSelectControl } from './custom-select-control';
export { default as Dashicon } from './dashicon';
export { DateTimePicker, DatePicker, TimePicker } from './date-time';
Expand Down
3 changes: 3 additions & 0 deletions packages/core-data/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const isRequestingEmbedPreview = createRegistrySelector(
* @return {Array} Authors list.
*/
export function getAuthors( state ) {
deprecated( "select( 'core' ).getAuthors()", {
alternative: "select( 'core' ).getUsers({ who: 'authors' })",
} );
return getUserQueryResults( state, 'authors' );
}

Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/post-author/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function PostAuthorCheck( {
authors,
children,
} ) {
if ( ! hasAssignAuthorAction || authors.length < 2 ) {
if ( ! hasAssignAuthorAction || ! authors || authors.length < 2 ) {
return null;
}

Expand All @@ -40,7 +40,7 @@ export default compose( [
false
),
postType: select( 'core/editor' ).getCurrentPostType(),
authors: select( 'core' ).getAuthors(),
authors: select( 'core' ).getUsers( { who: 'authors' } ),
};
} ),
withInstanceId,
Expand Down
Loading