<commit_before>import * as React from 'react';
import { compose } from 'redux';

import { formatDateTime } from '@waldur/core/dateUtils';
import { Link } from '@waldur/core/Link';
import { defaultCurrency } from '@waldur/core/services';
import { withTranslation } from '@waldur/i18n';
import { connectAngularComponent } from '@waldur/store/connect';
import { Table, connectTable, createFetcher } from '@waldur/table-react';
import { formatLongText } from '@waldur/table-react/utils';
import { getCustomer } from '@waldur/workspace/selectors';

import { ProjectCreateButton } from './ProjectCreateButton';
import { ProjectDeleteButton } from './ProjectDeleteButton';
import { ProjectDetailsButton } from './ProjectDetailsButton';
import { ProjectExpandableRowContainer } from './ProjectExpandableRowContainer';

const ProjectLink = ({ row }) => (
  <Link
    state="project.details"
    params={{ uuid: row.uuid }}
    label={row.name}
  />
);

const ProjectCostField = ({ row }) =>
  defaultCurrency(row.billing_price_estimate && row.billing_price_estimate.total || 0);

const ProjectActionsField = ({ row }) => (
  <div className="btn-group">
    <ProjectDetailsButton project={row}/>
    <ProjectDeleteButton project={row}/>
  </div>
);

export const TableComponent = props => {
  const { translate, filterColumns } = props;
  const columns = filterColumns([
    {
      title: translate('Name'),
      render: ProjectLink,
      orderField: 'name',
    },
    {
      title: translate('Description'),
      render: ({ row }) => formatLongText(row.description),
    },
    {
      title: translate('Created'),
      render: ({ row }) => formatDateTime(row.created),
      orderField: 'created',
    },
    {
      title: translate('Estimated cost'),
      feature: 'projectCostDetails',
      render: ProjectCostField,
    },
    {
      title: translate('Actions'),
      render: ProjectActionsField,
    },
  ]);

  return (
    <Table
      {...props}
      columns={columns}
      verboseName={translate('projects')}
      hasQuery={true}
      showPageSizeSelector={true}
      actions={<ProjectCreateButton/>}
      expandableRow={ProjectExpandableRowContainer}
    />
  );
};

const TableOptions = {
  table: 'ProjectsList',
  fetchData: createFetcher('projects'),
  getDefaultFilter: state => ({
    customer: getCustomer(state).uuid,
    o: 'name',
  }),
  exportRow: row => [
    row.name,
    row.description,
    formatDateTime(row.created),
  ],
  exportFields: [
    'Name',<commit_msg>Allow to filter projects by name or UUID [WAL-2196]<commit_after>import * as React from 'react';
import { compose } from 'redux';

import { formatDateTime } from '@waldur/core/dateUtils';
import { Link } from '@waldur/core/Link';
import { defaultCurrency } from '@waldur/core/services';
import { withTranslation } from '@waldur/i18n';
import { connectAngularComponent } from '@waldur/store/connect';
import { Table, connectTable, createFetcher } from '@waldur/table-react';
import { formatLongText } from '@waldur/table-react/utils';
import { getCustomer } from '@waldur/workspace/selectors';

import { ProjectCreateButton } from './ProjectCreateButton';
import { ProjectDeleteButton } from './ProjectDeleteButton';
import { ProjectDetailsButton } from './ProjectDetailsButton';
import { ProjectExpandableRowContainer } from './ProjectExpandableRowContainer';

const ProjectLink = ({ row }) => (
  <Link
    state="project.details"
    params={{ uuid: row.uuid }}
    label={row.name}
  />
);

const ProjectCostField = ({ row }) =>
  defaultCurrency(row.billing_price_estimate && row.billing_price_estimate.total || 0);

const ProjectActionsField = ({ row }) => (
  <div className="btn-group">
    <ProjectDetailsButton project={row}/>
    <ProjectDeleteButton project={row}/>
  </div>
);

export const TableComponent = props => {
  const { translate, filterColumns } = props;
  const columns = filterColumns([
    {
      title: translate('Name'),
      render: ProjectLink,
      orderField: 'name',
    },
    {
      title: translate('Description'),
      render: ({ row }) => formatLongText(row.description),
    },
    {
      title: translate('Created'),
      render: ({ row }) => formatDateTime(row.created),
      orderField: 'created',
    },
    {
      title: translate('Estimated cost'),
      feature: 'projectCostDetails',
      render: ProjectCostField,
    },
    {
      title: translate('Actions'),
      render: ProjectActionsField,
    },
  ]);

  return (
    <Table
      {...props}
      columns={columns}
      verboseName={translate('projects')}
      hasQuery={true}
      showPageSizeSelector={true}
      actions={<ProjectCreateButton/>}
      expandableRow={ProjectExpandableRowContainer}
    />
  );
};

const TableOptions = {
  table: 'ProjectsList',
  fetchData: createFetcher('projects'),
  queryField: 'query',
  getDefaultFilter: state => ({
    customer: getCustomer(state).uuid,
    o: 'name',
  }),
  exportRow: row => [
    row.name,
    row.description,
    formatDateTime(row.created),
  ],
  exportFields: [
    'Name',
{'fraction_non_alphanumeric': 0.14669299111549852, 'fraction_numerical': 0.0019743336623889436, 'mean_word_length': 3.6734317343173433, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, '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': '5189651', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1462, 'n_words': 313}