<commit_before>import { connect } from 'react-redux';
import classnames from 'classnames';

import PropTypes from 'prop-types';
import { Grid, IconButton, Icon, TextField } from '@material-ui/core';
import MySelect from '../../../../common/select';
import InputListField from '../../../../common/input-list-field';
import ConditionallyRender from '../../../../common/ConditionallyRender/ConditionallyRender';
import { useCommonStyles } from '../../../../../common.styles';
import { useStyles } from './OverrideConfig.styles.js';
import { Autocomplete } from '@material-ui/lab';

const OverrideConfig = ({
    overrides,
    updateOverrideType,
    updateOverrideValues,
    removeOverride,
    contextDefinitions,
}) => {
    const styles = useStyles();
    const commonStyles = useCommonStyles();
    const contextNames = contextDefinitions.map(c => ({
        key: c.name,
        label: c.name,
    }));

    const updateValues = i => values => {
        updateOverrideValues(i, values);
    };

    const updateSelectValues = i => (e, options) => {
        updateOverrideValues(i, options ? options : []);
    };

    return overrides.map((o, i) => {
        const legalValues =
            contextDefinitions.find(c => c.name === o.contextName)
                .legalValues || [];

        return (
            <Grid container key={`override=${i}`} alignItems="center">
                <Grid item md={3} className={styles.contextFieldSelect}>
                    <MySelect
                        name="contextName"
                        label="Context Field"
                        value={o.contextName}
                        options={contextNames}
                        classes={{
                            root: classnames(commonStyles.fullWidth),
                        }}
                        onChange={updateOverrideType(i)}
                    />
                </Grid>
                <Grid md={7} item>
                    <ConditionallyRender
                        condition={legalValues && legalValues.length > 0}
                        show={
                            <Autocomplete
                                multiple<commit_msg>fix: only get legalValues if definition exists<commit_after>import { connect } from 'react-redux';
import classnames from 'classnames';

import PropTypes from 'prop-types';
import { Grid, IconButton, Icon, TextField } from '@material-ui/core';
import MySelect from '../../../../common/select';
import InputListField from '../../../../common/input-list-field';
import ConditionallyRender from '../../../../common/ConditionallyRender/ConditionallyRender';
import { useCommonStyles } from '../../../../../common.styles';
import { useStyles } from './OverrideConfig.styles.js';
import { Autocomplete } from '@material-ui/lab';

const OverrideConfig = ({
    overrides,
    updateOverrideType,
    updateOverrideValues,
    removeOverride,
    contextDefinitions,
}) => {
    const styles = useStyles();
    const commonStyles = useCommonStyles();
    const contextNames = contextDefinitions.map(c => ({
        key: c.name,
        label: c.name,
    }));

    const updateValues = i => values => {
        updateOverrideValues(i, values);
    };

    const updateSelectValues = i => (e, options) => {
        updateOverrideValues(i, options ? options : []);
    };

    return overrides.map((o, i) => {
        const definition = contextDefinitions.find(
            c => c.name === o.contextName
        );
        const legalValues = definition ? definition.legalValues : [];

        return (
            <Grid container key={`override=${i}`} alignItems="center">
                <Grid item md={3} className={styles.contextFieldSelect}>
                    <MySelect
                        name="contextName"
                        label="Context Field"
                        value={o.contextName}
                        options={contextNames}
                        classes={{
                            root: classnames(commonStyles.fullWidth),
                        }}
                        onChange={updateOverrideType(i)}
                    />
                </Grid>
                <Grid md={7} item>
                    <ConditionallyRender
                        condition={legalValues && legalValues.length > 0}
                        show={
                            <Autocomplete
                                multiple
{'fraction_non_alphanumeric': 0.12921475446933695, 'fraction_numerical': 0.0013577732518669382, 'mean_word_length': 1.7216748768472907, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, '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': '4742658', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1042, 'n_words': 241}