<commit_before>/**
 * Copyright 2015-2019 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 UtilsNew from "../../core/utilsNew.js";
import "../commons/opencga-browser.js";
import "./clinical-analysis-view.js";
import "./clinical-analysis-grid.js";
import "./clinical-analysis-browser-filter.js";
import "./clinical-analysis-detail.js";
import "./clinical-analysis-group.js";


export default class ClinicalAnalysisBrowser extends LitElement {

    constructor() {
        super();
        this.#init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            opencgaSession: {
                type: Object
            },
            query: {
                type: Object
            },
            settings: {
                type: Object
            }
        };
    }

    #init() {
        this._prefix = UtilsNew.randomString(8);
        this.errorState = false;
    }

    connectedCallback() {
        super.connectedCallback();
        this._config = this.getDefaultConfig();
    }

    // NOTE turn updated into update here reduces the number of remote requests from 2 to 1 as in the grid components propertyObserver()
    // is executed twice in case there is external settings
    update(changedProperties) {
        if (changedProperties.has("settings")) {
            this.settingsObserver();
        }

        super.update(changedProperties);
    }

    settingsObserver() {
        this._config = this.getDefaultConfig();
        // merge filter list, canned filters, detail tabs
        if (this.settings?.menu) {
            this._config.filter = UtilsNew.mergeFiltersAndDetails(this._config?.filter, this.settings);
        }

        if (this.settings?.table) {
            this._config.filter.result.grid = {
                ...this._config.filter.result.grid,
                ...this.settings.table,
                toolbar: {
                    ...this._config.filter.result.grid.toolbar,
                    ...(this.settings.table.toolbar || {}),
                },
            };
        }
    }

    render() {
        if (!this._config) {
            return null;
        }

        return html`
            <opencga-browser
                resource="CLINICAL_ANALYSIS"
                .opencgaSession="${this.opencgaSession}"
                .query="${this.query}"
                .config="${this._config}">
            </opencga-browser>
        `;
    }

    getDefaultConfig() {
        return {
            title: "Clinical Analysis Browser",
            icon: "fab fa-searchengin",
            searchButtonText: "Search",
            views: [
                {
                    id: "table-tab",
                    name: "Table result",
                    icon: "fa fa-table",
                    active: true,
                    render: params => html `
                        <clinical-analysis-grid
                            .opencgaSession="${params.opencgaSession}"
                            .config="${params.config.filter.result.grid}"
                            .query="${params.executedQuery}"
                            .search="${params.executedQuery}"
                            .active="${params.active}"
                            @selectanalysis="${params.onSelectClinicalAnalysis}"
                            @selectrow="${e => params.onClickRow(e, "clinicalAnalysis")}">
                        </clinical-analysis-grid>
                        <clinical-analysis-detail
                            .opencgaSession="${params.opencgaSession}"
                            .config="${params.config.filter.detail}"
                            .clinicalAnalysisId="${params.detail.clinicalAnalysis?.id}">
                        </clinical-analysis-detail>
                    `,
                },
                {
                    id: "group",
                    name: "Group by",
                    icon: "fas fa-layer-group",
                    active: false,
                    render: params => html`
                        <clinical-analysis-group
                            .opencgaSession="${params.opencgaSession}"
                            .config="${params.config.filter.result.grid}"
                            .query="${params.executedQuery}"
                            .active="${params.active}">
                        </clinical-analysis-group>
                    `,
                },
            ],
            filter: {
                render: params => html `
                    <clinical-analysis-browser-filter
                        .opencgaSession="${params.opencgaSession}"
                        .config="${params.config.filter}"
                        .query="${params.query}"
                        @queryChange="${params.onQueryFilterChange}"
                        @querySearch="${params.onQueryFilterSearch}">
                    </clinical-analysis-browser-filter>`,
                sections: [<commit_msg>wc: minor fixes and improve config merge in clinical analysis browser #TASK-615<commit_after>/**
 * Copyright 2015-2019 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 UtilsNew from "../../core/utilsNew.js";
import "../commons/opencga-browser.js";
import "./clinical-analysis-view.js";
import "./clinical-analysis-grid.js";
import "./clinical-analysis-browser-filter.js";
import "./clinical-analysis-detail.js";
import "./clinical-analysis-group.js";


export default class ClinicalAnalysisBrowser extends LitElement {

    constructor() {
        super();
        this.#init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            opencgaSession: {
                type: Object
            },
            query: {
                type: Object
            },
            settings: {
                type: Object
            }
        };
    }

    #init() {
        this._prefix = UtilsNew.randomString(8);
    }

    connectedCallback() {
        super.connectedCallback();
        this._config = this.getDefaultConfig();
    }

    // NOTE turn updated into update here reduces the number of remote requests from 2 to 1 as in the grid components propertyObserver()
    // is executed twice in case there is external settings
    update(changedProperties) {
        if (changedProperties.has("settings")) {
            this.settingsObserver();
        }

        super.update(changedProperties);
    }

    settingsObserver() {
        const defaultConfig = this.getDefaultConfig();
        this._config = {
            ...defaultConfig,
            ...this.settings,
        };

        // merge filter list, canned filters, detail tabs
        if (this.settings?.menu) {
            this._config.filter = UtilsNew.mergeFiltersAndDetails(defaultConfig.filter, this.settings);
        }

        if (this.settings?.table) {
            this._config.filter.result.grid = {
                ...defaultConfig.filter.result.grid,
                ...this.settings.table,
                toolbar: {
                    ...defaultConfig.filter.result.grid.toolbar,
                    ...(this.settings.table.toolbar || {}),
                },
            };
        }
    }

    render() {
        if (!this._config) {
            return null;
        }

        return html`
            <opencga-browser
                resource="CLINICAL_ANALYSIS"
                .opencgaSession="${this.opencgaSession}"
                .query="${this.query}"
                .config="${this._config}">
            </opencga-browser>
        `;
    }

    getDefaultConfig() {
        return {
            title: "Clinical Analysis Browser",
            icon: "fab fa-searchengin",
            searchButtonText: "Search",
            views: [
                {
                    id: "table-tab",
                    name: "Table result",
                    icon: "fa fa-table",
                    active: true,
                    render: params => html `
                        <clinical-analysis-grid
                            .opencgaSession="${params.opencgaSession}"
                            .config="${params.config.filter.result.grid}"
                            .query="${params.executedQuery}"
                            .search="${params.executedQuery}"
                            .active="${params.active}"
                            @selectanalysis="${params.onSelectClinicalAnalysis}"
                            @selectrow="${e => params.onClickRow(e, "clinicalAnalysis")}">
                        </clinical-analysis-grid>
                        <clinical-analysis-detail
                            .opencgaSession="${params.opencgaSession}"
                            .config="${params.config.filter.detail}"
                            .clinicalAnalysisId="${params.detail.clinicalAnalysis?.id}">
                        </clinical-analysis-detail>
                    `,
                },
                {
                    id: "group",
                    name: "Group by",
                    icon: "fas fa-layer-group",
                    active: false,
                    render: params => html`
                        <clinical-analysis-group
                            .opencgaSession="${params.opencgaSession}"
                            .config="${params.config.filter.result.grid}"
                            .query="${params.executedQuery}"
                            .active="${params.active}">
                        </clinical-analysis-group>
                    `,
                },
            ],
            filter: {
                render: params => html `
                    <clinical-analysis-browser-filter
                        .opencgaSession="${params.opencgaSession}"
                        .config="${params.config.filter}"
                        .query="${params.query}"
                        @queryChange="${params.onQueryFilterChange}"
                        @querySearch="${params.onQueryFilterSearch}">
                    </clinical-analysis-browser-filter>
                `,
                sections: [
{'fraction_non_alphanumeric': 0.113272921108742, 'fraction_numerical': 0.002931769722814499, 'mean_word_length': 1.3849576271186441, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, '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': '1787817', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2562, 'n_words': 575}