Skip to content

Commit

Permalink
fix: avoid deepMapKeys NPM package (#2680)
Browse files Browse the repository at this point in the history
* fix: avoid deepMapKeys NPM package

* fix: better error messaging in Connections wizard
  • Loading branch information
dkoo authored Oct 2, 2023
1 parent f00d206 commit 60b9828
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 8 additions & 4 deletions assets/wizards/connections/views/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ const Main = () => {
<SectionHeader title={ __( 'Plugins', 'newspack' ) } />
<Plugins />
<SectionHeader title={ __( 'APIs', 'newspack' ) } />
{ newspack_connections_data.can_connect_google && <GoogleAuth setError={ setError } /> }
<Mailchimp setError={ setError } />
{ newspack_connections_data.can_connect_google && (
<GoogleAuth setError={ err => setError( __( 'Google: ', 'newspack-plugin' ) + err ) } />
) }
<Mailchimp setError={ err => setError( __( 'Mailchimp: ', 'newspack-plugin' ) + err ) } />
{ newspack_connections_data.can_connect_fivetran && (
<>
<SectionHeader title="Fivetran" />
<FivetranConnection setError={ setError } />
<FivetranConnection
setError={ err => setError( __( 'FiveTran: ', 'newspack-plugin' ) + err ) }
/>
</>
) }
<Recaptcha setError={ setError } />
<Recaptcha setError={ err => setError( __( 'reCAPTCHA: ', 'newspack-plugin' ) + err ) } />
<Webhooks />
</>
);
Expand Down
31 changes: 30 additions & 1 deletion assets/wizards/seo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,41 @@ import { Settings } from './views';
/**
* External dependencies.
*/
import deepMapKeys from 'deep-map-keys';
import camelCase from 'lodash/camelCase';
import snakeCase from 'lodash/snakeCase';

const { HashRouter, Redirect, Route, Switch } = Router;

/**
* Check whether the given object is a pure object with key/value pairs.
*
* @param {*} obj Object to check.
* @return {boolean} True if an object, otherwise false.
*/
const isObj = obj =>
null !== obj && typeof obj === 'object' && Object.getPrototypeOf( obj ).isPrototypeOf( Object );

/**
* Recursively run the given `callback` on all keys of `obj`, and all keys of values of `obj`.
*
* @param {*} obj
* @param {Function} callback
* @return {*} Transformed obj.
*/
const deepMapKeys = ( obj, callback ) => {
if ( ! isObj( obj ) ) {
return obj;
}
const result = {};
for ( const key in obj ) {
if ( obj.hasOwnProperty( key ) ) {
result[ callback( key ) ] = deepMapKeys( obj[ key ], callback );
}
}

return result;
};

class SEOWizard extends Component {
state = {
underConstruction: false,
Expand Down

0 comments on commit 60b9828

Please sign in to comment.