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

Metric datatype incorrect when swap dataset #29227

Open
3 tasks done
rad-pat opened this issue Jun 12, 2024 · 1 comment
Open
3 tasks done

Metric datatype incorrect when swap dataset #29227

rad-pat opened this issue Jun 12, 2024 · 1 comment
Labels
viz:charts Namespace | Anything related to viz types

Comments

@rad-pat
Copy link

rad-pat commented Jun 12, 2024

Bug description

Swapping the dataset of a chart using the numeric metric of the original dataset to another dataset that has a numeric metric of the same name fails converts the metric datatype to text and loses the custom formatting.

How to reproduce the bug

Create dataset 1 with numeric metric "Metric1", sum(some numeric column), apply D3 formatting $,.2f
Create dataset 2 with the same metric name and formatting.
Create table chart1 from dataset1 add columns and metric1
Create chart and see formatting on metric column
Save Chart
Edit Chart
Swap dataset to dataset2
Click continue on Continue on message about controls will be retained.
View "Customize" tab, metric appears to be numeric
Click "Update Chart" - metric now switches to text and formatting is lost.

Screenshots/recordings

No response

Superset version

3.1.3

Python version

3.10

Node version

I don't know

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@dosubot dosubot bot added the viz:charts Namespace | Anything related to viz types label Jun 12, 2024
Copy link

dosubot bot commented Jun 12, 2024

Hey @rad-pat! I'm here to help you with the issue you've encountered. I'm a bot that can assist you with bug resolution, answer your questions, and guide you on becoming a contributor. Let's dive into solving this together!

To resolve the issue in Superset version 3.1.3 where swapping the dataset of a chart causes a numeric metric to incorrectly convert to text and lose its custom formatting, you can leverage the SHARED_COLUMN_CONFIG_PROPS and DEFAULT_CONFIG_FORM_LAYOUT constants from the superset-frontend/src/explore/components/controls/ColumnConfigControl/constants.tsx file. These constants define the configurable column formatting properties and their default layouts, ensuring that numeric metrics retain their formatting.

Here is how you can ensure the correct formatter is applied:

  1. Import the necessary constants:
import { SHARED_COLUMN_CONFIG_PROPS, DEFAULT_CONFIG_FORM_LAYOUT } from 'path-to-constants';
  1. Use the SHARED_COLUMN_CONFIG_PROPS to define your column formatting properties:
const columnConfigProps = {
  ...SHARED_COLUMN_CONFIG_PROPS,
  // Add any additional custom properties if needed
};
  1. Apply the DEFAULT_CONFIG_FORM_LAYOUT to ensure the correct layout and formatting:
const configFormLayout = {
  ...DEFAULT_CONFIG_FORM_LAYOUT,
  // Customize the layout if necessary
};
  1. Ensure the correct formatter is applied to your numeric metrics:
const formatNumericMetric = (metricValue) => {
  const formatter = columnConfigProps.d3NumberFormat;
  return formatter(metricValue);
};

// Example usage
const formattedValue = formatNumericMetric(yourMetricValue);

By using the SHARED_COLUMN_CONFIG_PROPS and DEFAULT_CONFIG_FORM_LAYOUT, you can ensure that numeric metrics retain their custom formatting when swapping datasets, thus resolving the issue [1][2].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
viz:charts Namespace | Anything related to viz types
Projects
None yet
Development

No branches or pull requests

1 participant