• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 15936d2b846c322fa3b4b91e32ba3f7c002a45a6

13 May 2025 08:35AM UTC coverage: 58.702% (+0.06%) from 58.644%
15936d2b846c322fa3b4b91e32ba3f7c002a45a6

Pull #22258

github

web-flow
Merge pull request #22254 from Yoast/fix/ai-optimize-woo-upsell

Adds an upsell for AI Optimize on products
Pull Request #22258: Merges the feature branch `feature/ai-optimize-classic` to `trunk`

8175 of 14231 branches covered (57.45%)

Branch coverage included in aggregate %.

37 of 68 new or added lines in 11 files covered. (54.41%)

3 existing lines in 2 files now uncovered.

14070 of 23664 relevant lines covered (59.46%)

100886.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/js/src/introductions/components/provider.js
1
import { useSelect } from "@wordpress/data";
2
import { createContext, useCallback, useContext, useEffect, useState } from "@wordpress/element";
3
import { doAction } from "@wordpress/hooks";
4
import { find } from "lodash";
5
import PropTypes from "prop-types";
6
import { STORE_NAME_INTRODUCTIONS } from "../constants";
7

8
// Prepare global.
9
window.YoastSEO = window.YoastSEO || {};
×
10

11
const IntroductionsContext = createContext( {} );
×
12

13
/**
14
 * @returns {Object} The context.
15
 */
16
export const useIntroductionsContext = () => useContext( IntroductionsContext );
×
17

18
/**
19
 * @param {JSX.node} children The children.
20
 * @param {Object} initialComponents The initial components.
21
 * @returns {JSX.Element} The element.
22
 */
23
export const IntroductionProvider = ( { children, initialComponents } ) => {
×
24
        const [ components, setComponents ] = useState( initialComponents );
×
25
        const introductions = useSelect( select => select( STORE_NAME_INTRODUCTIONS ).selectIntroductions(), [] );
×
26

27
        const registerComponent = useCallback( ( id, Component ) => {
×
28
                const introduction = find( introductions, { id } );
×
29
                if ( ! introduction ) {
×
30
                        // Bail when unknown.
31
                        console.error( "Warning: Introductions received a registration for an unknown key:", id );
×
32
                        return;
×
33
                }
34
                setComponents( currentComponents => ( { ...currentComponents, [ id ]: Component } ) );
×
35
        }, [ introductions, setComponents ] );
36

37
        useEffect( () => {
×
38
                // Update the global window registration method.
39
                window.YoastSEO._registerIntroductionComponent = registerComponent;
×
40

41
                // Signal that the introductions API is ready.
NEW
42
                doAction( "yoast.introductions.ready" );
×
43
        }, [ registerComponent ] );
44

45

46
        return (
×
47
                <IntroductionsContext.Provider value={ components }>
48
                        { children }
49
                </IntroductionsContext.Provider>
50
        );
51
};
52
IntroductionProvider.propTypes = {
×
53
        children: PropTypes.node.isRequired,
54
        initialComponents: PropTypes.object.isRequired,
55
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc