<commit_before>var view = (function () {

    function removeSortableFieldsFromDOM() {
        // Remove all sortable field elements.
        $('.fieldList__item').remove();
    }


    function makeDraggableField(fieldName) {
        // Create a container element for a sortable field.
        var fieldNameSpaceSafe = fieldName.split(' ').join('-');
        var field = $('<div>')
            .addClass('fieldList__item draggableItem field')
            .attr('id', 'sortField-' + fieldNameSpaceSafe)
            .text(fieldName)
            .disableSelection()
            .draggable({
                helper: "clone",
                revert: "invalid"
            });
        return field;
    }


    function makeBucketIndicator() {
        var indicator = $('<div>')
            .addClass('queryBuilder__bucketIndicator');
        return indicator;
    }


    function constructSortableField(fieldName) {
        // Make a single entry in the field list.
        // Entries are composed of two elements: 
        // - a div for the selection indicator
        // - a div for the field's name
        var container = $('<div>')
            .addClass('queryBuilder__fieldListItemContainer');
        var draggableField = makeDraggableField(fieldName);
        var indicator = makeBucketIndicator();
        container.append(indicator, draggableField);
        return container;
    }


    function findBucketIndicatorOfField(fieldName) {
        var matchedElem = $('#sortCol-noField .fieldList__item')
            .filter(function (idx, elem) {
                return utils.textOf($(elem)) === fieldName;
            })
            .first();
        if (!matchedElem) { return; }
        var indicator = $(matchedElem)
            .parent()
            .find('.queryBuilder__bucketIndicator')
            .first();
        return $(indicator);
    }


    function addFieldToBucket(fieldName) {
        // When a given field is added to a sorting bucket, add a selection indicator to its entry in the field list.
        var indicator = findBucketIndicatorOfField(fieldName);
        if (!indicator) { return; }
        var icon = $('<i class="fa fa-check" aria-hidden="true"></i>')
            .appendTo(indicator);
    }


    function removeFieldFromBucket(fieldName) {
        // When a given field is removed from a sorting bucket, also remove its selection indicator in the field list.
        var indicator = findBucketIndicatorOfField(fieldName);
        if (!indicator) { return; }
        indicator.children().remove();
    }


    function addSortableFieldsToDOM(fieldsToAdd) {
        // Given an array of fields, construct a container element for each.
        fieldsToAdd.forEach(function (elem) {
            var field = constructSortableField(elem);
            field.appendTo('#sortCol-noField');
        });
    }


    function resetState(selectedTableObject) {
        // Reset DOM state.
        removeSortableFieldsFromDOM();
        addSortableFieldsToDOM(selectedTableObject.headers);
    }


    function makeFilterText(model, fieldName) {
        // Stringify a filter object.
        var filterObj = data.getFilter(model, fieldName);
        var is = filterObj.filterExistence ? "is" : "is not";
        return "(" + is + " " + filterObj.filterOp + " " + filterObj.filterVal + ")";
    }


    function makeAdditionalUI(model, clickInformation) {
        // Construct filter/reducer guide text and add it to the DOM.
        clickInformation.clicked.find('.additionalUI').remove();
        var text = '';<commit_msg>ensure field indicator is added/removed under proper constraints<commit_after>var view = (function () {

    function removeSortableFieldsFromDOM() {
        // Remove all sortable field elements.
        $('.fieldList__item').remove();
    }


    function makeDraggableField(fieldName) {
        // Create a container element for a sortable field.
        var fieldNameSpaceSafe = fieldName.split(' ').join('-');
        var field = $('<div>')
            .addClass('fieldList__item draggableItem field')
            .attr('id', 'sortField-' + fieldNameSpaceSafe)
            .text(fieldName)
            .disableSelection()
            .draggable({
                helper: "clone",
                revert: "invalid"
            });
        return field;
    }


    function makeBucketIndicator() {
        var indicator = $('<div>')
            .addClass('queryBuilder__bucketIndicator');
        return indicator;
    }


    function constructSortableField(fieldName) {
        // Make a single entry in the field list.
        // Entries are composed of two elements: 
        // - a div for the selection indicator
        // - a div for the field's name
        var container = $('<div>')
            .addClass('queryBuilder__fieldListItemContainer');
        var draggableField = makeDraggableField(fieldName);
        var indicator = makeBucketIndicator();
        container.append(indicator, draggableField);
        return container;
    }


    function findBucketIndicatorOfField(fieldName) {
        var matchedElem = $('#sortCol-noField .fieldList__item')
            .filter(function (idx, elem) {
                return utils.textOf($(elem)) === fieldName;
            })
            .first();
        if (!matchedElem) { return; }
        var indicator = $(matchedElem)
            .parent()
            .find('.queryBuilder__bucketIndicator')
            .first();
        return $(indicator);
    }


    function addFieldToBucket(fieldName) {
        // When a given field is added to a sorting bucket, add a selection indicator to its entry in the field list.
        var indicator = findBucketIndicatorOfField(fieldName);
        if (!indicator) { return; }
        if (indicator.children().length == 0) {
            var icon = $('<i class="fa fa-check" aria-hidden="true"></i>')
                .appendTo(indicator);
        }
    }


    function removeFieldFromBucket(fieldName) {
        // When a given field is removed from a sorting bucket, also remove its selection indicator in the field list.
        var indicator = findBucketIndicatorOfField(fieldName);
        if (!indicator) { return; }
        var occurrencesOfFieldInBuckets = $('.fieldList__item--inBucket')
            .filter(function (idx, elem) {
                return utils.textOf($(elem)) === fieldName;
            })
            .length;
        if (occurrencesOfFieldInBuckets === 0) {
            indicator.children().remove();
        }
    }


    function addSortableFieldsToDOM(fieldsToAdd) {
        // Given an array of fields, construct a container element for each.
        fieldsToAdd.forEach(function (elem) {
            var field = constructSortableField(elem);
            field.appendTo('#sortCol-noField');
        });
    }


    function resetState(selectedTableObject) {
        // Reset DOM state.
        removeSortableFieldsFromDOM();
        addSortableFieldsToDOM(selectedTableObject.headers);
    }


    function makeFilterText(model, fieldName) {
        // Stringify a filter object.
        var filterObj = data.getFilter(model, fieldName);
        var is = filterObj.filterExistence ? "is" : "is not";
        return "(" + is + " " + filterObj.filterOp + " " + filterObj.filterVal + ")";
    }


    function makeAdditionalUI(model, clickInformation) {
        // Construct filter/reducer guide text and add it to the DOM.
        clickInformation.clicked.find('.additionalUI').remove();
        var text = '';
{'fraction_non_alphanumeric': 0.1095396931287525, 'fraction_numerical': 0.000266844563042028, 'mean_word_length': 2.2075310226786478, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1053781', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1910, 'n_words': 511}