Skip to content

Commit

Permalink
merge groups
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpkane committed Nov 25, 2024
1 parent 4d17241 commit 4d554d6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 45 additions & 0 deletions app/packages/state/src/recoil/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,47 @@ const DEFAULT_VIDEO_GROUPS: State.SidebarGroup[] = [

const NONE = [null, undefined];

const insertFromNeighbor = (sink: string[], source: string[], key: string) => {
if (sink.includes(key)) {
return;
}
const sourceIndex = source.indexOf(key);
const neighbor = source[sourceIndex - 1];
const neighborIndex = sink.indexOf(neighbor);

!neighbor ? sink.push(key) : sink.splice(neighborIndex + 1, 0, key);
};

const mergeGroups = (
sink: State.SidebarGroup[],
source: State.SidebarGroup[]
) => {
const mapping = Object.fromEntries(sink.map((g) => [g.name, g]));
const configMapping = Object.fromEntries(source.map((g) => [g.name, g]));
const sinkKeys = sink.map(({ name }) => name);
const sourceKeys = source.map(({ name }) => name);
for (const key of sourceKeys) {
insertFromNeighbor(sinkKeys, sourceKeys, key);
}

const resolved = sink.map((g) => mapping[g] ?? configMapping[g]);
for (const g in sink) {
const i = source.indexOf(g);

if (i < 0) {
continue;
}

const gPaths = source[i].paths;

for (const p in gPaths) {
insertFromNeighbor(mapping[g].paths, gPaths, p);
}
}

return resolved;
};

export const resolveGroups = (
sampleFields: StrictField[],
frameFields: StrictField[],
Expand All @@ -210,6 +251,10 @@ export const resolveGroups = (
? DEFAULT_VIDEO_GROUPS
: DEFAULT_IMAGE_GROUPS;

if (currentGroups.length && configGroups.length) {
groups = mergeGroups(groups, configGroups);
}

const expanded = configGroups.reduce((map, { name, expanded }) => {
map[name] = expanded;
return map;
Expand Down
4 changes: 3 additions & 1 deletion fiftyone/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def serialize(self, reflective=True):

if self.dataset is not None:
d["dataset"] = self.dataset.name
collection = self.dataset
collection = fo.Dataset(
self.dataset.name, _create=False, _force_load=True
)
if self.view is not None:
collection = self.view

Expand Down

0 comments on commit 4d554d6

Please sign in to comment.