<commit_before>import * as React from "react";
import * as ItemModels from '../Models/ItemModels';
import * as GradeLevels from '../Models/GradeLevels';
import { AdvancedFilterOption, OptionType, AdvancedFilterCategory, FilterOptions } from './AdvancedFilterModel';
import { AdvancedFilter } from './AdvancedFilter';

interface Props {
    filterOptions: AdvancedFilterCategory[];
    onClick: (selected: AdvancedFilterCategory[]) => void;
}

interface State {
    filters: AdvancedFilterCategory[];
}

export class AdvancedFilterContainer extends React.Component<Props,State>{
    constructor(props:Props){
        super(props);

        this.state = {
            filters: props.filterOptions
        }
    }

    onSelect(category: AdvancedFilterCategory, option?: AdvancedFilterOption) {
        const index = this.state.filters.indexOf(category);
        const newFilters = [...this.state.filters];
        let newOptions = newFilters[index].filterOptions
            .map(opt => {return {...opt, isSelected: false}});

        if (!option) { // all pressed
            
        } else {
            const optionIdx = newFilters[index].filterOptions.indexOf(option);
            if(category.isMultiSelect){
                const optionSelect = newOptions[optionIdx].isSelected;
                //XOR for boolean.
                newOptions[optionIdx].isSelected = newOptions[optionIdx].isSelected ? !optionSelect : optionSelect;
            }
            else {
                newOptions[optionIdx].isSelected = !option.isSelected;
            }

            newFilters[index] = {
                ...newFilters[index],
                filterOptions: newOptions
            };

            this.setState({
                filters: newFilters
            });
        }
    }

    resetFilters() {
        let newFilters = [...this.state.filters];
        newFilters.forEach(cate => {
            cate.filterOptions.map(opt => {return {...opt, isSelected: false}});
        });

        this.setState({
            filters: newFilters
        });
    }

    keyPressResetFilters(e: React.KeyboardEvent<HTMLElement>) {
        if (e.keyCode === 0 || e.keyCode === 13 || e.keyCode === 32) {
            this.resetFilters();<commit_msg>fixing advanced filter render TODO: update table on callback<commit_after>import * as React from "react";
import * as ItemModels from '../Models/ItemModels';
import * as GradeLevels from '../Models/GradeLevels';
import { AdvancedFilterOption, OptionType, AdvancedFilterCategory, FilterOptions } from './AdvancedFilterModel';
import { AdvancedFilter } from './AdvancedFilter';

interface Props {
    filterOptions: AdvancedFilterCategory[];
    onClick: (selected: AdvancedFilterCategory[]) => void;
}

interface State {
    filters: AdvancedFilterCategory[];
}

export class AdvancedFilterContainer extends React.Component<Props,State>{
    constructor(props:Props){
        super(props);

        this.state = {
            filters: props.filterOptions
        }
    }

    onSelect(category: AdvancedFilterCategory, option?: AdvancedFilterOption) {
        const index = this.state.filters.indexOf(category);
        const newFilters = [...this.state.filters];
        let newOptions = newFilters[index].filterOptions
            .map(opt => {return {...opt, isSelected: false}});

        if (!option) { // all pressed
            
        } else {
            const optionIdx = newFilters[index].filterOptions.indexOf(option);
            if(category.isMultiSelect){
                newOptions = newFilters[index].filterOptions
                    .map(opt => {return {...opt}});

                console.log(newOptions[optionIdx].isSelected);
                newOptions[optionIdx].isSelected = !newOptions[optionIdx].isSelected;

                console.log(newOptions[optionIdx].isSelected);
            }
            else {
                newOptions = newFilters[index].filterOptions
                    .map(opt => {return {...opt, isSelected: false}});
                newOptions[optionIdx].isSelected = !option.isSelected;
            }

            newFilters[index] = {
                ...newFilters[index],
                filterOptions: newOptions
            };

            this.setState({
                filters: newFilters
            });
        }
    }

    resetFilters() {
        let newFilters = [...this.state.filters];
        newFilters.forEach(cate => {
            cate.filterOptions.map(opt => {return {...opt, isSelected: false}});
        });

        this.setState({
            filters: newFilters
        });
    }

    keyPressResetFilters(e: React.KeyboardEvent<HTMLElement>) {
        if (e.keyCode === 0 || e.keyCode === 13 || e.keyCode === 32) {
            this.resetFilters();
{'fraction_non_alphanumeric': 0.12089991589571068, 'fraction_numerical': 0.0021026072329688814, 'mean_word_length': 2.179812834224599, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '244026', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1212, 'n_words': 249}