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

Yoast / wordpress-seo / 6774f0888d7341dfa21895afa15ad8b4521fb0b3

20 Nov 2024 09:57AM CUT coverage: 54.684% (-0.004%) from 54.688%
6774f0888d7341dfa21895afa15ad8b4521fb0b3

push

github

pls78
Merge branch 'release/24.0' of https://github.com/Yoast/wordpress-seo into trunk

7593 of 13597 branches covered (55.84%)

Branch coverage included in aggregate %.

13 of 24 new or added lines in 1 file covered. (54.17%)

1 existing line in 1 file now uncovered.

29746 of 54685 relevant lines covered (54.4%)

41969.0 hits per line

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

65.91
/packages/js/src/components/SEMrushRelatedKeyphrasesModalContent.js
1
/* External dependencies */
2
import { Fragment } from "@wordpress/element";
3
import { KeyphrasesTable } from "@yoast/related-keyphrase-suggestions";
4
import { Root } from "@yoast/ui-library";
5
import { __, sprintf } from "@wordpress/i18n";
6
import PropTypes from "prop-types";
7
import { isEmpty } from "lodash";
8

9
/* Internal dependencies */
10
import SEMrushLoading from "./modals/SEMrushLoading";
11
import SEMrushLimitReached from "./modals/SEMrushLimitReached";
12
import SEMrushCountrySelector from "./modals/SEMrushCountrySelector";
13
import SEMrushUpsellAlert from "./modals/SEMrushUpsellAlert";
14
import SEMrushRequestFailed from "./modals/SEMrushRequestFailed";
15
import SEMrushMaxRelatedKeyphrases from "./modals/SEMrushMaxRelatedKeyphrases";
16
import getL10nObject from "../analysis/getL10nObject";
17
import { makeOutboundLink } from "@yoast/helpers";
18

19
/**
20
 * Determines whether the error property is present in the passed response object.
21
 *
22
 * @param {Object} response The response object.
23
 *
24
 * @returns {boolean} Whether or not the error property is present.
25
 */
26
export function hasError( response ) {
27
        return ! isEmpty( response ) && "error" in response;
6✔
28
}
29

30
/**
31
 * Gets a user message based on the passed props' values.
32
 *
33
 * @param {Object} props The props to use.
34
 *
35
 * @returns {wp.Element} The user message.
36
 */
37
export function getUserMessage( props ) {
38
        const {
39
                isPending,
40
                requestLimitReached,
41
                isSuccess,
42
                response,
43
                requestHasData,
44
        } = props;
8✔
45

46
        if ( isPending ) {
8✔
47
                return <SEMrushLoading />;
2✔
48
        }
49

50
        if ( requestLimitReached ) {
6✔
51
                return <SEMrushLimitReached />;
2✔
52
        }
53

54
        if ( ! isSuccess && hasError( response ) ) {
4✔
55
                return <SEMrushRequestFailed />;
2✔
56
        }
57

58
        if ( ! requestHasData ) {
2!
59
                return <p>{ __( "Sorry, there's no data available for that keyphrase/country combination.", "wordpress-seo" ) }</p>;
2✔
60
        }
61
}
62

63
/**
64
 * Determines whether the maximum amount of related keyphrases has been reached.
65
 *
66
 * @param {array} relatedKeyphrases The related keyphrases. Can be empty.
67
 *
68
 * @returns {boolean} Whether or not the maximum limit has been reached.
69
 */
70
export function hasMaximumRelatedKeyphrases( relatedKeyphrases ) {
71
        return relatedKeyphrases && relatedKeyphrases.length >= 4;
6✔
72
}
73

74
/**
75
 * Renders the SEMrush related keyphrases modal content.
76
 *
77
 * @param {Object} props The props to use within the content.
78
 *
79
 * @returns {wp.Element} The SEMrush related keyphrases modal content.
80
 */
