Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a94fe3e
adding console logs to be able to understand the flow of the code better
chippison Nov 17, 2025
d541f6e
adding a timeout so that we can wait a little for the async process o…
chippison Nov 17, 2025
0e4f564
Removing the '+1' from segmentCompareLimit and just making the value …
chippison Nov 17, 2025
c814da9
adding the check for maximum compared segments
chippison Nov 17, 2025
429da96
adding a 'no-click' class when max compared segments is reached which…
chippison Nov 17, 2025
49d1798
adding the tooltip
chippison Nov 18, 2025
8c54eaf
making the translatable error message available in the client side
chippison Nov 18, 2025
aa08ea9
We make sure that it is only the <span> with class segname gets the c…
chippison Nov 19, 2025
8571997
adding listener for segment comparison change so we can mark them pro…
chippison Nov 19, 2025
4bf4e37
using value from global.ini 'data_comparison_segment_limit' as the limit
chippison Nov 19, 2025
69b2eeb
Build vue files
innocraft-automation Nov 19, 2025
14a6d6b
cleanup code
chippison Nov 20, 2025
5b72f27
adding fake test so that I can grab screenshot of what is actually ha…
chippison Nov 20, 2025
0a78aa2
Merge branch '5.x-dev' into ux-340
chippison Nov 21, 2025
5ec75f1
adding a segment so that we can test reaching the maximum limit
chippison Nov 21, 2025
15e9a15
adding test so that we can count how many where set to class='compare…
chippison Nov 21, 2025
0428839
finished test using only DOM checks
chippison Nov 21, 2025
ba68438
update screenshot to reflect change in segment limit comparison
chippison Nov 22, 2025
67e8e59
revert file
chippison Nov 22, 2025
1eea7c1
Merge branch '5.x-dev' into ux-340
chippison Nov 23, 2025
f3c6dd6
removed this bunch of code as we already call the function after the …
chippison Nov 24, 2025
1939100
Merge branch '5.x-dev' into ux-340
chippison Nov 24, 2025
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
2 changes: 1 addition & 1 deletion config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@
num_days_before_tracking_code_reminder = 5

; The maximum number of segments that can be compared simultaneously.
data_comparison_segment_limit = 5
data_comparison_segment_limit = 6

; The maximum number of periods that can be compared simultaneously.
data_comparison_period_limit = 5
Expand Down
1 change: 1 addition & 0 deletions core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public function getClientSideOptions()
'action_title_category_delimiter' => $general['action_title_category_delimiter'],
'are_ads_enabled' => Advertising::isAdsEnabledInConfig($general),
'autocomplete_min_sites' => $general['autocomplete_min_sites'],
'data_comparison_segment_limit' => $general['data_comparison_segment_limit'],
'datatable_export_range_as_day' => $general['datatable_export_range_as_day'],
'datatable_row_limits' => $this->getDatatableRowLimits(),
'enable_general_settings_admin' => Controller::isGeneralSettingsAdminEnabled(),
Expand Down
2 changes: 1 addition & 1 deletion plugins/API/Filter/DataComparisonFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function __construct($request, ?Report $report = null)
$this->segmentName = $this->getSegmentNameFromReport($report);

$this->compareSegments = self::getCompareSegments();
if (count($this->compareSegments) > $this->segmentCompareLimit + 1) {
if (count($this->compareSegments) > $this->segmentCompareLimit) {
throw new BadRequestException(Piwik::translate('General_MaximumNumberOfSegmentsComparedIs', [$this->segmentCompareLimit]));
}

Expand Down
1 change: 1 addition & 0 deletions plugins/SegmentEditor/SegmentEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = 'SegmentEditor_ThisSegmentIsSelectedAndCannotBeCompared';
$translationKeys[] = 'SegmentEditor_CompareThisSegment';
$translationKeys[] = 'Live_VisitsLog';
$translationKeys[] = 'General_MaximumNumberOfSegmentsComparedIs';
}

public static function getAllSegmentsForSite($idSite)
Expand Down
35 changes: 27 additions & 8 deletions plugins/SegmentEditor/javascripts/Segmentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,41 @@ Segmentation = (function($) {
content: title,
});
};
// We will listen to changes in the Segment Comparison Store
// so we can mark compared segments properly. This will now include deletion of compared segments.
piwik.on('piwikComparisonsChanged', function () {
self.markComparedSegments();
});

