mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
refactor: table mode and context
This commit is contained in:
@@ -5,6 +5,9 @@ import { EntryId, isOntimeEvent, isOntimeGroup, RundownEntries, SupportedEntry }
|
||||
* ------------------------------------
|
||||
* Due to limitations in dnd-kit we need to flatten the list of entries
|
||||
* This list should also be aware of any elements that are sortable (ie: group ends)
|
||||
*
|
||||
* Note: This creates the FULL structure including all entries and pseudo end-group entries.
|
||||
* For rendering, use filterVisibleEntries() to exclude collapsed items.
|
||||
*/
|
||||
export function makeSortableList(order: EntryId[], entries: RundownEntries): EntryId[] {
|
||||
const flatIds: EntryId[] = [];
|
||||
@@ -31,6 +34,42 @@ export function makeSortableList(order: EntryId[], entries: RundownEntries): Ent
|
||||
return flatIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters sortable list to only include visible entries based on collapsed state
|
||||
* ------------------------------------
|
||||
* Excludes:
|
||||
* - Children of collapsed groups
|
||||
* - End-group markers of collapsed groups
|
||||
*
|
||||
* This is used by Virtuoso for rendering, while DND-kit uses the full sortableData.
|
||||
*/
|
||||
export function filterVisibleEntries(
|
||||
sortableData: EntryId[],
|
||||
entries: RundownEntries,
|
||||
getIsCollapsed: (groupId: EntryId) => boolean,
|
||||
): EntryId[] {
|
||||
return sortableData.filter((entryId) => {
|
||||
// group end pseudo entries are only shown if the group is expanded
|
||||
if (entryId.startsWith('end-')) {
|
||||
const parentId = entryId.split('end-')[1];
|
||||
return !getIsCollapsed(parentId);
|
||||
}
|
||||
|
||||
// retrieve the entry as usual
|
||||
const entry = entries[entryId];
|
||||
if (!entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if entry has a parent and parent is collapsed, filter it out
|
||||
if (entry.type !== SupportedEntry.Group && 'parent' in entry && entry.parent) {
|
||||
return !getIsCollapsed(entry.parent);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a drop operation is valid
|
||||
* Currently only used for validating dropping groups
|
||||
|
||||
Reference in New Issue
Block a user