<commit_before>/* eslint-disable react/no-multi-comp */

import React from 'react';
import {getGenericListPageComponent, GenericListPageComponent} from 'core/ui/components/ListPage/generic-list-page';
import {IFormField, IFormGroup, FormFieldType} from 'core/ui/components/generic-form/interfaces/form';
import {ListItemColumn, ListItemActionsMenu, ListItem} from 'core/components/ListItem';
import {getFormFieldPreviewComponent} from 'core/ui/components/generic-form/form-field';
import {IInternalDestination} from 'superdesk-interfaces/InternalDestination';

const InternalDestinationsPageComponent = getGenericListPageComponent<IInternalDestination>('internal_destinations');

const nameField: IFormField = {
    label: gettext('Destination name'),
    type: FormFieldType.textSingleLine,
    field: 'name',
    required: true,
};

const isActiveField: IFormField = {
    label: gettext('Active'),
    type: FormFieldType.checkbox,
    field: 'is_active',
};

const contentFilterField: IFormField = {
    label: gettext('Content filter'),
    type: FormFieldType.contentFilterSingleValue,
    field: 'filter',
};

const deskField: IFormField = {
    label: gettext('Desk'),
    type: FormFieldType.deskSingleValue,
    field: 'desk',
    required: true,
};

const stageField: IFormField = {
    label: gettext('Stage'),
    type: FormFieldType.stageSingleValue,
    field: 'stage',
    component_parameters: {
        deskField: 'desk',
    },
};

const macroField: IFormField = {
    label: gettext('Macro'),
    type: FormFieldType.macroSingleValue,
    field: 'macro',
    component_parameters: {
        deskField: 'desk',
    },
};

const formConfig: IFormGroup = {
    direction: 'vertical',
    type: 'inline',
    form: [
        isActiveField,
        nameField,
        contentFilterField,
        deskField,
        stageField,
        macroField,
    ],
};

const renderRow = (
    key: string,
    item: IInternalDestination,
    page: GenericListPageComponent<IInternalDestination>,
) => (
    <ListItem
        key={key}
        onClick={() => page.openPreview(item._id)}
        inactive={!item.is_active}
        data-test-id="internal-destinations-item"
    >
        <ListItemColumn ellipsisAndGrow noBorder>
            {getFormFieldPreviewComponent(item, nameField)}
        </ListItemColumn>
        {
            item.is_active ? null : (
                <ListItemColumn noBorder>
                    <span className="label label--hollow label--alert">{gettext('Inactive')}</span>
                </ListItemColumn><commit_msg>Make delaying of item creation in internal destinations configurable. (SDESK-4129) (#2965)<commit_after>/* eslint-disable react/no-multi-comp */

import React from 'react';
import {getGenericListPageComponent, GenericListPageComponent} from 'core/ui/components/ListPage/generic-list-page';
import {IFormField, IFormGroup, FormFieldType} from 'core/ui/components/generic-form/interfaces/form';
import {ListItemColumn, ListItemActionsMenu, ListItem} from 'core/components/ListItem';
import {getFormFieldPreviewComponent} from 'core/ui/components/generic-form/form-field';
import {IInternalDestination} from 'superdesk-interfaces/InternalDestination';

const InternalDestinationsPageComponent = getGenericListPageComponent<IInternalDestination>('internal_destinations');

const nameField: IFormField = {
    label: gettext('Destination name'),
    type: FormFieldType.textSingleLine,
    field: 'name',
    required: true,
};

const isActiveField: IFormField = {
    label: gettext('Active'),
    type: FormFieldType.checkbox,
    field: 'is_active',
};

const contentFilterField: IFormField = {
    label: gettext('Content filter'),
    type: FormFieldType.contentFilterSingleValue,
    field: 'filter',
};

const deskField: IFormField = {
    label: gettext('Desk'),
    type: FormFieldType.deskSingleValue,
    field: 'desk',
    required: true,
};

const stageField: IFormField = {
    label: gettext('Stage'),
    type: FormFieldType.stageSingleValue,
    field: 'stage',
    component_parameters: {
        deskField: 'desk',
    },
};

const macroField: IFormField = {
    label: gettext('Macro'),
    type: FormFieldType.macroSingleValue,
    field: 'macro',
    component_parameters: {
        deskField: 'desk',
    },
};

const sendAfterSchedule: IFormField = {
    label: gettext('Send only after publish schedule'),
    type: FormFieldType.checkbox,
    field: 'send_after_schedule',
};

const formConfig: IFormGroup = {
    direction: 'vertical',
    type: 'inline',
    form: [
        isActiveField,
        sendAfterSchedule,
        nameField,
        contentFilterField,
        deskField,
        stageField,
        macroField,
    ],
};

const renderRow = (
    key: string,
    item: IInternalDestination,
    page: GenericListPageComponent<IInternalDestination>,
) => (
    <ListItem
        key={key}
        onClick={() => page.openPreview(item._id)}
        inactive={!item.is_active}
        data-test-id="internal-destinations-item"
    >
        <ListItemColumn ellipsisAndGrow noBorder>
            {getFormFieldPreviewComponent(item, nameField)}
        </ListItemColumn>
        {
            item.is_active ? null : (
                <ListItemColumn noBorder>
                    <span className="label label--hollow label--alert">{gettext('Inactive')}</span>
                </ListItemColumn>
{'fraction_non_alphanumeric': 0.11830357142857142, 'fraction_numerical': 0.001488095238095238, 'mean_word_length': 3.5109060402684564, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, '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': '2979410', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1580, 'n_words': 311}