Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpkane committed Nov 25, 2024
1 parent d058feb commit a0901ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/packages/state/src/recoil/sidebar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
unsupportedMatcher,
} from "../utils";
import * as viewAtoms from "../view";
import { mergeGroups } from "./sidebar-utils";

export enum EntryKind {
EMPTY = "EMPTY",
Expand Down
6 changes: 5 additions & 1 deletion app/packages/state/src/recoil/sidebar/sidebar-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { describe, expect, it, vi } from "vitest";
vi.mock("recoil");
vi.mock("recoil-relay");

import { mergeGroups } from "./sidebar-utils";
import { merge, mergeGroups } from "./sidebar-utils";

describe("test sidebar groups resolution", () => {
it("test list merge", () => {
expect(merge([], ["one", "two"])).toStrictEqual(["one", "two"]);
});

it("merges current and config groups", () => {
expect(
mergeGroups(
Expand Down
13 changes: 10 additions & 3 deletions app/packages/state/src/recoil/sidebar/sidebar-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ const insertFromNeighbor = (sink: string[], source: string[], key: string) => {
return;
};

const merge = (sink: string[], source: string[]) => {
export const merge = (sink: string[], source: string[]) => {
const missing = new Set(source.filter((key) => !sink.includes(key)));

while (missing.size) {
const force = ![...missing].some((name) => hasNeighbor(sink, source, name));
const force = [...missing].every(
(name) => !hasNeighbor(sink, source, name)
);
for (const name of missing) {
if (!force && !hasNeighbor(sink, source, name)) {
continue;
}

insertFromNeighbor(sink, source, name);

missing.delete(name);
}
}

return sink;
};

export const mergeGroups = (
Expand All @@ -70,7 +76,8 @@ export const mergeGroups = (
continue;
}

merge(mapping[name].paths || [], source[i].paths);
mapping[name].paths = mapping[name].paths ?? [];
merge(mapping[name].paths, source[i].paths);
}

return resolved;
Expand Down

0 comments on commit a0901ce

Please sign in to comment.