LYS - Disable the save changes button until changes are made (#47316)

* Disable the save changes button until changes are made

* Add changefile(s) from automation for the following project(s): woocommerce

* Fix broken test

* Test

* Remove test code

* Tmp fix - fix broken test

* Fix incorrect comparison

* Remove test code

* minor refactor -- re-use setting

* Remove use of loadash isequal

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Moon 2024-05-14 02:56:51 +12:00 committed by GitHub
parent 4ba770cbba
commit 5183b1bb1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 9 deletions

View File

@ -11,6 +11,7 @@ import {
useState,
createInterpolateElement,
createElement,
useEffect,
} from '@wordpress/element';
import { registerPlugin } from '@wordpress/plugins';
import { __ } from '@wordpress/i18n';
@ -32,23 +33,38 @@ import {
const { Fill } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT );
const SiteVisibility = () => {
const shareKey =
window?.wcSettings?.admin?.siteVisibilitySettings
?.woocommerce_share_key;
const setting = window?.wcSettings?.admin?.siteVisibilitySettings || {};
const shareKey = setting?.woocommerce_share_key;
const [ comingSoon, setComingSoon ] = useState(
window?.wcSettings?.admin?.siteVisibilitySettings
?.woocommerce_coming_soon || 'no'
setting?.woocommerce_coming_soon || 'no'
);
const [ storePagesOnly, setStorePagesOnly ] = useState(
window?.wcSettings?.admin?.siteVisibilitySettings
?.woocommerce_store_pages_only
setting?.woocommerce_store_pages_only || 'no'
);
const [ privateLink, setPrivateLink ] = useState(
window?.wcSettings?.admin?.siteVisibilitySettings
?.woocommerce_private_link
setting?.woocommerce_private_link || 'no'
);
useEffect( () => {
const initValues = {
comingSoon: setting.woocommerce_coming_soon,
storePagesOnly: setting.woocommerce_store_pages_only,
privateLink: setting.woocommerce_private_link || 'no',
};
const currentValues = { comingSoon, storePagesOnly, privateLink };
const saveButton = document.getElementsByClassName(
'woocommerce-save-button'
)[ 0 ];
if ( saveButton ) {
saveButton.disabled =
initValues.comingSoon === currentValues.comingSoon &&
initValues.storePagesOnly === currentValues.storePagesOnly &&
initValues.privateLink === currentValues.privateLink;
}
}, [ comingSoon, storePagesOnly, privateLink ] );
const copyLink = __( 'Copy link', 'woocommerce' );
const copied = __( 'Copied!', 'woocommerce' );
const [ copyLinkText, setCopyLinkText ] = useState( copyLink );

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
LYS: disables the "Save changes" button until changes are made.