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

Jetpack: Fix some minor eslint lints #39753

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function withModuleSettingsFormHelpers( InnerComponent ) {
const saneOptions = {};

each( this.state.options, ( value, key ) => {
key = key.replace( /\-/, '_' );
key = key.replace( /-/, '_' );
saneOptions[ key ] = value;
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function choosePrimary( prefered, room ) {

// less chopped of than other sides
if ( space > best ) {
( best = space ), ( bestPos = prefered );
best = space;
bestPos = prefered;
}
}

Expand Down Expand Up @@ -161,7 +162,8 @@ function chooseSecondary( primary, prefered, el, target, w, h ) {

// shows more of the tip than the other positions
if ( area > best ) {
( best = area ), ( bestPos = pos );
best = area;
bestPos = pos;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class NavTabs extends React.Component {
case 32: // space
case 13: // enter
event.preventDefault();
document.activeElement.click();
event.target.ownerDocument.activeElement.click();
break;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class SelectDropdown extends Component {
if ( ! this.state.isOpen ) {
return this.openDropdown();
}
document.activeElement.click();
this.dropdownContainerRef.current.ownerDocument.activeElement.click();
}

focusSibling( direction ) {
Expand Down
3 changes: 2 additions & 1 deletion projects/plugins/jetpack/_inc/client/pro-status/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ class ProStatus extends React.Component {
break;
case 'invalid_key':
return;
case 'rewind_connected':
case 'rewind_connected': {
const rewindMessage = this.getRewindMessage();
return <Status status={ rewindMessage.status } text={ rewindMessage.text } />;
}
case 'active':
return <Status status="active" />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export const user = ( state = window.Initial_State.userData || {}, action ) => {
case USER_CONNECTION_DATA_FETCH_SUCCESS:
return assign( {}, state, action.userConnectionData );

case UNLINK_USER_SUCCESS:
case UNLINK_USER_SUCCESS: {
const currentUser = assign( {}, state.currentUser, { isConnected: false } );
return assign( {}, state, { currentUser } );
}

case MOCK_SWITCH_USER_PERMISSIONS:
return merge( {}, state, action.initialState );
Expand Down
9 changes: 6 additions & 3 deletions projects/plugins/jetpack/_inc/client/state/modules/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ export const items = ( state = {}, action ) => {
return assign( {}, state, {
[ action.module ]: assign( {}, state[ action.module ], { activated: false } ),
} );
case JETPACK_MODULE_UPDATE_OPTIONS_SUCCESS:
case JETPACK_MODULE_UPDATE_OPTIONS_SUCCESS: {
const updatedModule = assign( {}, state[ action.module ] );
Object.keys( action.newOptionValues ).forEach( key => {
updatedModule.options[ key ].current_value = action.newOptionValues[ key ];
} );
return assign( {}, state, {
[ action.module ]: updatedModule,
} );
}
default:
return state;
}
Expand Down Expand Up @@ -84,7 +85,7 @@ export const requests = ( state = initialRequestsState, action ) => {
[ action.module ]: false,
} ),
} );
case JETPACK_MODULE_UPDATE_OPTIONS:
case JETPACK_MODULE_UPDATE_OPTIONS: {
const updatingOption = assign( {}, state.updatingOption );
updatingOption[ action.module ] = assign( {}, updatingOption[ action.module ] );
Object.keys( action.newOptionValues ).forEach( key => {
Expand All @@ -93,8 +94,9 @@ export const requests = ( state = initialRequestsState, action ) => {
return assign( {}, state, {
updatingOption: assign( {}, state.updatingOption, updatingOption ),
} );
}
case JETPACK_MODULE_UPDATE_OPTIONS_FAIL:
case JETPACK_MODULE_UPDATE_OPTIONS_SUCCESS:
case JETPACK_MODULE_UPDATE_OPTIONS_SUCCESS: {
const _updatingOption = assign( {}, state.updatingOption );
_updatingOption[ action.module ] = assign( {}, _updatingOption[ action.module ] );
Object.keys( action.newOptionValues ).forEach( key => {
Expand All @@ -103,6 +105,7 @@ export const requests = ( state = initialRequestsState, action ) => {
return assign( {}, state, {
updatingOption: assign( {}, state.updatingOption, _updatingOption ),
} );
}
default:
return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export const items = ( state = {}, action ) => {
return assign( {}, state, action.initialState.settings );
case JETPACK_SETTINGS_FETCH_RECEIVE:
return assign( {}, action.settings );
case JETPACK_SETTING_UPDATE_SUCCESS:
case JETPACK_SETTING_UPDATE_SUCCESS: {
const key = Object.keys( action.updatedOption )[ 0 ];
return assign( {}, state, {
[ key ]: action.updatedOption[ key ],
} );
}
case JETPACK_SETTINGS_UPDATE_SUCCESS:
return assign( {}, state, action.updatedOptions );
default:
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/_inc/client/writing/composing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Composing extends React.Component {
* @return {*} the updated value
*/
updateFormStateByMarkdown = module => {
if ( !! this.props.getSettingCurrentValue( 'wpcom_publish_comments_with_markdown', module ) ) {
if ( this.props.getSettingCurrentValue( 'wpcom_publish_comments_with_markdown', module ) ) {
return this.props.updateFormStateModuleOption( module, 'wpcom_publish_posts_with_markdown' );
}
return this.props.updateFormStateModuleOption(
Expand Down
9 changes: 5 additions & 4 deletions projects/plugins/jetpack/_inc/jetpack-deactivate-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@
$( '#TB_window' ).addClass( 'jetpack-disconnect-modal' );
deactivationModalCentralize();

$( '#TB_closeWindowButton, #TB_overlay' ).on( 'click', function ( e ) {
$( '#TB_closeWindowButton, #TB_overlay' ).on( 'click', function () {
deactivationModalTrackCloseEvent();
} );

document.onkeyup = function ( e ) {
var keycode;
if ( e === null ) {
// ie
keycode = event.keyCode;
} else {
// mozilla
keycode = e.which;
}
if ( keycode == 27 ) {
if ( keycode === 27 ) {
// close
deactivationModalTrackCloseEvent();
}
Expand Down Expand Up @@ -77,12 +78,12 @@
deactivateLinkElem.attr( 'title', deactivate_dialog.title );
deactivateLinkElem.addClass( 'thickbox' );
deactivateLinkElem.html( deactivate_dialog.deactivate_label );
deactivateLinkElem.on( 'click', function ( e ) {
deactivateLinkElem.on( 'click', function () {
observer.observe( body, { childList: true } );
analytics.tracks.recordEvent( 'jetpack_termination_dialog_open', tracksProps );
} );

$( '#jetpack_deactivation_dialog_content__button-cancel' ).on( 'click', function ( e ) {
$( '#jetpack_deactivation_dialog_content__button-cancel' ).on( 'click', function () {
tb_remove();
deactivationModalTrackCloseEvent();
} );
Expand Down
13 changes: 2 additions & 11 deletions projects/plugins/jetpack/_inc/jetpack-modules.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
( function ( window, $, items, models, views, i18n, modalinfo, nonces ) {
'use strict';

var modules,
list_table,
handle_module_tag_click,
$the_table,
$the_filters,
$the_search,
$jp_frame,
$bulk_button;

$the_table = $( '.wp-list-table.jetpack-modules' );
var modules, list_table, handle_module_tag_click, $the_filters, $the_search, $bulk_button;

$the_filters = $( '.navbar-form' );
$the_search = $( '#srch-term-search-input' );
$jp_frame = $( '.jp-frame' );
$bulk_button = $( '#doaction' );

modules = new models.Modules( {
Expand Down
5 changes: 5 additions & 0 deletions projects/plugins/jetpack/changelog/fix-various-eslint-lints
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Fix various eslint lints. Should be no change to functionality, although it's possible some obscure React bugs got fixed.


Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function eventIdFromUrl( url ) {
return null;
}

const match = url.match( /(\d+)\/?(?:\?[^\/]*)?\s*$/ );
const match = url.match( /(\d+)\/?(?:\?[^/]*)?\s*$/ );
return match && match[ 1 ] ? parseInt( match[ 1 ], 10 ) : null;
}

Expand Down
42 changes: 19 additions & 23 deletions projects/plugins/jetpack/extensions/blocks/image-compare/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,30 @@ import './view.js';

const Edit = ( { attributes, clientId, isSelected, setAttributes } ) => {
const { align, imageBefore, imageAfter, caption, orientation } = attributes;
// Check for useResizeObserver, not available in older Gutenberg.
let resizeListener = null;
let sizes = null;

const blockProps = useBlockProps();
const juxtaposeRef = useRef( undefined );
if ( useResizeObserver ) {
// Let's look for resize so we can trigger the thing.
[ resizeListener, sizes ] = useResizeObserver();

useDebounce(
sz => {
if ( sz > 0 ) {
if ( typeof juxtapose !== 'undefined' && juxtapose.sliders ) {
// only update for *this* slide
juxtapose.sliders.forEach( elem => {
const parentElem = elem.wrapper.parentElement;
if ( parentElem.id === clientId ) {
elem.optimizeWrapper( sz );
}
} );
}
// Let's look for resize so we can trigger the thing.
const [ resizeListener, sizes ] = useResizeObserver();

useDebounce(
sz => {
if ( sz > 0 ) {
if ( typeof juxtapose !== 'undefined' && juxtapose.sliders ) {
// only update for *this* slide
juxtapose.sliders.forEach( elem => {
const parentElem = elem.wrapper.parentElement;
if ( parentElem.id === clientId ) {
elem.optimizeWrapper( sz );
}
} );
}
},
200,
sizes.width
);
}
}
},
200,
sizes.width
);

// Initial state if attributes already set or not.
// If both images are set, add juxtapose class, which is picked up by the library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function OpenTableEdit( {
// Need to force attribute to be updated after switch to using block styles
// so it still meets frontend rendering expectations.
setAttributes( { style } );
}, [ style ] );
}, [ align, style, prevStyle, setAttributes ] );

const parseEmbedCode = embedCode => {
const newAttributes = getAttributesFromEmbedCode( embedCode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function RestaurantPicker( props ) {
const { restaurants, hasRequestFailed } = useRestaurantSearch( input, MAX_SUGGESTIONS );
const [ selectedRestaurants, setSelectedRestaurants ] = useState( props.rids || [] );

const idRegex = /^(\d+)$|\(\#(\d+)\)$/;
const idRegex = /^(\d+)$|\(#(\d+)\)$/;

const onChange = selected => {
const selectedIds = selected.map( restaurant => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
import { useState, useEffect, useCallback } from '@wordpress/element';
import { useState, useEffect, useCallback, useMemo } from '@wordpress/element';
import { unionBy, throttle, isEmpty } from 'lodash';

export const possibleEmbed = /^\s*(http[s]?:\/\/|\<script)/;
export const possibleEmbed = /^\s*(http[s]?:\/\/|<script)/;

export default function useRestaurantSearch( searchTerm, maxResults ) {
const [ restaurants, setRestaurants ] = useState( [] );
const [ hasRequestFailed, setHasRequestFailed ] = useState( false );

const searchRestaurants = ( input = '' ) => {
setHasRequestFailed( false );
const searchRestaurants = useCallback(
( input = '' ) => {
setHasRequestFailed( false );

fetch(
'https://www.opentable.com/widget/reservation/restaurant-search?pageSize=' +
maxResults +
'&query=' +
encodeURIComponent( input )
)
.then( result => result.json() )
.then( restaurantResponse => {
setHasRequestFailed( false );
setRestaurants( unionBy( restaurants, restaurantResponse.items, 'rid' ) );
} )
.catch( () => setHasRequestFailed( true ) );
};
fetch(
'https://www.opentable.com/widget/reservation/restaurant-search?pageSize=' +
maxResults +
'&query=' +
encodeURIComponent( input )
)
.then( result => result.json() )
.then( restaurantResponse => {
setHasRequestFailed( false );
setRestaurants( unionBy( restaurants, restaurantResponse.items, 'rid' ) );
} )
.catch( () => setHasRequestFailed( true ) );
},
[ restaurants, maxResults ]
);

const throttledSearchRestaurants = useCallback( throttle( searchRestaurants, 500 ), [
restaurants,
] );
const throttledSearchRestaurants = useMemo(
() => throttle( searchRestaurants, 500 ),
[ searchRestaurants ]
);

useEffect( () => {
if ( ! isEmpty( searchTerm ) && ! possibleEmbed.test( searchTerm ) ) {
throttledSearchRestaurants( searchTerm );
}
}, [ searchTerm ] );
}, [ searchTerm, throttledSearchRestaurants ] );

return { restaurants, hasRequestFailed };
}
21 changes: 9 additions & 12 deletions projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import SubscriptionSkeletonLoader from './subscription-skeleton-loader';

const { getComputedStyle } = window;
const isGradientAvailable = !! useGradient;
const useGradientIfAvailable = isGradientAvailable ? useGradient : () => ( {} );
const name = metadata.name.replace( 'jetpack/', '' );

const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
Expand Down Expand Up @@ -125,18 +126,14 @@ export function SubscriptionEdit( props ) {
};
} );

const emailFieldGradient = isGradientAvailable
? useGradient( {
gradientAttribute: 'emailFieldGradient',
customGradientAttribute: 'customEmailFieldGradient',
} )
: {};
const buttonGradient = isGradientAvailable
? useGradient( {
gradientAttribute: 'buttonGradient',
customGradientAttribute: 'customButtonGradient',
} )
: {};
const emailFieldGradient = useGradientIfAvailable( {
gradientAttribute: 'emailFieldGradient',
customGradientAttribute: 'customEmailFieldGradient',
} );
const buttonGradient = useGradientIfAvailable( {
gradientAttribute: 'buttonGradient',
customGradientAttribute: 'customButtonGradient',
} );

const sharedClasses = {
'no-border-radius': borderRadius === 0,
Expand Down
Loading
Loading