in lib/utils/sort.js [29:55]
export function sortData({ columnKey, data, direction, sortConfig } = {}) {
if (!data) {
console.debug('No data yet, bailing');
return data;
}
if (!Object.keys(sortConfig).includes(columnKey)) {
console.debug(
`"${columnKey}" does not match one of "${Object.keys(sortConfig).join(
', ',
)}"`,
);
return data;
}
if (!['desc', 'asc'].includes(direction)) {
console.debug(`"${direction}" does not match one of 'asc' or 'desc'`);
return data;
}
const sortFunc = sortConfig[columnKey].sortFunc || alphaSort;
const sorted = [].concat(data).sort(sortFunc(columnKey));
// Reverse for desc.
if (direction === 'desc') {
sorted.reverse();
}
return sorted;
}