<commit_before>﻿import * as React from "react";
import { TypeContext, LineBaseProps, LineBase, FormGroup } from "../Lines";
import { SearchMessage, MList, newMListElement } from "../Signum.Entities";
import * as Constructor from "../Constructor";
import { Binding, New } from "../Reflection";
import { mlistItemContext } from "../TypeContext";



interface MultiValueLineProps extends LineBaseProps {
    ctx: TypeContext<MList<any>>;    
    onRenderItem: (ctx: TypeContext<any>) => React.ReactElement<any>;
    onCreate?: () => Promise<any>;
    addValueText?: string;
}

export class MultiValueLine extends LineBase<MultiValueLineProps, MultiValueLineProps> {
    calculateDefaultState(state: MultiValueLineProps) {

        if (state.ctx.value == undefined)
            state.ctx.value = [];

        super.calculateDefaultState(state);
    }


    handleDeleteValue = (index: number) => {
        const list = this.state.ctx.value;
        list.removeAt(index);
        this.setValue(list);
    }

    handleAddValue = () => {
        const list = this.state.ctx.value;
        const newValuePromise = this.state.onCreate == null ? this.defaultCreate() : this.state.onCreate();
        newValuePromise.then(v => {
            if (v === undefined)
                return undefined;

            list.push(newMListElement(v));
            this.setValue(list);<commit_msg>fix MultiValueLine<commit_after>﻿import * as React from "react";
import { TypeContext, LineBaseProps, LineBase, FormGroup } from "../Lines";
import { SearchMessage, MList, newMListElement } from "../Signum.Entities";
import * as Constructor from "../Constructor";
import { Binding, New } from "../Reflection";
import { mlistItemContext } from "../TypeContext";



interface MultiValueLineProps extends LineBaseProps {
    ctx: TypeContext<MList<any>>;    
    onRenderItem: (ctx: TypeContext<any>) => React.ReactElement<any>;
    onCreate?: () => Promise<any>;
    addValueText?: string;
}

export class MultiValueLine extends LineBase<MultiValueLineProps, MultiValueLineProps> {
    calculateDefaultState(state: MultiValueLineProps) {

        if (state.ctx.value == undefined)
            state.ctx.value = [];

        super.calculateDefaultState(state);
    }


    handleDeleteValue = (index: number) => {
        const list = this.state.ctx.value;
        list.removeAt(index);
        this.setValue(list);
    }

    handleAddValue = () => {
        const list = this.state.ctx.value;
        const newValuePromise = this.state.onCreate == null ? this.defaultCreate() : this.state.onCreate();

        newValuePromise.then(v => {
            if (v === undefined)
                return;

            list.push(newMListElement(v));
            this.setValue(list);  
{'fraction_non_alphanumeric': 0.1303714493809177, 'fraction_numerical': 0.0, 'mean_word_length': 3.039705882352941, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1205963', 'n_tokens_mistral': 773, 'n_tokens_neox': 761, 'n_words': 169}