81
export default function RelatedKeyphraseModalContent( props ) {
82
        const {
83
                response,
84
                lastRequestKeyphrase,
85
                keyphrase,
86
                newRequest,
87
                setCountry,
88
                renderAction,
89
                countryCode,
90
                requestLimitReached,
91
                setRequestFailed,
92
                setNoResultsFound,
93
                relatedKeyphrases,
94
                setRequestSucceeded,
95
                setRequestLimitReached,
96
                isPending,
97
                isRtl,
98
                userLocale,
UNCOV
99
        } = props;
×
100

101
        const isPremium = getL10nObject().isPremium;
×
102
        const GetMoreInsightsLink = makeOutboundLink();
×
103
        const url = "https://www.semrush.com/analytics/keywordoverview/?q=" + encodeURIComponent( keyphrase ) +
×
104
                        "&db=" + encodeURIComponent( countryCode );
105

106
        return (
×
107
                <Root context={ { isRtl } }>
108
                        { ! requestLimitReached && (
×
109
                                <Fragment>
110
                                        { ! isPremium && <SEMrushUpsellAlert /> }
×
111
                                        { isPremium && hasMaximumRelatedKeyphrases( relatedKeyphrases ) && <SEMrushMaxRelatedKeyphrases /> }
×
112
                                        <SEMrushCountrySelector
113
                                                countryCode={ countryCode }
114
                                                setCountry={ setCountry }
115
                                                newRequest={ newRequest }
116
                                                keyphrase={ keyphrase }
117
                                                setRequestFailed={ setRequestFailed }
118
                                                setNoResultsFound={ setNoResultsFound }
119
                                                setRequestSucceeded={ setRequestSucceeded }
120
                                                setRequestLimitReached={ setRequestLimitReached }
121
                                                response={ response }
122
                                                lastRequestKeyphrase={ lastRequestKeyphrase }
123
                                                userLocale={ userLocale.split( "_" )[ 0 ] }
124
                                        />
125
                                </Fragment>
126
                        ) }
127

128
                        { getUserMessage( props ) }
129

130
                        <KeyphrasesTable
131
                                relatedKeyphrases={ relatedKeyphrases }
132
                                columnNames={ response?.results?.columnNames }
133
                                data={ response?.results?.rows }
134
                                isPending={ isPending }
135
                                renderButton={ renderAction }
136
                        />
137
                        { response?.results?.rows && <p className="yst-mb-0 yst-mt-2">
×
138
                                <GetMoreInsightsLink href={ url }>
139
                                        { sprintf(
140
                                        /* translators: %s expands to Semrush */
141
                                                __( "Get more insights at %s", "wordpress-seo" ),
142
                                                "Semrush"
143
                                        ) }
144
                                </GetMoreInsightsLink>
145
                        </p> }
146
                </Root>
147
        );
148
}
149

150
RelatedKeyphraseModalContent.propTypes = {
2✔
151
        keyphrase: PropTypes.string,
152
        relatedKeyphrases: PropTypes.array,
153
        renderAction: PropTypes.func,
154
        requestLimitReached: PropTypes.bool,
155
        countryCode: PropTypes.string.isRequired,
156
        setCountry: PropTypes.func.isRequired,
157
        newRequest: PropTypes.func.isRequired,
158
        setRequestSucceeded: PropTypes.func.isRequired,
159
        setRequestLimitReached: PropTypes.func.isRequired,
160
        setRequestFailed: PropTypes.func.isRequired,
161
        setNoResultsFound: PropTypes.func.isRequired,
162
        response: PropTypes.object,
163
        lastRequestKeyphrase: PropTypes.string,
164
        isRtl: PropTypes.bool,
165
        userLocale: PropTypes.string,
166
        isPending: PropTypes.bool,
167
};
168

169
RelatedKeyphraseModalContent.defaultProps = {
2✔
170
        keyphrase: "",
171
        relatedKeyphrases: [],
172
        renderAction: null,
173
        requestLimitReached: false,
174
        response: {},
175
        lastRequestKeyphrase: "",
176
        isRtl: false,
177
        userLocale: null,
178
        isPending: false,
179
};
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