<commit_before>/*
 * Copyright 2015-2016 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "lit";
import {classMap} from "lit/directives/class-map.js";
import LitUtils from "../utils/lit-utils.js";
import "../forms/checkbox-field-filter.js";

export default class VariantTypeFilter extends LitElement {

    constructor() {
        super();

        // Set status and init private properties
        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            type: {
                type: String
            },
            disabled: {
                type: Boolean
            },
            config: {
                type: Object
            }
        };
    }

    _init() {
        this._config = this.getDefaultConfig();
    }

    // TODO Remove this code since it does not seem necessary.
    // connectedCallback() {
    //     super.connectedCallback();
    //     this._config = {...this.getDefaultConfig(), ...this.config};
    // }

    update(changedProperties) {
        if (changedProperties.has("config")) {
            this._config = {...this.getDefaultConfig(), ...this.config};
        }
        super.update(changedProperties);
    }

    filterChange(e) {
        this.type = e.detail.value;
        LitUtils.dispatchCustomEvent(this, "filterChange", this.type);
    }

    onSelectAll() {
        this.type = this._config.types?.join(",");
        LitUtils.dispatchCustomEvent(this, "filterChange", this.type);
    }

    getDefaultConfig() {
        return {
            types: VARIANT_TYPES,
            layout: "vertical"
        };
    }

    render() {
        return html`
            <style>
                variant-type-filter .inline li {
                    display: inline-block;
                    margin-right: 10px;
                }
            </style>

            <div style="margin-bottom: 10px">
                <button type="button" class="btn btn-xs btn-default" @click=${this.onSelectAll}>
                    Select All
                </button>
            </div>
            <div class="${classMap({inline: this._config.layout === "horizontal"})}">
                <checkbox-field-filter
                    .value="${this.type}"
                    .data="${this._config.types}"
                    .disabled="${this.disabled}"
                    @filterChange="${e => this.filterChange(e)}">
                </checkbox-field-filter>
            </div>
        `;
    }

}

customElements.define("variant-type-filter", VariantTypeFilter);
<commit_msg>wc: variant-type-filter.js array of object support added. toggle button added. #404, #405<commit_after>/*
 * Copyright 2015-2016 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "lit";
import {classMap} from "lit/directives/class-map.js";
import LitUtils from "../utils/lit-utils.js";
import "../forms/checkbox-field-filter.js";

export default class VariantTypeFilter extends LitElement {

    constructor() {
        super();

        // Set status and init private properties
        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            type: {
                type: String
            },
            disabled: {
                type: Boolean
            },
            config: {
                type: Object
            }
        };
    }

    _init() {
        this._config = this.getDefaultConfig();
    }

    update(changedProperties) {
        if (changedProperties.has("config")) {
            this._config = {...this.getDefaultConfig(), ...this.config};
        }
        super.update(changedProperties);
    }

    filterChange(e) {
        this.type = e.detail.value;
        LitUtils.dispatchCustomEvent(this, "filterChange", this.type);
    }

    onToggleAll() {
        this.setAll = !this.setAll;
        this.type = this.setAll ?
            this._config.types?.map(t => t?.id ?? t).join(",") :
            null;
        LitUtils.dispatchCustomEvent(this, "filterChange", this.type);
    }

    getDefaultConfig() {
        return {
            types: VARIANT_TYPES, // it can be either an array of strings or array of objects {id, name}
            layout: "vertical"
        };
    }

    render() {
        return html`
            <style>
                variant-type-filter .inline li {
                    display: inline-block;
                    margin-right: 10px;
                }
            </style>

            <div style="margin-bottom: 10px">
                <button type="button" class="btn btn-xs btn-default" @click=${this.onToggleAll}>
                    ${this.setAll ? "Deselect" : "Select"} all
                </button>
            </div>
            <div class="${classMap({inline: this._config.layout === "horizontal"})}">
                <checkbox-field-filter
                    .value="${this.type}"
                    .data="${this._config.types}"
                    .disabled="${this.disabled}"
                    @filterChange="${e => this.filterChange(e)}">
                </checkbox-field-filter>
            </div>
        `;
    }

}

customElements.define("variant-type-filter", VariantTypeFilter);

{'fraction_non_alphanumeric': 0.12213257395981648, 'fraction_numerical': 0.006011707008384749, 'mean_word_length': 1.7874779541446209, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3105465', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1627, 'n_words': 438}