Skip to content

Commit

Permalink
do not add valid list field filters to collapsed paths (#5280)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpkane authored Dec 17, 2024
1 parent a78dd41 commit 1ddd2bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
24 changes: 22 additions & 2 deletions app/packages/state/src/recoil/sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { describe, expect, it, vi } from "vitest";
vi.mock("recoil");
vi.mock("recoil-relay");

import { Field } from "@fiftyone/utilities";
import { setMockAtoms, TestSelector } from "../../../../__mocks__/recoil";
import { DICT_FIELD, Field, STRING_FIELD } from "@fiftyone/utilities";
import { TestSelector, setMockAtoms } from "../../../../__mocks__/recoil";
import * as sidebar from "./sidebar";

const mockFields = {
Expand Down Expand Up @@ -566,3 +566,23 @@ describe("hiddenNoneGroups selector", () => {
expect(testHiddenNoneGroups()).toStrictEqual(present);
});
});

describe("collapsedPaths resolution", () => {
it("does not add valid list fields (i.e. with a primitive subfield)", () => {
setMockAtoms({
field: (path) =>
path === "dict_list"
? { subfield: DICT_FIELD }
: { subfield: STRING_FIELD },
fieldPaths: ({ ftype }) =>
ftype === DICT_FIELD ? [] : ["dict_list", "string_list"],
fields: () => [],
});

const collapsed = <TestSelector<typeof sidebar.collapsedPaths>>(
(<unknown>sidebar.collapsedPaths)
);

expect(collapsed()).toStrictEqual(new Set(["dict_list"]));
});
});
12 changes: 9 additions & 3 deletions app/packages/state/src/recoil/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
LABELS_PATH,
LABEL_DOC_TYPES,
LIST_FIELD,
UNSUPPORTED_FILTER_TYPES,
VALID_LABEL_TYPES,
VALID_PRIMITIVE_TYPES,
withPath,
Expand Down Expand Up @@ -292,7 +293,6 @@ export const resolveGroups = (
"other",
fieldsMatcher(frameFields, () => true, present, "frames.")
);

return groups;
};

Expand Down Expand Up @@ -761,11 +761,16 @@ export const isDisabledFilterPath = selectorFamily<boolean, string>({
get(disabledFilterPaths).has(path),
});

const collapsedPaths = selector<Set<string>>({
export const collapsedPaths = selector<Set<string>>({
key: "collapsedPaths",
get: ({ get }) => {
let paths = [...get(fieldPaths({ ftype: DICT_FIELD }))];
paths = [...paths, ...get(fieldPaths({ ftype: LIST_FIELD }))];
paths = [
...paths,
...get(fieldPaths({ ftype: LIST_FIELD })).filter((path) =>
UNSUPPORTED_FILTER_TYPES.includes(get(field(path)).subfield)
),
];

for (const { fields: fieldsData, name: prefix } of get(
fields({ ftype: EMBEDDED_DOCUMENT_FIELD, space: State.SPACE.SAMPLE })
Expand Down Expand Up @@ -877,6 +882,7 @@ export const groupShown = selectorFamily<
if (["tags"].includes(group)) {
return null;
}

return (
!data.paths.length ||
!data.paths.every((path) => get(collapsedPaths).has(path))
Expand Down

0 comments on commit 1ddd2bf

Please sign in to comment.