Files
warren/frontend/utils/selection.ts

18 lines
658 B
TypeScript

import type { DirectoryEntry } from '~/shared/types';
/** Converts a selection and the entry that triggered an action into the target entries
* @param targetEntry - The entry that triggered an action
* @param selection - The selected entries
* @returns If there are no selected elements or the target was not included only the target is returned. Otherwise the selection is returned
*/
export function getTargetsFromSelection(
targetEntry: DirectoryEntry,
selection: Set<DirectoryEntry>
): DirectoryEntry[] {
if (selection.size === 0 || !selection.has(targetEntry)) {
return [targetEntry];
}
return Array.from(selection);
}