<commit_before>import {ICellRendererComp} from "./cellRenderers/iCellRenderer";
import {Autowired, Bean} from "../context/context";
import {ComponentRecipes} from "../components/framework/componentRecipes";
import {ColDef} from "../entities/colDef";
import {GroupCellRendererParams} from "./cellRenderers/groupCellRenderer";
import {ComponentResolver, ComponentSource, ResolvedComponent} from "../components/framework/componentResolver";
import {ISetFilterParams} from "../interfaces/iSetFilterParams";
import {_} from "../utils";

/** Class to use a cellRenderer. */
@Bean('cellRendererService')
export class CellRendererService {
    @Autowired('componentRecipes') private componentRecipes: ComponentRecipes;
    @Autowired('componentResolver') private componentResolver: ComponentResolver;

    public useCellRenderer(
        target:ColDef,
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let cellRenderer: ICellRendererComp = this.componentRecipes.newCellRenderer (target, params);
        return this.bindToHtml(cellRenderer, eTarget);
    }

    public useFilterCellRenderer(
        target:ColDef,
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let cellRenderer: ICellRendererComp = this.componentRecipes.newCellRenderer((<ISetFilterParams>target.filterParams), params);
        return this.bindToHtml(cellRenderer, eTarget);
    }

    public useInnerCellRenderer(
        target:GroupCellRendererParams,
        originalColumn:ColDef,
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let rendererToUse:ICellRendererComp = null;
        let componentToUse:ResolvedComponent<any, any> = this.componentResolver.getComponentToUse(target, "innerRenderer");

        if (componentToUse && componentToUse.component != null && componentToUse.source != ComponentSource.DEFAULT){
            //THERE IS ONE INNER CELL RENDERER HARDCODED IN THE COLDEF FOR THIS GROUP COLUMN
            rendererToUse = this.componentRecipes.newInnerCellRenderer(target, params);
        } else {
            let otherRenderer: ResolvedComponent<any, any> = this.componentResolver.getComponentToUse(originalColumn, "cellRenderer");
            if (otherRenderer.source != ComponentSource.DEFAULT){
                //Only if the original column is using an specific renderer, it it is a using a DEFAULT one
                //ignore it
                //THIS COMES FROM A COLUMN WHICH HAS BEEN GROUPED DYNAMICALLY, WE REUSE ITS RENDERER
                rendererToUse = this.componentRecipes.newCellRenderer(originalColumn, params);
            } else if (otherRenderer.source == ComponentSource.DEFAULT && (_.get(originalColumn, 'cellRendererParams.innerRenderer', null))) {
                //EDGE CASE - THIS COMES FROM A COLUMN WHICH HAS BEEN GROUPED DYNAMICALLY, THAT HAS AS RENDERER 'group'
                //AND HAS A INNER CELL RENDERER
                rendererToUse = this.componentRecipes.newInnerCellRenderer(originalColumn.cellRendererParams, params);
            } else {
                //This forces the retrieval of the default plain cellRenderer that just renders the values.
                rendererToUse = this.componentRecipes.newCellRenderer({}, params);
            }
        }

        return this.bindToHtml(rendererToUse, eTarget);
    }

    public useFullWidthGroupRowInnerCellRenderer(
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let cellRenderer: ICellRendererComp = this.componentRecipes.newFullWidthGroupRowInnerCellRenderer (params);
        return this.bindToHtml(cellRenderer, eTarget);
    }


    public bindToHtml(cellRenderer: ICellRendererComp, eTarget: HTMLElement) {
        let gui: HTMLElement|string = cellRenderer.getGui();
        if (gui != null) {
            if (typeof gui == 'object'){
                eTarget.appendChild(gui);
            } else {
                eTarget.innerHTML = gui;
            }
        }

        return cellRenderer;
    }


<commit_msg>AG-714 Fixing edge case when grouping<commit_after>import {ICellRendererComp} from "./cellRenderers/iCellRenderer";
import {Autowired, Bean} from "../context/context";
import {ComponentRecipes} from "../components/framework/componentRecipes";
import {ColDef} from "../entities/colDef";
import {GroupCellRendererParams} from "./cellRenderers/groupCellRenderer";
import {ComponentResolver, ComponentSource, ResolvedComponent} from "../components/framework/componentResolver";
import {ISetFilterParams} from "../interfaces/iSetFilterParams";
import {_} from "../utils";

/** Class to use a cellRenderer. */
@Bean('cellRendererService')
export class CellRendererService {
    @Autowired('componentRecipes') private componentRecipes: ComponentRecipes;
    @Autowired('componentResolver') private componentResolver: ComponentResolver;

