Skip to content

Commit

Permalink
fix(plugins): Fix dashboard filter in Period Over Period KPI plugin (a…
Browse files Browse the repository at this point in the history
…pache#27013)

(cherry picked from commit 607301a)
  • Loading branch information
Antonio-RiveroMartnez authored and sadpandajoe committed Feb 5, 2024
1 parent 6b72594 commit 1350b3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ function calculatePrev(
}

export default function buildQuery(formData: QueryFormData) {
const { cols: groupby, time_comparison: timeComparison } = formData;
const {
cols: groupby,
time_comparison: timeComparison,
extra_form_data: extraFormData,
} = formData;

const queryContextA = buildQueryContext(formData, baseQueryObject => [
{
Expand All @@ -244,9 +248,11 @@ export default function buildQuery(formData: QueryFormData) {
'comparator' in timeFilter &&
typeof timeFilter.comparator === 'string'
) {
[testSince, testUntil] = getSinceUntil(
timeFilter.comparator.toLocaleLowerCase(),
);
let timeRange = timeFilter.comparator.toLocaleLowerCase();
if (extraFormData?.time_range) {
timeRange = extraFormData.time_range;
}
[testSince, testUntil] = getSinceUntil(timeRange);
}

let formDataB: QueryFormData;
Expand Down Expand Up @@ -277,11 +283,13 @@ export default function buildQuery(formData: QueryFormData) {
formDataB = {
...formData,
adhoc_filters: queryBFilters,
extra_form_data: {},
};
} else {
formDataB = {
...formData,
adhoc_filters: formData.adhoc_custom,
extra_form_data: {},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ export default function transformProps(chartProps: ChartProps) {

let valueDifference: number | string = bigNumber - prevNumber;

const percentDifferenceNum = prevNumber
? (bigNumber - prevNumber) / Math.abs(prevNumber)
: 0;
let percentDifferenceNum;

if (!bigNumber && !prevNumber) {
percentDifferenceNum = 0;
} else if (!bigNumber || !prevNumber) {
percentDifferenceNum = bigNumber ? 1 : -1;
} else {
percentDifferenceNum = (bigNumber - prevNumber) / Math.abs(prevNumber);
}

const compType = compTitles[formData.timeComparison];
bigNumber = numberFormatter(bigNumber);
Expand Down

0 comments on commit 1350b3b

Please sign in to comment.