<commit_before>frappe.ui.Filter = class {
	constructor(opts) {
		$.extend(this, opts);
		if (this.value === null || this.value === undefined) {
			this.value = '';
		}

		this.utils = frappe.ui.filter_utils;
		this.conditions = [
			["=", __("Equals")],
			["!=", __("Not Equals")],
			["like", __("Like")],
			["not like", __("Not Like")],
			["in", __("In")],
			["not in", __("Not In")],
			["is", __("Is")],
			[">", ">"],
			["<", "<"],
			[">=", ">="],
			["<=", "<="],
			["Between", __("Between")],
			["Previous", __("Previous")],
			["Next", __("Next")]
		];

		this.nested_set_conditions = [
			["descendants of", __("Descendants Of")],
			["not descendants of", __("Not Descendants Of")],
			["ancestors of", __("Ancestors Of")],
			["not ancestors of", __("Not Ancestors Of")],
		];

		this.conditions.push(...this.nested_set_conditions);

		this.invalid_condition_map = {
			Date: ['like', 'not like'],
			Datetime: ['like', 'not like'],
			Data: ['Between', 'Previous', 'Next'],
			Select: ['like', 'not like', 'Between', 'Previous', 'Next'],
			Link: ["Between", 'Previous', 'Next', '>', '<', '>=', '<='],
			Currency: ["Between", 'Previous', 'Next'],
			Color: ["Between", 'Previous', 'Next'],
			Check: this.conditions.map(c => c[0]).filter(c => c !== '=')
		};
		this.make();
		this.make_select();
		this.set_events();
		this.setup();
	}

	make() {
		this.filter_edit_area = $(frappe.render_template("edit_filter", {
			conditions: this.conditions
		}))
			.appendTo(this.parent.find('.filter-edit-area'));
	}

	make_select() {
		this.fieldselect = new frappe.ui.FieldSelect({
			parent: this.filter_edit_area.find('.fieldname-select-area'),
			doctype: this.parent_doctype,
			filter_fields: this.filter_fields,
			select: (doctype, fieldname) => {
				this.set_field(doctype, fieldname);
			}
		});

		if(this.fieldname) {
			this.fieldselect.set_value(this.doctype, this.fieldname);
		}
	}

	set_events() {
		this.filter_edit_area.find("a.remove-filter").on("click", () => {
			this.remove();
		});

		this.filter_edit_area.find(".set-filter-and-run").on("click", () => {
			this.filter_edit_area.removeClass("new-filter");
			this.on_change();
			this.update_filter_tag();
		});

		this.filter_edit_area.find('.condition').change(() => {
			if(!this.field) return;

			let condition = this.get_condition();
			let fieldtype = null;

			if(["in", "like", "not in", "not like"].includes(condition)) {
				fieldtype = 'Data';
				this.add_condition_help(condition);
			}

			if (['Select', 'MultiSelect'].includes(this.field.df.fieldtype) && ["in", "not in"].includes(condition)) {
				fieldtype = 'MultiSelect';
			}

			this.set_field(this.field.df.parent, this.field.df.fieldname, fieldtype, condition);
		});
	}

	setup() {
		const fieldname = this.fieldname || 'name';
		// set the field
		return this.set_values(this.doctype, fieldname, this.condition, this.value);
	}

	setup_state(is_new) {
		let promise = Promise.resolve();
		if (is_new) {
			this.filter_edit_area.addClass("new-filter");
		} else {
			promise = this.update_filter_tag();
		}

		if(this.hidden) {
			promise.then(() => this.$filter_tag.hide());
		}
	}

	freeze() {
		this.update_filter_tag();
	}

	update_filter_tag() {
		if (this._filter_value_set) {
			return this._filter_value_set.then(() => {
				!this.$filter_tag ? this.make_tag() : this.set_filter_button_text();
				this.filter_edit_area.hide();
			});
		} else {
			return Promise.resolve();
		}
	}

	remove() {
		this.filter_edit_area.remove();
		this.$filter_tag && this.$filter_tag.remove();
		this.field = null;
		this.on_change(true);
	}

	set_values(doctype, fieldname, condition, value) {
		// presents given (could be via tags!)
		if (this.set_field(doctype, fieldname) === false) {
			return
		}

		if(this.field.df.original_type==='Check') {
			value = (value==1) ? 'Yes' : 'No';
		}
		if(condition) this.set_condition(condition, true);

		// set value can be asynchronous, so update_filter_tag should happen after field is set
		this._filter_value_set = Promise.resolve();

		if (['in', 'not in'].includes(condition) && Array.isArray(value)) {
			value = value.join(',');
		}

		if (Array.isArray(value)) {
			this._filter_value_set = this.field.set_value(value);
		} else if (value !== undefined || value !== null) {
			this._filter_value_set = this.field.set_value((value + '').trim());
		}
		return this._filter_value_set;
	}

	set_field(doctype, fieldname, fieldtype, condition) {
		// set in fieldname (again)
		let cur = {};
		if(this.field) for(let k in this.field.df) cur[k] = this.field.df[k];

		let original_docfield = (this.fieldselect.fields_by_name[doctype] || {})[fieldname];

		if(!original_docfield) {
			console.warn(`Field ${fieldname} is not selectable.`);
			this.remove();
			return false;
		}

		let df = copy_dict(original_docfield);

		// filter field shouldn't be read only or hidden
		df.read_only = 0;
		df.hidden = 0;
		df.is_filter = true;

		let c = condition ? condition : this.utils.get_default_condition(df);
		this.set_condition(c);

		this.utils.set_fieldtype(df, fieldtype, this.get_condition());

		// called when condition is changed,
		// don't change if all is well
		if(this.field && cur.fieldname == fieldname && df.fieldtype == cur.fieldtype &&
			df.parent == cur.parent) {<commit_msg>fix: check for df options in set fieldin case field type for both conditions is the same<commit_after>frappe.ui.Filter = class {
	constructor(opts) {
		$.extend(this, opts);
		if (this.value === null || this.value === undefined) {
			this.value = '';
		}

		this.utils = frappe.ui.filter_utils;
		this.conditions = [
			["=", __("Equals")],
			["!=", __("Not Equals")],
			["like", __("Like")],
			["not like", __("Not Like")],
			["in", __("In")],
			["not in", __("Not In")],
			["is", __("Is")],
			[">", ">"],
			["<", "<"],
			[">=", ">="],
			["<=", "<="],
			["Between", __("Between")],
			["Previous", __("Previous")],
			["Next", __("Next")]
		];

		this.nested_set_conditions = [
			["descendants of", __("Descendants Of")],
			["not descendants of", __("Not Descendants Of")],
			["ancestors of", __("Ancestors Of")],
			["not ancestors of", __("Not Ancestors Of")],
		];

		this.conditions.push(...this.nested_set_conditions);

		this.invalid_condition_map = {
			Date: ['like', 'not like'],
			Datetime: ['like', 'not like'],
			Data: ['Between', 'Previous', 'Next'],
			Select: ['like', 'not like', 'Between', 'Previous', 'Next'],
			Link: ["Between", 'Previous', 'Next', '>', '<', '>=', '<='],
			Currency: ["Between", 'Previous', 'Next'],
			Color: ["Between", 'Previous', 'Next'],
			Check: this.conditions.map(c => c[0]).filter(c => c !== '=')
		};
		this.make();
		this.make_select();
		this.set_events();
		this.setup();
	}

	make() {
		this.filter_edit_area = $(frappe.render_template("edit_filter", {
			conditions: this.conditions
		}))
			.appendTo(this.parent.find('.filter-edit-area'));
	}

	make_select() {
		this.fieldselect = new frappe.ui.FieldSelect({
			parent: this.filter_edit_area.find('.fieldname-select-area'),
			doctype: this.parent_doctype,
			filter_fields: this.filter_fields,
			select: (doctype, fieldname) => {
				this.set_field(doctype, fieldname);
			}
		});

		if(this.fieldname) {
			this.fieldselect.set_value(this.doctype, this.fieldname);
		}
	}

	set_events() {
		this.filter_edit_area.find("a.remove-filter").on("click", () => {
			this.remove();
		});

		this.filter_edit_area.find(".set-filter-and-run").on("click", () => {
			this.filter_edit_area.removeClass("new-filter");
			this.on_change();
			this.update_filter_tag();
		});

		this.filter_edit_area.find('.condition').change(() => {
			if(!this.field) return;

			let condition = this.get_condition();
			let fieldtype = null;

			if(["in", "like", "not in", "not like"].includes(condition)) {
				fieldtype = 'Data';
				this.add_condition_help(condition);
			}

			if (['Select', 'MultiSelect'].includes(this.field.df.fieldtype) && ["in", "not in"].includes(condition)) {
				fieldtype = 'MultiSelect';
			}

			this.set_field(this.field.df.parent, this.field.df.fieldname, fieldtype, condition);
		});
	}

	setup() {
		const fieldname = this.fieldname || 'name';
		// set the field
		return this.set_values(this.doctype, fieldname, this.condition, this.value);
	}

	setup_state(is_new) {
		let promise = Promise.resolve();
		if (is_new) {
			this.filter_edit_area.addClass("new-filter");
		} else {
			promise = this.update_filter_tag();
		}

		if(this.hidden) {
			promise.then(() => this.$filter_tag.hide());
		}
	}

	freeze() {
		this.update_filter_tag();
	}

	update_filter_tag() {
		if (this._filter_value_set) {
			return this._filter_value_set.then(() => {
				!this.$filter_tag ? this.make_tag() : this.set_filter_button_text();
				this.filter_edit_area.hide();
			});
		} else {
			return Promise.resolve();
		}
	}

	remove() {
		this.filter_edit_area.remove();
		this.$filter_tag && this.$filter_tag.remove();
		this.field = null;
		this.on_change(true);
	}

	set_values(doctype, fieldname, condition, value) {
		// presents given (could be via tags!)
		if (this.set_field(doctype, fieldname) === false) {
			return
		}

		if(this.field.df.original_type==='Check') {
			value = (value==1) ? 'Yes' : 'No';
		}
		if(condition) this.set_condition(condition, true);

		// set value can be asynchronous, so update_filter_tag should happen after field is set
		this._filter_value_set = Promise.resolve();

		if (['in', 'not in'].includes(condition) && Array.isArray(value)) {
			value = value.join(',');
		}

		if (Array.isArray(value)) {
			this._filter_value_set = this.field.set_value(value);
		} else if (value !== undefined || value !== null) {
			this._filter_value_set = this.field.set_value((value + '').trim());
		}
		return this._filter_value_set;
	}

	set_field(doctype, fieldname, fieldtype, condition) {
		// set in fieldname (again)
		let cur = {};
		if(this.field) for(let k in this.field.df) cur[k] = this.field.df[k];

		let original_docfield = (this.fieldselect.fields_by_name[doctype] || {})[fieldname];

		if(!original_docfield) {
			console.warn(`Field ${fieldname} is not selectable.`);
			this.remove();
			return false;
		}

		let df = copy_dict(original_docfield);

		// filter field shouldn't be read only or hidden
		df.read_only = 0;
		df.hidden = 0;
		df.is_filter = true;

		let c = condition ? condition : this.utils.get_default_condition(df);
		this.set_condition(c);

		this.utils.set_fieldtype(df, fieldtype, this.get_condition());

		// called when condition is changed,
		// don't change if all is well
		if(this.field && cur.fieldname == fieldname && df.fieldtype == cur.fieldtype &&
			df.parent == cur.parent && df.options == cur.options) {
{'fraction_non_alphanumeric': 0.19785046728971964, 'fraction_numerical': 0.0007476635514018691, 'mean_word_length': 3.8486633439057543, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, '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': '6335423', 'n_tokens_mistral': 4287, 'n_tokens_neox': 3756, 'n_words': 700}