32 lines
906 B
TypeScript
32 lines
906 B
TypeScript
export function normalizePayrollColumnOrder(
|
|
storedOrder: string[],
|
|
availableIds: string[],
|
|
): string[] {
|
|
const available = new Set(availableIds);
|
|
const seen = new Set<string>();
|
|
const normalized = storedOrder.filter((columnId) => {
|
|
if (!available.has(columnId) || seen.has(columnId)) return false;
|
|
seen.add(columnId);
|
|
return true;
|
|
});
|
|
for (const columnId of availableIds) {
|
|
if (!seen.has(columnId)) normalized.push(columnId);
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
export function movePayrollColumn(
|
|
columnOrder: string[],
|
|
activeId: string,
|
|
overId: string,
|
|
): string[] {
|
|
const oldIndex = columnOrder.indexOf(activeId);
|
|
const newIndex = columnOrder.indexOf(overId);
|
|
if (oldIndex < 0 || newIndex < 0 || oldIndex === newIndex) return columnOrder;
|
|
|
|
const next = [...columnOrder];
|
|
const [moved] = next.splice(oldIndex, 1);
|
|
next.splice(newIndex, 0, moved);
|
|
return next;
|
|
}
|