Make 'sortWorldInfoEntries' custom sortable

This commit is contained in:
Wolfsblvt
2024-08-02 20:57:55 +02:00
parent c0039111dd
commit dee4ad8794

View File

@ -1642,13 +1642,15 @@ function getWIElement(name) {
* Sorts the given data based on the selected sort option * Sorts the given data based on the selected sort option
* *
* @param {any[]} data WI entries * @param {any[]} data WI entries
* @param {object} [options={}] - Optional arguments
* @param {{sortField?: string, sortOrder?: string, sortRule?: string}} [options.customSort={}] - Custom sort options, instead of the chosen UI sort
* @returns {any[]} Sorted data * @returns {any[]} Sorted data
*/ */
export function sortWorldInfoEntries(data) { export function sortWorldInfoEntries(data, { customSort = null } = {}) {
const option = $('#world_info_sort_order').find(':selected'); const option = $('#world_info_sort_order').find(':selected');
const sortField = option.data('field'); const sortField = customSort.sortField ?? option.data('field');
const sortOrder = option.data('order'); const sortOrder = customSort.sortOrder ?? option.data('order');
const sortRule = option.data('rule'); const sortRule = customSort.sortRule ?? option.data('rule');
const orderSign = sortOrder === 'asc' ? 1 : -1; const orderSign = sortOrder === 'asc' ? 1 : -1;
if (!data.length) return data; if (!data.length) return data;