<commit_before>({
    /**
     *  @description: resets values and visibility for objects based on the object details
     * this is run when the page is first loaded or when a cancel event resets the page
     */
    setObjectAndFieldDependencies: function (cmp) {
        console.log("In setObjectAndFieldDependencies");

        //need to reset fields to populate the selected objects -- refactor to see if necessary
        //fields can be lazy loaded if user is creating a new rollup
        if (cmp.get("v.mode") !== 'create') {
            this.fieldSetup(cmp);
        } else {
            //set active default as true
            cmp.set("v.activeRollup.isActive", true);
            // check for a summary object filter to see if summary fields need to be set
            var summaryObject = cmp.get("v.activeRollup.summaryObject");
            var summaryObjects = cmp.get("v.summaryObjects");
            var label = this.retrieveFieldLabel(summaryObject, summaryObjects);

            //sets summary object if it's being passed from the container
            if (summaryObject) {
                this.onChangeSummaryObject(cmp, summaryObject, label);
            }
            this.hideAllFields(cmp);
            this.setIntegerYearList(cmp);
        }

        //update filter group list to contain none as a first option
        //note: unshift can't be used here due to an issue with bound values
        var filterGroups = cmp.get("v.filterGroups");
        var tempList = [{"name": "", "label": cmp.get("v.labels.na")}];
        tempList = tempList.concat(filterGroups);
        cmp.set("v.filterGroups", tempList);

        console.log('Called reset details');
    },

    /**
     * @description: changes field visibility and save button access based on the mode
     * this is bound to a change handler to the mode attribute
     */
    changeMode: function (cmp) {
        var mode = cmp.get("v.mode");
        //we check to see if mode is null since the change handler is called when mode is cleared in the container
        if (mode) {
            console.log("Mode is " + mode);
            console.log("In changeMode");

            //View is the only readOnly mode. Clone removes the activeRollupId for save.
            //Create hides all fields and sets isIncomplete to disable the save button.
            if (mode === "view") {
                cmp.set("v.isReadOnly", true);
            } else if (mode === "clone") {
                cmp.set("v.activeRollupId", null);
                cmp.set("v.activeRollup.recordId", null);
                cmp.set("v.activeRollup.recordName", null);
                cmp.set("v.isReadOnly", false);
                //reset summary fields, clear current summary field, and rerender rollup name
                var newSummaryFields = this.uniqueSummaryFieldCheck(cmp, cmp.get("v.summaryFields"));
                cmp.set("v.summaryFields", newSummaryFields);
                cmp.set("v.activeRollup.summaryField", null);
                this.updateRollupName(cmp);
                cmp.set("v.isIncomplete", true);
            } else if (mode === "edit") {
                cmp.set("v.isReadOnly", false);
                cmp.set("v.isIncomplete", false);
            } else if (mode === "create") {
                cmp.set("v.isIncomplete", true);
                cmp.set("v.isReadOnly", false);
                this.hideAllFields(cmp);
            } else if (mode === "delete") {
                var activeRollup = cmp.get("v.activeRollup");
                this.saveRollup(cmp, activeRollup);
            }
        }
    },

    /**
     * @description: applies the correct labels for all underlying API values and resets allowed values
     * this is run when the page is first loaded or when a cancel event resets the page
     */
    fieldSetup: function(cmp) {
        this.resetAllFields(cmp);
        this.updateAllowedOperations(cmp);
        this.onChangeOperation(cmp, cmp.get("v.activeRollup.operation"));
        this.setIntegerYearList(cmp);
        this.onChangeTimeBoundOperationsOptions(cmp, false);
        this.onChangeInteger(cmp, cmp.get("v.activeRollup.intValue"));
        var potentialDetailObjects = this.getPotentialDetailObjects(cmp, cmp.get("v.activeRollup.amountObject"));
        this.filterDetailFieldsBySummaryField(cmp, potentialDetailObjects);
        this.updateRollupName(cmp);
    },

    /**
     * @description: filters a picklist of fields by their type
     * @param typeList: list of types to match
     * @param allFields: list of mapped fields to their type to filter
     * @return: the filtered list of values
     */
    filterFieldsByType: function (cmp, typeList, allFields) {
        //if type is null, no detail field is selected
        console.log("filter fields by type function");
        var newFields = [];

        typeList.forEach(function (type) {
            if (!(type === undefined || type === null)) {
                allFields.forEach(function (field) {
                    var datatype = field.type;
                    if (datatype === type) {
                        newFields.push(field);
                    }
                });
            }
        });
        return newFields;
    },

    /**
     * @description: filters possible detail fields by summary type and updates the detailFields attribute
     * @param potentialDetailObjects: list of potential detail objects for this rollup type
     */
    filterDetailFieldsBySummaryField: function (cmp, potentialDetailObjects) {

        //current version filters strictly; update will include type conversion fields
        var summaryField = cmp.get("v.activeRollup.summaryField");

        //need to get all detail fields, or we filter on a subset of all options
        var allFields = [];
        for (var i = 0; i<potentialDetailObjects.length; i++) {
            var objectFields = cmp.get("v.objectDetails")[potentialDetailObjects[i]];
            allFields = allFields.concat(objectFields);
        }

        var newFields = [];

        //loop over all summary fields to get the type of selected field
        var summaryFields = cmp.get("v.summaryFields");
        var type = this.retrieveFieldType(cmp, summaryField, summaryFields);

        //TODO: maybe check if type is the same to see if need to filter?
        //if type is undefined, return all fields<commit_msg>fixed javascript error explicit null rolluptype<commit_after>({
    /**
     *  @description: resets values and visibility for objects based on the object details
     * this is run when the page is first loaded or when a cancel event resets the page
     */
    setObjectAndFieldDependencies: function (cmp) {
        console.log("In setObjectAndFieldDependencies");

        //need to reset fields to populate the selected objects -- refactor to see if necessary
        //fields can be lazy loaded if user is creating a new rollup
        if (cmp.get("v.mode") !== 'create') {
            this.fieldSetup(cmp);
        } else {
            //set active default as true
            cmp.set("v.activeRollup.isActive", true);
            // check for a summary object filter to see if summary fields need to be set
            var summaryObject = cmp.get("v.activeRollup.summaryObject");
            var summaryObjects = cmp.get("v.summaryObjects");
            var label = this.retrieveFieldLabel(summaryObject, summaryObjects);

            //sets summary object if it's being passed from the container
            if (summaryObject) {
                this.onChangeSummaryObject(cmp, summaryObject, label);
            }
            this.hideAllFields(cmp);
            this.setIntegerYearList(cmp);
        }

        //update filter group list to contain none as a first option
        //note: unshift can't be used here due to an issue with bound values
        var filterGroups = cmp.get("v.filterGroups");
        var tempList = [{"name": "", "label": cmp.get("v.labels.na")}];
        tempList = tempList.concat(filterGroups);
        cmp.set("v.filterGroups", tempList);

        console.log('Called reset details');
    },

    /**
     * @description: changes field visibility and save button access based on the mode
     * this is bound to a change handler to the mode attribute
     */
    changeMode: function (cmp) {
        var mode = cmp.get("v.mode");
        //we check to see if mode is null since the change handler is called when mode is cleared in the container
        if (mode) {
            console.log("Mode is " + mode);
            console.log("In changeMode");

            //View is the only readOnly mode. Clone removes the activeRollupId for save.
            //Create hides all fields and sets isIncomplete to disable the save button.
            if (mode === "view") {
                cmp.set("v.isReadOnly", true);
            } else if (mode === "clone") {
                cmp.set("v.activeRollupId", null);
                cmp.set("v.activeRollup.recordId", null);
                cmp.set("v.activeRollup.recordName", null);
                cmp.set("v.isReadOnly", false);
                //reset summary fields, clear current summary field, and rerender rollup name
                var newSummaryFields = this.uniqueSummaryFieldCheck(cmp, cmp.get("v.summaryFields"));
                cmp.set("v.summaryFields", newSummaryFields);
                cmp.set("v.activeRollup.summaryField", null);
                this.updateRollupName(cmp);
                cmp.set("v.isIncomplete", true);
            } else if (mode === "edit") {
                cmp.set("v.isReadOnly", false);
                cmp.set("v.isIncomplete", false);
            } else if (mode === "create") {
                cmp.set("v.isIncomplete", true);
                cmp.set("v.isReadOnly", false);
                this.hideAllFields(cmp);
            } else if (mode === "delete") {
                var activeRollup = cmp.get("v.activeRollup");
                this.saveRollup(cmp, activeRollup);
            }
        }
    },

    /**
     * @description: applies the correct labels for all underlying API values and resets allowed values
     * this is run when the page is first loaded or when a cancel event resets the page
     */
    fieldSetup: function(cmp) {
        this.resetAllFields(cmp);
        this.updateAllowedOperations(cmp);
        this.onChangeOperation(cmp, cmp.get("v.activeRollup.operation"));
        this.setIntegerYearList(cmp);
        this.onChangeTimeBoundOperationsOptions(cmp, false);
        this.onChangeInteger(cmp, cmp.get("v.activeRollup.intValue"));
        var potentialDetailObjects = this.getPotentialDetailObjects(cmp, cmp.get("v.activeRollup.amountObject"));
        this.filterDetailFieldsBySummaryField(cmp, potentialDetailObjects);
        this.updateRollupName(cmp);
    },

    /**
     * @description: filters a picklist of fields by their type
     * @param typeList: list of types to match
     * @param allFields: list of mapped fields to their type to filter
     * @return: the filtered list of values
     */
    filterFieldsByType: function (cmp, typeList, allFields) {
        //if type is null, no detail field is selected
        console.log("filter fields by type function");
        var newFields = [];

        typeList.forEach(function (type) {
            if (!(type === undefined || type === null)) {
                allFields.forEach(function (field) {
                    if(field !== undefined) {
                        var datatype = field.type;
                        if (datatype === type) {
                            newFields.push(field);
                        }
                    }
                });
            }
        });
        return newFields;
    },

    /**
     * @description: filters possible detail fields by summary type and updates the detailFields attribute
     * @param potentialDetailObjects: list of potential detail objects for this rollup type
     */
    filterDetailFieldsBySummaryField: function (cmp, potentialDetailObjects) {

        //current version filters strictly; update will include type conversion fields
        var summaryField = cmp.get("v.activeRollup.summaryField");

        //need to get all detail fields, or we filter on a subset of all options
        var allFields = [];
        for (var i = 0; i<potentialDetailObjects.length; i++) {
            var objectFields = cmp.get("v.objectDetails")[potentialDetailObjects[i]];
            allFields = allFields.concat(objectFields);
        }

        var newFields = [];

        //loop over all summary fields to get the type of selected field
        var summaryFields = cmp.get("v.summaryFields");
        var type = this.retrieveFieldType(cmp, summaryField, summaryFields);

        //TODO: maybe check if type is the same to see if need to filter?
        //if type is undefined, return all fields
{'fraction_non_alphanumeric': 0.10132192846034214, 'fraction_numerical': 0.00015552099533437013, 'mean_word_length': 2.1375945352525005, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, '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': '1678030', 'n_tokens_mistral': 3356, 'n_tokens_neox': 3234, 'n_words': 1072}