    public useCellRenderer(
        target:ColDef,
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let cellRenderer: ICellRendererComp = this.componentRecipes.newCellRenderer (target, params);
        return this.bindToHtml(cellRenderer, eTarget);
    }

    public useFilterCellRenderer(
        target:ColDef,
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let cellRenderer: ICellRendererComp = this.componentRecipes.newCellRenderer((<ISetFilterParams>target.filterParams), params);
        return this.bindToHtml(cellRenderer, eTarget);
    }

    public useInnerCellRenderer(
        target:GroupCellRendererParams,
        originalColumn:ColDef,
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let rendererToUse:ICellRendererComp = null;
        let componentToUse:ResolvedComponent<any, any> = this.componentResolver.getComponentToUse(target, "innerRenderer");

        if (componentToUse && componentToUse.component != null && componentToUse.source != ComponentSource.DEFAULT){
            //THERE IS ONE INNER CELL RENDERER HARDCODED IN THE COLDEF FOR THIS GROUP COLUMN
            rendererToUse = this.componentRecipes.newInnerCellRenderer(target, params);
        } else {
            let otherRenderer: ResolvedComponent<any, any> = this.componentResolver.getComponentToUse(originalColumn, "cellRenderer");
            if (otherRenderer.source != ComponentSource.DEFAULT){
                //Only if the original column is using an specific renderer, it it is a using a DEFAULT one
                //ignore it
                //THIS COMES FROM A COLUMN WHICH HAS BEEN GROUPED DYNAMICALLY, WE REUSE ITS RENDERER
                rendererToUse = this.componentRecipes.newCellRenderer(originalColumn, params);
            } else if (otherRenderer.source == ComponentSource.DEFAULT && (_.get(originalColumn, 'cellRendererParams.innerRenderer', null))) {
                //EDGE CASE - THIS COMES FROM A COLUMN WHICH HAS BEEN GROUPED DYNAMICALLY, THAT HAS AS RENDERER 'group'
                //AND HAS A INNER CELL RENDERER
                rendererToUse = this.componentRecipes.newInnerCellRenderer(originalColumn.cellRendererParams, params);
            } else {
                //This forces the retrieval of the default plain cellRenderer that just renders the values.
                rendererToUse = this.componentRecipes.newCellRenderer({}, params);
            }
        }
        if (rendererToUse != null) {
            this.bindToHtml(rendererToUse, eTarget);
        } else {
            eTarget.innerText = params.valueFormatted != null ? params.valueFormatted : params.value;
        }
        return rendererToUse;
    }

    public useFullWidthGroupRowInnerCellRenderer(
        eTarget: HTMLElement,
        params: any
    ): ICellRendererComp {
        let cellRenderer: ICellRendererComp = this.componentRecipes.newFullWidthGroupRowInnerCellRenderer (params);
        return this.bindToHtml(cellRenderer, eTarget);
    }


    public bindToHtml(cellRenderer: ICellRendererComp, eTarget: HTMLElement) {
        let gui: HTMLElement|string = cellRenderer.getGui();
        if (gui != null) {
            if (typeof gui == 'object'){
                eTarget.appendChild(gui);
            } else {
                eTarget.innerHTML = gui;
            }
        }

        return cellRenderer;
    }



{'fraction_non_alphanumeric': 0.08839113680154143, 'fraction_numerical': 0.000361271676300578, 'mean_word_length': 3.0101400289715112, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2258694', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2156, 'n_words': 539}