<commit_before>import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { c } from 'ttag';
import { FormModal, useEventManager, useLoading, useApi, useNotifications } from 'react-components';
import { LABEL_COLORS, ROOT_FOLDER, LABEL_TYPE } from 'proton-shared/lib/constants';
import { randomIntFromInterval } from 'proton-shared/lib/helpers/function';
import { create as createLabel, updateLabel } from 'proton-shared/lib/api/labels';
import { noop } from 'proton-shared/lib/helpers/function';

import NewLabelForm from '../NewLabelForm';

function EditLabelModal({
    label = null,
    mode = 'create',
    onEdit = noop,
    onClose = noop,
    onAdd = noop,
    type = 'label',
    ...props
}) {
    const { call } = useEventManager();
    const { createNotification } = useNotifications();
    const api = useApi();
    const [loading, withLoading] = useLoading();

    const I18N = {
        edition({ Type } = {}) {
            if (Type === LABEL_TYPE.MESSAGE_LABEL) {
                return c('Label/folder modal').t`Edit label`;
            }
            return c('Label/folder modal').t`Edit folder`;
        },
        create({ Type } = {}) {
            if (Type === LABEL_TYPE.MESSAGE_LABEL) {
                return c('Label/folder modal').t`Create label`;
            }
            return c('Label/folder modal').t`Create folder`;
        }
    };

    const [model, setModel] = useState(
        label || {
            Name: '',
            Color: LABEL_COLORS[randomIntFromInterval(0, LABEL_COLORS.length - 1)],
            Type: type === 'folder' ? LABEL_TYPE.MESSAGE_FOLDER : LABEL_TYPE.MESSAGE_LABEL,
            ParentID: type === 'folder' ? ROOT_FOLDER : undefined
        }
    );

    const create = async (label) => {
        const { Label } = await api(createLabel(label));
        await call();
        createNotification({
            text: c('label/folder notification').t`${Label.Name} created`
        });
        onAdd(Label);
        onClose();
    };

    const update = async (label) => {
        const { Label } = await api(updateLabel(label.ID, label));
        await call();
        createNotification({
            text: c('Filter notification').t`${Label.Name} updated`
        });
        onEdit(Label);
        onClose();
    };

    const ACTIONS = { create, edition: update };

    const handleSubmit = () => withLoading(ACTIONS[mode](model));

    const handleChangeColor = (Color) => {
        setModel({
            ...model,
            Color
        });<commit_msg>Disable type checking on edit js<commit_after>import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { c } from 'ttag';
import { FormModal, useEventManager, useLoading, useApi, useNotifications } from 'react-components';
import { LABEL_COLORS, ROOT_FOLDER, LABEL_TYPE } from 'proton-shared/lib/constants';
import { randomIntFromInterval } from 'proton-shared/lib/helpers/function';
import { create as createLabel, updateLabel } from 'proton-shared/lib/api/labels';

import NewLabelForm from '../NewLabelForm';

/**
 * @type any
 * @param {any} options
 */
function EditLabelModal({ label = null, mode = 'create', onEdit, onClose, onAdd, type = 'label', ...props }) {
    const { call } = useEventManager();
    const { createNotification } = useNotifications();
    const api = useApi();
    const [loading, withLoading] = useLoading();

    const I18N = {
        edition({ Type } = {}) {
            if (Type === LABEL_TYPE.MESSAGE_LABEL) {
                return c('Label/folder modal').t`Edit label`;
            }
            return c('Label/folder modal').t`Edit folder`;
        },
        create({ Type } = {}) {
            if (Type === LABEL_TYPE.MESSAGE_LABEL) {
                return c('Label/folder modal').t`Create label`;
            }
            return c('Label/folder modal').t`Create folder`;
        }
    };

    const [model, setModel] = useState(
        label || {
            Name: '',
            Color: LABEL_COLORS[randomIntFromInterval(0, LABEL_COLORS.length - 1)],
            Type: type === 'folder' ? LABEL_TYPE.MESSAGE_FOLDER : LABEL_TYPE.MESSAGE_LABEL,
            ParentID: type === 'folder' ? ROOT_FOLDER : undefined
        }
    );

    const create = async (label) => {
        const { Label } = await api(createLabel(label));
        await call();
        createNotification({
            text: c('label/folder notification').t`${Label.Name} created`
        });
        onAdd?.(Label);
        onClose?.();
    };

    const update = async (label) => {
        const { Label } = await api(updateLabel(label.ID, label));
        await call();
        createNotification({
            text: c('Filter notification').t`${Label.Name} updated`
        });
        onEdit?.(Label);
        onClose?.();
    };

    const ACTIONS = { create, edition: update };

    const handleSubmit = () => withLoading(ACTIONS[mode](model));

    const handleChangeColor = (Color) => {
        setModel({
            ...model,
            Color
        });
{'fraction_non_alphanumeric': 0.14282884310618066, 'fraction_numerical': 0.001584786053882726, 'mean_word_length': 2.3615179760319576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5390745', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1456, 'n_words': 345}