Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): Make comparison values on BigNumberPeriodOverPeriod toggleable #28605

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const form_data = {
header_font_size: 60,
subheader_font_size: 26,
comparison_color_enabled: true,
previous_period_value_enabled: true,
value_difference_enabled: true,
percent_difference_enabled: true,
extra_form_data: {},
force: false,
result_format: 'json',
Expand Down Expand Up @@ -142,7 +145,7 @@ describe('getComparisonInfo', () => {
expect(resultFormData.adhoc_filters?.[0]).toEqual(expectedFilters[0]);
});

it('If adhoc_filter is undefrined the code wont break', () => {
it('If adhoc_filter is undefined the code wont break', () => {
const resultFormData = getComparisonInfo(
{
...form_data,
Expand Down Expand Up @@ -175,4 +178,21 @@ describe('getComparisonInfo', () => {
expect(resultFormData.adhoc_filters?.length).toEqual(1);
expect(resultFormData.adhoc_filters).toEqual(expectedFilters);
});

it('Updates comparison display values when toggled', () => {
const resultFormData = getComparisonInfo(
{
...form_data,
previous_period_value_enabled: false,
value_difference_enabled: false,
percent_difference_enabled: false,
},
ComparisonTimeRangeType.Year,
{},
);

expect(resultFormData.previous_period_value_enabled).toEqual(false);
expect(resultFormData.value_difference_enabled).toEqual(false);
expect(resultFormData.percent_difference_enabled).toEqual(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export default function PopKPI(props: PopKPIProps) {
headerFontSize,
subheaderFontSize,
comparisonColorEnabled,
previousPeriodValueEnabled,
valueDifferenceEnabled,
percentDifferenceEnabled,
comparisonColorScheme,
percentDifferenceNumber,
currentTimeRangeFilter,
Expand Down Expand Up @@ -194,29 +197,50 @@ export default function PopKPI(props: PopKPIProps) {
percentDifferenceNumber,
]);

const previousPeriodSymbol = previousPeriodValueEnabled
? [
{
symbol: '#',
value: prevNumber,
tooltipText: t('Data for %s', comparisonRange || 'previous range'),
},
]
: [];

const valueDifferenceSymbol = valueDifferenceEnabled
? [
{
symbol: '△',
value: valueDifference,
tooltipText: t('Value difference between the time periods'),
},
]
: [];

const percentDifferenceSymbol = percentDifferenceEnabled
? [
{
symbol: '%',
value: percentDifferenceFormattedString,
tooltipText: t('Percentage difference between the time periods'),
},
]
: [];

const SYMBOLS_WITH_VALUES = useMemo(
() => [
{
symbol: '#',
value: prevNumber,
tooltipText: t('Data for %s', comparisonRange || 'previous range'),
},
{
symbol: '△',
value: valueDifference,
tooltipText: t('Value difference between the time periods'),
},
{
symbol: '%',
value: percentDifferenceFormattedString,
tooltipText: t('Percentage difference between the time periods'),
},
...previousPeriodSymbol,
...valueDifferenceSymbol,
...percentDifferenceSymbol,
],
[
comparisonRange,
prevNumber,
valueDifference,
percentDifferenceFormattedString,
previousPeriodSymbol,
valueDifferenceSymbol,
percentDifferenceSymbol,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'previous_period_value_enabled',
config: {
type: 'CheckboxControl',
label: t('Add previous period value'),
renderTrigger: true,
default: true,
description: t('Add previous period value'),
},
},
],
[
{
name: 'value_difference_enabled',
config: {
type: 'CheckboxControl',
label: t('Add period difference'),
renderTrigger: true,
default: true,
description: t('Add period difference'),
},
},
],
[
{
name: 'percent_difference_enabled',
config: {
type: 'CheckboxControl',
label: t('Add percent difference'),
renderTrigger: true,
default: true,
description: t('Add percent difference'),
},
},
],
[
{
name: 'comparison_color_enabled',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export default function transformProps(chartProps: ChartProps) {
comparisonColorScheme,
comparisonColorEnabled,
percentDifferenceFormat,
previousPeriodValueEnabled,
valueDifferenceEnabled,
percentDifferenceEnabled,
} = formData;
const { data: dataA = [] } = queriesData[0];
const data = dataA;
Expand Down Expand Up @@ -184,6 +187,9 @@ export default function transformProps(chartProps: ChartProps) {
compType,
comparisonColorEnabled,
comparisonColorScheme,
previousPeriodValueEnabled,
valueDifferenceEnabled,
percentDifferenceEnabled,
percentDifferenceNumber: percentDifferenceNum,
currentTimeRangeFilter,
startDateOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export interface PopKPIStylesProps {
subheaderFontSize: keyof typeof supersetTheme.typography.sizes;
boldText: boolean;
comparisonColorEnabled: boolean;
previousPeriodValueEnabled: boolean;
valueDifferenceEnabled: boolean;
percentDifferenceEnabled: boolean;
}

interface PopKPICustomizeProps {
Expand Down
Loading