-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link Control require user to manually submit any changes (#50668)
* Implement initial shallow checking * Don’t assyne value when comparing value changes * Fix recrusive re-renders in hook Avoid passing a default when default is handled internally. Set default to be an object as that is what we are tracking. * Fix ENTER submission bug * Require settings changes to be “Applied” * Refactor for readability and tidy * Improve test naming * Add test for new UX * Improve fetching of settings * Rename hook to convey new purpose * Improve test coverage of test * Fix tab stops now Apply is disabled when there are no changes * Wait for settings drawer to open * Extract retrival of settings keys * Move setters to hook * Make API clearer to consumers of hook
- Loading branch information
Showing
5 changed files
with
179 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
packages/block-editor/src/components/link-control/use-internal-input-value.js
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
packages/block-editor/src/components/link-control/use-internal-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState, useEffect } from '@wordpress/element'; | ||
|
||
export default function useInternalValue( value ) { | ||
const [ internalValue, setInternalValue ] = useState( value || {} ); | ||
|
||
// If the value prop changes, update the internal state. | ||
useEffect( () => { | ||
setInternalValue( ( prevValue ) => { | ||
if ( value && value !== prevValue ) { | ||
return value; | ||
} | ||
|
||
return prevValue; | ||
} ); | ||
}, [ value ] ); | ||
|
||
const setInternalURLInputValue = ( nextValue ) => { | ||
setInternalValue( { | ||
...internalValue, | ||
url: nextValue, | ||
} ); | ||
}; | ||
|
||
const setInternalTextInputValue = ( nextValue ) => { | ||
setInternalValue( { | ||
...internalValue, | ||
title: nextValue, | ||
} ); | ||
}; | ||
|
||
const createSetInternalSettingValueHandler = | ||
( settingsKeys ) => ( nextValue ) => { | ||
// Only apply settings values which are defined in the settings prop. | ||
const settingsUpdates = Object.keys( nextValue ).reduce( | ||
( acc, key ) => { | ||
if ( settingsKeys.includes( key ) ) { | ||
acc[ key ] = nextValue[ key ]; | ||
} | ||
return acc; | ||
}, | ||
{} | ||
); | ||
|
||
setInternalValue( { | ||
...internalValue, | ||
...settingsUpdates, | ||
} ); | ||
}; | ||
|
||
return [ | ||
internalValue, | ||
setInternalValue, | ||
setInternalURLInputValue, | ||
setInternalTextInputValue, | ||
createSetInternalSettingValueHandler, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2b687d0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 2b687d0.
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/5079817879
📝 Reported issues:
No Behaviors
should be the default as defined in the core theme.json #50923 in/test/e2e/specs/editor/various/behaviors.spec.js