<commit_before>import * as React from 'react';
import * as Col from 'react-bootstrap/lib/Col';
import * as Row from 'react-bootstrap/lib/Row';
import useAsync from 'react-use/lib/useAsync';

import { EChart } from '@waldur/core/EChart';
import { LoadingSpinner } from '@waldur/core/LoadingSpinner';
import { Panel } from '@waldur/core/Panel';
import { CategoryResourcesList } from '@waldur/dashboard/CategoryResourcesList';
import { DashboardCounter } from '@waldur/dashboard/DashboardCounter';
import { DashboardHeader } from '@waldur/dashboard/DashboardHeader';
import { isFeatureVisible } from '@waldur/features/connect';
import { translate } from '@waldur/i18n';
import { User, Customer } from '@waldur/workspace/types';

import { loadSummary } from './api';
import { CustomerActions } from './CustomerActions';
import { CustomerResourcesList } from './CustomerResourcesList';

interface CustomerDashboardProps {
  user: User;
  customer: Customer;
}

export const CustomerDashboard = (props: CustomerDashboardProps) => {
  const { loading, value } = useAsync(() => loadSummary(props.customer), [
    props.customer,
  ]);

  return (
    <>
      <DashboardHeader
        title={translate('Welcome, {user}!', { user: props.user.full_name })}
        subtitle={translate('Overview of {organization} organization', {
          organization: props.customer.name,
        })}
      />
      {loading ? (
        <LoadingSpinner />
      ) : (
        <div style={{ paddingLeft: 10 }}>
          <Row>
            {value.map((item, index) => (
              <Col key={index} md={4}>
                <DashboardCounter
                  label={item.chart.title}
                  value={item.chart.current}
                />
                <EChart options={item.options} height="100px" />
              </Col>
            ))}
            <Col md={4}>
              <CustomerActions customer={props.customer} user={props.user} />
            </Col>
          </Row>
          <Panel title={translate('Resources')}>
            <CustomerResourcesList />
          </Panel>
          {isFeatureVisible('customer.dashboard.category-resources-list') && (
            <CategoryResourcesList
              scopeType="organization"
              scope={props.customer}
            />
          )}
        </div>
      )}
    </>
  );
};
<commit_msg>Make customer dashboard chart more robust.<commit_after>import * as React from 'react';
import * as Col from 'react-bootstrap/lib/Col';
import * as Row from 'react-bootstrap/lib/Row';
import useAsync from 'react-use/lib/useAsync';

import { EChart } from '@waldur/core/EChart';
import { LoadingSpinner } from '@waldur/core/LoadingSpinner';
import { Panel } from '@waldur/core/Panel';
import { CategoryResourcesList } from '@waldur/dashboard/CategoryResourcesList';
import { DashboardCounter } from '@waldur/dashboard/DashboardCounter';
import { DashboardHeader } from '@waldur/dashboard/DashboardHeader';
import { isFeatureVisible } from '@waldur/features/connect';
import { translate } from '@waldur/i18n';
import { User, Customer } from '@waldur/workspace/types';

import { loadSummary } from './api';
import { CustomerActions } from './CustomerActions';
import { CustomerResourcesList } from './CustomerResourcesList';

interface CustomerDashboardProps {
  user: User;
  customer: Customer;
}

export const CustomerDashboard = (props: CustomerDashboardProps) => {
  const { loading, value } = useAsync(() => loadSummary(props.customer), [
    props.customer,
  ]);

  return (
    <>
      <DashboardHeader
        title={translate('Welcome, {user}!', { user: props.user.full_name })}
        subtitle={translate('Overview of {organization} organization', {
          organization: props.customer.name,
        })}
      />
      {loading ? (
        <LoadingSpinner />
      ) : Array.isArray(value) ? (
        <div style={{ paddingLeft: 10 }}>
          <Row>
            {value.map((item, index) => (
              <Col key={index} md={4}>
                <DashboardCounter
                  label={item.chart.title}
                  value={item.chart.current}
                />
                <EChart options={item.options} height="100px" />
              </Col>
            ))}
            <Col md={4}>
              <CustomerActions customer={props.customer} user={props.user} />
            </Col>
          </Row>
          <Panel title={translate('Resources')}>
            <CustomerResourcesList />
          </Panel>
          {isFeatureVisible('customer.dashboard.category-resources-list') && (
            <CategoryResourcesList
              scopeType="organization"
              scope={props.customer}
            />
          )}
        </div>
      ) : null}
    </>
  );
};

{'fraction_non_alphanumeric': 0.14005484075089644, 'fraction_numerical': 0.0037966673697532164, 'mean_word_length': 2.466374269005848, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3510990', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1288, 'n_words': 271}