Skip to content

Commit

Permalink
Merge branch 'feature/wincher-modal-improvements' of https://github.c…
Browse files Browse the repository at this point in the history
…om/wincher-ab/wordpress-seo into wincher-modal-improvements
  • Loading branch information
pls78 committed Oct 10, 2023
2 parents d410ad4 + 6cbd0a9 commit 5197029
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
33 changes: 29 additions & 4 deletions packages/js/src/components/WincherRankingHistoryChart.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
/* External dependencies */
import { Line } from "react-chartjs-2";
import { CategoryScale, Chart, LineController, LineElement, LinearScale, PointElement, TimeScale, Colors, Legend, Tooltip } from "chart.js";
import { CategoryScale, Chart, LineController, LineElement, LinearScale, PointElement, TimeScale, Legend, Tooltip } from "chart.js";
import "chartjs-adapter-moment";
import PropTypes from "prop-types";
import { noop } from "lodash";
import moment from "moment";

Chart.register( CategoryScale, LineController, LineElement, PointElement, LinearScale, TimeScale, Colors, Legend, Tooltip );
Chart.register( CategoryScale, LineController, LineElement, PointElement, LinearScale, TimeScale, Legend, Tooltip );

const CHART_COLORS = [
"#ff983b",
"#ffa3f7",
"#3798ff",
"#ff3b3b",
"#acce81",
"#b51751",
"#3949ab",
"#26c6da",
"#ccb800",
"#de66ff",
"#4db6ac",
"#ffab91",
"#45f5f1",
"#77f210",
"#90a4ae",
"#ffd54f",
"#006b5e",
"#8ec7d2",
"#b1887c",
"#cc9300",
];

/**
* Renders the Wincher ranking history chart.
Expand All @@ -20,7 +43,7 @@ export default function WincherRankingHistoryChart( { datasets, isChartShown } )
return null;
}

const data = datasets.map( dataset => ( {
const data = datasets.map( ( dataset, index ) => ( {
...dataset,
data: dataset.data.map( ( { datetime, value } ) => ( {
x: datetime,
Expand All @@ -31,7 +54,8 @@ export default function WincherRankingHistoryChart( { datasets, isChartShown } )
pointHoverRadius: 4,
borderWidth: 2,
pointHitRadius: 6,
} ) );
backgroundColor: CHART_COLORS[ index % CHART_COLORS.length ],
} ) ).filter( dataset => dataset.selected !== false );

return (
<Line
Expand Down Expand Up @@ -109,6 +133,7 @@ WincherRankingHistoryChart.propTypes = {
value: PropTypes.number.isRequired,
} )
).isRequired,
selected: PropTypes.bool,
} )
).isRequired,
isChartShown: PropTypes.bool.isRequired,
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/components/WincherSEOPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ const TableContent = ( props ) => {
if ( isEmpty( trackedKeyphrases ) ) {
return [];
}
return Object.values( trackedKeyphrases ).filter( keyphrase => selectedKeyphrases.includes( keyphrase.keyword ) )
.filter( keyphrase => ! isEmpty( keyphrase.position?.history ) )
return Object.values( trackedKeyphrases )
.map( keyphrase => ( {
label: keyphrase.keyword,
data: keyphrase.position.history,
selected: selectedKeyphrases.includes( keyphrase.keyword ) && ! isEmpty( keyphrase.position?.history ),
} ) );
}, [ selectedKeyphrases, trackedKeyphrases ] );

Expand Down
3 changes: 1 addition & 2 deletions packages/js/src/redux/selectors/WincherSEOPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export function hasWincherTrackedKeyphrases( state ) {
export function getWincherTrackableKeyphrases( state ) {
const isPremium = getL10nObject().isPremium;
const premiumStore = window.wp.data.select( "yoast-seo-premium/editor" );
const tracked = Object.keys( getWincherTrackedKeyphrases( state ) || {} ).map( k => k.trim() );
const keyphrases = [ state.focusKeyword.trim(), ...tracked ];
const keyphrases = [ state.focusKeyword.trim() ];

if ( isPremium && premiumStore ) {
// eslint-disable-next-line no-undefined
Expand Down

0 comments on commit 5197029

Please sign in to comment.