segmentation.prototype.markComparedSegments = function() {
var comparisonService = window.CoreHome.ComparisonsStoreInstance;
var comparedSegments = comparisonService.getSegmentComparisons().map(function (comparison) {
return comparison.params.segment;
});

$('div.segmentList ul li[data-definition]', this.target).removeClass('comparedSegment').filter(function () {
var definition = $(this).attr('data-definition');
return comparedSegments.indexOf(definition) !== -1 || comparedSegments.indexOf(decodeURIComponent(definition)) !== -1;
}).each(function () {
$(this).addClass('comparedSegment');
});
self.checkIfComparedSegmentsHasReachedLimit();
};
segmentation.prototype.checkIfComparedSegmentsHasReachedLimit = function() {
const limit = piwik.config.data_comparison_segment_limit;
const comparisonService = window.CoreHome.ComparisonsStoreInstance;
const comparedSegmentsLength = comparisonService.getSegmentComparisons().length;
$('div.segmentList ul li[data-definition] span.compareSegment').each(function() {
if (comparedSegmentsLength >= limit) {
$(this).addClass('no-click');
$(this).parent().attr('title', _pk_translate('General_MaximumNumberOfSegmentsComparedIs', [limit]));
} else {
$(this).removeClass('no-click');
var idSegment = $(this).parent().attr('data-idsegment');
const title = getSegmentName(getSegmentFromId(idSegment));
$(this).parent().attr('title', title);
}
});
return false;
};

segmentation.prototype.markCurrentSegment = function(){
Expand Down Expand Up @@ -408,20 +430,17 @@ Segmentation = (function($) {
self.target.on('click', '.compareSegment', function (e) {
e.stopPropagation();
e.preventDefault();

var comparisonService = window.CoreHome.ComparisonsStoreInstance;
comparisonService.addSegmentComparison({
segment: $(e.target).closest('li').data('definition'),
});

self.markComparedSegments();

closeAllOpenLists();
});

self.target.on("click", ".segmentList li", function (e) {
if ($(e.currentTarget).hasClass("grayed") !== true) {
var segmentDefinition = $(this).data("definition");
self.target.on("click", ".segmentList li span.segname", function (e) {
let parentLi = $(this).parent();
if (parentLi.hasClass("grayed") !== true) {
var segmentDefinition = $(parentLi).data("definition");

if (!piwikHelper.isReportingPage()) {
// we update segment on location change success
Expand Down
3 changes: 3 additions & 0 deletions plugins/SegmentEditor/stylesheets/segmentation.less
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ div.scrollable {
margin-right: 24px;
}
}
span.compareSegment.no-click {
pointer-events: none;
}

li.segmentSelected, li.comparedSegment {
span.compareSegment {
Expand Down
47 changes: 47 additions & 0 deletions plugins/SegmentEditor/tests/UI/SegmentSelectorEditor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,51 @@ describe("SegmentSelectorEditorTest", function () {
await page.click('.segmentationContainer .title');
expect(await page.screenshotSelector(selectorsToCapture)).to.matchImage('enabled_create_realtime_segments_saved');
});

it('should not allow comparing segments more than the limit set', async function() {
const maxSegments = 3;
testEnvironment.overrideConfig('General', 'data_comparison_segment_limit', maxSegments);
testEnvironment.save();
await page.goto(url);
await page.waitForNetworkIdle();
// We grab the max limit message
const maxLimitMessage = await page.evaluate(
(limit) => _pk_translate('General_MaximumNumberOfSegmentsComparedIs', [limit]),
maxSegments);

// We check that the title attribute is still not the max limit message
let title = await page.$eval('.segmentationContainer .segmentList li:last-child', (el) => el.getAttribute('title'));
expect(title).to.not.equal(maxLimitMessage);

await page.waitForSelector('.segmentationContainer');
// We check that the number of <li> elements is greater than the limit we set
const liElemLength = await page.$$eval('.segmentListContainer .segmentList li', (e) => e.length);
expect(liElemLength).to.be.greaterThan(maxSegments);

// We check that the number of segments compared is 1 at the start
let comparedCount = await page.$$eval(
'.segmentListContainer .segmentList li.comparedSegment',
(nodes) => nodes.length,
);
expect(comparedCount).to.equal(1);

// We want to click all the segments so that we can check that it stops at the limit
for (let i=0; i<liElemLength; i++) {
await page.click('.segmentationContainer .title');
const segments = await page.$$('.segmentListContainer .segmentList li span.compareSegment');
await segments[i].click();
await page.waitForTimeout(50);
}

// We check that the number of segments compared is now equal to the limit we set
comparedCount = await page.$$eval(
'.segmentListContainer .segmentList li.comparedSegment',
(nodes) => nodes.length,
);
expect(comparedCount).to.equal(maxSegments);

// Last we check that the title attribute has changed to reflect the limit has been reached
title = await page.$eval('.segmentationContainer .segmentList li:last-child', (el) => el.getAttribute('title'));
expect(title).to.equal(maxLimitMessage);
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated General.data_comparison_limit

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading