<commit_before>import AppError from '../infrastructure/error';
import {orderBy} from '../services/utility';
import {key as getKey, direction as getDirection} from '../sort/sort.service';
import {find} from '../column/column.service';

export default function pipeSort(data, context, next) {
	const values = [];
	const directions = [];
	const model = context.model;
	const dataState = model.data();
	const columns = dataState.columns;
	const sort = model.sort();
	const by = sort.by;

	for (let i = 0, length = by.length; i < length; i++) {
		let item = by[i],
			key = getKey(item),
			value = getDirection(item),
			column = find(columns, key);

		if (!column) {
			throw new AppError('column.service', `Column "${key}" is not found`);
		}

		values.push(context.valueFactory(column));
		directions.push(value);
	}

	const result = orderBy(data, values, directions);
	next(result);
}
<commit_msg>Apply sorting only if order by is setup<commit_after>import AppError from '../infrastructure/error';
import {orderBy} from '../services/utility';
import {key as getKey, direction as getDirection} from '../sort/sort.service';
import {find} from '../column/column.service';

export default function pipeSort(data, context, next) {
	const model = context.model;
	const by = model.sort().by;
	let result = data;

	if (by.length) {
		const columns = model.data().columns;
		const mappings = [];
		const directions = [];

		for (let i = 0, length = by.length; i < length; i++) {
			const sortEntry = by[i];
			const	sortKey = getKey(sortEntry);
			const	sortDir = getDirection(sortEntry);
			const	sortColumn = find(columns, sortKey);
			if (!sortColumn) {
				throw new AppError('sort.pipe', `Column "${sortKey}" is not found`);
			}

			mappings.push(context.valueFactory(sortColumn));
			directions.push(sortDir);
		}

		result = orderBy(data, mappings, directions);
	}

	next(result);
}

{'fraction_non_alphanumeric': 0.15249734325185973, 'fraction_numerical': 0.0010626992561105207, 'mean_word_length': 4.102981029810298, 'pattern_counts': {'":': 0, '<': 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': '211204', 'n_tokens_mistral': 632, 'n_tokens_neox': 581, 'n_words': 174}