Skip to content

Commit

Permalink
Lightning filter fixes (#4757)
Browse files Browse the repository at this point in the history
* minor lightning fixes

* add test

* add note
  • Loading branch information
benjaminpkane authored Sep 11, 2024
1 parent ca1ff54 commit 94871b3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ const Checkboxes = ({
const show = useRecoilValue(showSearchSelector({ modal, path }));
const getCount = useGetCount(modal, path);

if (loading) {
// if results are null, and show is false, values are loading
if (loading || (!show && results === null)) {
return <LoadingDots text={"Loading"} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function (
const shown =
(resultsLoadable.state !== "loading" || lightning) &&
(showSearch || length > CHECKBOX_LIMIT);

return {
results,
useSearch: useRecoilValue(hasSearchResultsSelector(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const FILTERS = {
[fou.INT_FIELD]: filters.NumericFieldFilter,
[fou.OBJECT_ID_FIELD]: filters.StringFieldFilter,
[fou.STRING_FIELD]: filters.StringFieldFilter,
["_LABEL_TAGS"]: filters.LabelFieldFilter,
_LABEL_TAGS: filters.LabelFieldFilter,
};

const FilterItem = ({
Expand Down
25 changes: 25 additions & 0 deletions app/packages/state/src/recoil/lightning.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it, vi } from "vitest";

vi.mock("recoil");
vi.mock("recoil-relay");

import { TestSelectorFamily, setMockAtoms } from "../../../../__mocks__/recoil";
import * as lightning from "./lightning";

describe("tests lightning selectors", () => {
it("resolves wildcard indexed fields with database path", () => {
const test = <TestSelectorFamily<typeof lightning.lightningPaths>>(
(<unknown>lightning.lightningPaths("ground_truth"))
);
setMockAtoms({
dbPath: (p) =>
p === "ground_truth.id" ? "ground_truth._id" : "ground_truth.label",
expandPath: () => "ground_truth",
fieldPaths: () => ["id", "label"],
indexesByPath: new Set(["ground_truth._id", "ground_truth.label"]),
isLabelPath: () => true,
});

expect(test()).toEqual(new Set(["ground_truth.id", "ground_truth.label"]));
});
});
2 changes: 1 addition & 1 deletion app/packages/state/src/recoil/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const lightningPaths = selectorFamily<Set<string>, string>({
})
)
.map((p) => `${expanded}.${p}`)
.filter((p) => indexes.has(p))
.filter((p) => indexes.has(get(schemaAtoms.dbPath(p))))
);
}

Expand Down

0 comments on commit 94871b3

Please sign in to comment.