Skip to content

Commit

Permalink
Resolve rebase errors
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 30, 2020
1 parent 4689533 commit 49f0b2e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 82 deletions.
121 changes: 40 additions & 81 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ function LinkControl( {
const instanceId = useInstanceId( LinkControl );
const [ inputValue, setInputValue ] = useState( ( value && value.url ) || '' );
const [ isEditingLink, setIsEditingLink ] = useState( ! value || ! value.url );
const [ isResolvingLink, setIsResolvingLink ] = useState( false );
const [ isResolvingLink, setIsResolvingLink ] = useState( false );
const [ errorMsg, setErrorMsg ] = useState( null );
const isEndingEditWithFocus = useRef( false );

const { fetchSearchSuggestions } = useSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
Expand Down Expand Up @@ -314,41 +315,20 @@ function LinkControl( {
}

return (
<LinkControlSearchItem
key={ `${ suggestion.id }-${ suggestion.type }` }
itemProps={ buildSuggestionItemProps( suggestion, index ) }
suggestion={ suggestion }
onClick={ () => {
stopEditing();
onChange( { ...value, ...suggestion } );
} }
isSelected={ index === selectedSuggestion }
isURL={ directLinkEntryTypes.includes( suggestion.type.toLowerCase() ) }
searchTerm={ inputValue }
/>
) ) }
;
<LinkControlSearchItem
key={ `${ suggestion.id }-${ suggestion.type }` }
itemProps={ buildSuggestionItemProps( suggestion, index ) }
suggestion={ suggestion }
onClick={ () => {
stopEditing();
onChange( { ...value, ...suggestion } );
} }
isSelected={ index === selectedSuggestion }
isURL={ directLinkEntryTypes.includes( suggestion.type.toLowerCase() ) }
searchTerm={ inputValue }
/>
);
} ) }

{ showCreatePages && createEmptyPage && ! isInitialSuggestions && ! isSingleDirectEntryResult && (
<LinkControlSearchCreate
searchTerm={ inputValue }
onClick={ async () => {
setIsResolvingLink( true );
const newPage = await createEmptyPage( inputValue );
// TODO: handle error from API
onChange( {
id: newPage.id,
title: newPage.title.raw, // TODO: use raw or rendered?
url: newPage.link,
type: newPage.type,
} );
setIsResolvingLink( false );
setIsEditingLink( false );
onChange( _result );
} }
/>
) }
</div>

</div>
Expand All @@ -362,42 +342,40 @@ function LinkControl( {
ref={ wrapperNode }
className="block-editor-link-control"
>
{ isResolvingLink && (
<div
className={ classnames( 'block-editor-link-control__search-item', {
'is-current': true,
} ) }
>
<span className="block-editor-link-control__search-item-header">
<span
className="block-editor-link-control__search-item-title"
>
{ __( 'Creating Page' ) }
</span>
<span className="block-editor-link-control__search-item-info">
{ __( 'Your new Page is being created' ) }.
</span>
</span>
</div>


{ isEditingLink || ! value ?
<LinkControlSearchInput
{ isResolvingLink && (
<div
className={ classnames( 'block-editor-link-control__search-item', {
'is-current': true,
} ) }
>
<span className="block-editor-link-control__search-item-header">
<span
className="block-editor-link-control__search-item-title"
>
{ __( 'Creating Page' ) }
</span>
<span className="block-editor-link-control__search-item-info">
{ __( 'Your new Page is being created' ) }.
</span>
</span>
</div>
) }

{ isEditingLink || ! value
? <LinkControlSearchInput
value={ inputValue }
onChange={ onInputChange }
onSelect={ ( suggestion ) => {
stopEditing();
onChange( { ...value, ...suggestion } );
handleSelectSuggestion( suggestion, value )();
} }
renderSuggestions={ renderSearchResults }
fetchSuggestions={ getSearchHandler }
onReset={ resetInput }
showInitialSuggestions={ showInitialSuggestions }
/> :
) }

{ ( ! isEditingLink && ! isResolvingLink ) && (
<Fragment>
errorMsg={ errorMsg }
/>
: <Fragment>
<VisuallyHidden>
<p aria-label={ __( 'Currently selected' ) } id={ `current-link-label-${ instanceId }` }>
{ __( 'Currently selected' ) }:
Expand Down Expand Up @@ -439,25 +417,6 @@ function LinkControl( {
/>
</Fragment>
}

{ isEditingLink && ! isResolvingLink && (
<LinkControlSearchInput
value={ inputValue }
onChange={ onInputChange }
onSelect={ ( suggestion ) => {
handleSelectSuggestion( suggestion, value )();
} }
renderSuggestions={ renderSearchResults }
fetchSuggestions={ getSearchHandler }
onReset={ resetInput }
showInitialSuggestions={ showInitialSuggestions }
errorMsg={ errorMsg }
/>
) }

{ ! isEditingLink && ! isResolvingLink && (
<LinkControlSettingsDrawer value={ value } settings={ settings } onChange={ onChange } />
) }
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Basic rendering should render 1`] = `"<div class=\\"block-editor-link-control\\"><form><div class=\\"block-editor-link-control__search-input-wrapper\\"><div class=\\"components-base-control block-editor-url-input block-editor-link-control__search-input\\"><div class=\\"components-base-control__field\\"><input type=\\"text\\" aria-label=\\"URL\\" required=\\"\\" placeholder=\\"Search or type url\\" role=\\"combobox\\" aria-expanded=\\"false\\" aria-autocomplete=\\"list\\" aria-owns=\\"block-editor-url-input-suggestions-0\\" value=\\"\\"></div></div><button type=\\"reset\\" disabled=\\"\\" class=\\"components-button block-editor-link-control__search-reset has-icon\\" aria-label=\\"Reset\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewBox=\\"0 0 20 20\\" class=\\"dashicon dashicons-no-alt\\"><path d=\\"M14.95 6.46L11.41 10l3.54 3.54-1.41 1.41L10 11.42l-3.53 3.53-1.42-1.42L8.58 10 5.05 6.47l1.42-1.42L10 8.58l3.54-3.53z\\"></path></svg></button></div><div role=\\"alert\\" aria-live=\\"assertive\\"></div></form></div>"`;
exports[`Basic rendering should render 1`] = `"<div tabindex=\\"-1\\" class=\\"block-editor-link-control\\"><form><div class=\\"block-editor-link-control__search-input-wrapper\\"><div class=\\"components-base-control block-editor-url-input block-editor-link-control__search-input\\"><div class=\\"components-base-control__field\\"><input type=\\"text\\" aria-label=\\"URL\\" required=\\"\\" placeholder=\\"Search or type url\\" role=\\"combobox\\" aria-expanded=\\"false\\" aria-autocomplete=\\"list\\" aria-owns=\\"block-editor-url-input-suggestions-0\\" value=\\"\\"></div></div><button type=\\"reset\\" disabled=\\"\\" class=\\"components-button block-editor-link-control__search-reset has-icon\\" aria-label=\\"Reset\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewBox=\\"0 0 20 20\\" class=\\"dashicon dashicons-no-alt\\"><path d=\\"M14.95 6.46L11.41 10l3.54 3.54-1.41 1.41L10 11.42l-3.53 3.53-1.42-1.42L8.58 10 5.05 6.47l1.42-1.42L10 8.58l3.54-3.53z\\"></path></svg></button></div><div role=\\"alert\\" aria-live=\\"assertive\\"></div></form></div>"`;

0 comments on commit 49f0b2e

Please sign in to comment.