Giter VIP home page Giter VIP logo

Comments (1)

dosubot avatar dosubot commented on July 17, 2024 2

Hey @ThinneshHummingsoft! I'm here to help you with your bug report. I can assist you with solving bugs, answering questions, and even becoming a contributor. Let's get to the bottom of this together!

To resolve the "Unexpected error: TypeError: Cannot read properties of undefined (reading 'some')" error when adding metrics in the tree chart page of Apache Superset, ensure that the savedMetrics and columns props passed to the DndMetricSelect component are properly defined and not undefined.

The error occurs because the some method is being called on undefined in the coerceMetrics function. This can happen if savedMetrics or columns are not properly initialized.

Here is the relevant part of the code where the error might be occurring:

const coerceMetrics = (
  addedMetrics: QueryFormMetric | QueryFormMetric[] | undefined | null,
  savedMetrics: Metric[],
  columns: ColumnMeta[],
) => {
  if (!addedMetrics) {
    return [];
  }
  const metricsCompatibleWithDataset = ensureIsArray(addedMetrics).filter(
    metric => {
      if (isSavedMetric(metric)) {
        return savedMetrics.some(
          savedMetric => savedMetric.metric_name === metric,
        );
      }
      if (isAdhocMetricSimple(metric)) {
        return columns.some(
          column => column.column_name === metric.column.column_name,
        );
      }
      return true;
    },
  );

  return metricsCompatibleWithDataset.map(metric => {
    if (!isDictionaryForAdhocMetric(metric)) {
      return metric;
    }
    if (isAdhocMetricSimple(metric)) {
      const column = columns.find(
        col => col.column_name === metric.column.column_name,
      );
      if (column) {
        return new AdhocMetric({ ...metric, column });
      }
    }
    return new AdhocMetric(metric);
  });
};

To fix this, ensure that savedMetrics and columns are always defined when passed to the DndMetricSelect component. You can add default values or checks to handle cases where these might be undefined.

For example:

const DndMetricSelect = (props: any) => {
  const { onChange, multi, datasource, savedMetrics = [], columns = [] } = props;

  // ... rest of the component code
};

By providing default values ([] for both savedMetrics and columns), you can prevent the some method from being called on undefined, thus avoiding the TypeError [1].

To continue talking to Dosu, mention @dosu.

from superset.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.