Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic group player for group datasets #4479

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/packages/state/src/hooks/useCreateLooker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ export default <T extends AbstractLooker<BaseState>>(
);
const page = snapshot
.getLoadable(
dynamicGroupAtoms.dynamicGroupPageSelector(
groupByFieldValueTransformed
)
dynamicGroupAtoms.dynamicGroupPageSelector({
value: groupByFieldValueTransformed,
modal: isModal,
})
)
.valueMaybe();

Expand Down Expand Up @@ -257,6 +258,7 @@ export default <T extends AbstractLooker<BaseState>>(
highlight,
isClip,
isFrame,
isModal,
shouldRenderImaVidLooker,
isPatch,
mediaField,
Expand Down
35 changes: 33 additions & 2 deletions app/packages/state/src/recoil/dynamicGroups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { describe, expect, it, vi } from "vitest";
vi.mock("recoil");
vi.mock("recoil-relay");

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

describe("handles non-nested dynamic groups", () => {
describe("handles dynamic groups", () => {
const testNesting = <
TestSelector<typeof dynamicGroups.isNonNestedDynamicGroup>
>(<unknown>dynamicGroups.isNonNestedDynamicGroup);
Expand All @@ -25,4 +29,31 @@ describe("handles non-nested dynamic groups", () => {
});
expect(testNesting()).toBe(false);
});

const modalPageSelector = <
TestSelectorFamily<typeof dynamicGroups.dynamicGroupPageSelector>
>(<unknown>(
dynamicGroups.dynamicGroupPageSelector({ value: "test", modal: true })
));
const pageSelector = <
TestSelectorFamily<typeof dynamicGroups.dynamicGroupPageSelector>
>(<unknown>(
dynamicGroups.dynamicGroupPageSelector({ value: "test", modal: false })
));

it("uses correct slice", () => {
setMockAtoms({
datasetName: "dataset",
dynamicGroupViewQuery: () => [],
groupSlice: "main",
modalGroupSlice: "modal",
});

expect(pageSelector()(0, 1).filter).toStrictEqual({
group: { slice: "main" },
});
expect(modalPageSelector()(0, 1).filter).toStrictEqual({
group: { slice: "modal" },
});
});
});
15 changes: 10 additions & 5 deletions app/packages/state/src/recoil/dynamicGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
LIST_FIELD,
} from "@fiftyone/utilities";
import { atom, atomFamily, selector, selectorFamily } from "recoil";
import { currentSlice, hasGroupSlices } from "./groups";
import {
currentSlice,
groupSlice,
hasGroupSlices,
modalGroupSlice,
} from "./groups";
import { modalLooker } from "./modal";
import { dynamicGroupsViewMode } from "./options";
import { fieldPaths } from "./schema";
Expand Down Expand Up @@ -70,25 +75,25 @@ export const dynamicGroupPageSelector = selectorFamily<
after: string | null;
count: number;
dataset: string;
filter: Record<string, never>;
filter: { group: { slice?: string } };
view: State.Stage[];
},
string
{ modal: boolean; value: string }
>({
key: "paginateDynamicGroupVariables",
get:
(value) =>
({ modal, value }) =>
({ get }) => {
const params = {
dataset: get(datasetName),
view: get(dynamicGroupViewQuery(value)),
filter: { group: { slice: get(modal ? modalGroupSlice : groupSlice) } },
Comment on lines +78 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored dynamicGroupPageSelector to handle modal contexts.

The refactoring of dynamicGroupPageSelector to include a modal context is a significant improvement. Consider adding more detailed comments explaining the logic, especially how the modal flag affects the slice selection, to aid future maintainability.

};

return (cursor: number, pageSize: number) => ({
...params,
after: cursor ? String(cursor) : null,
count: pageSize,
filter: {},
});
},
});
Expand Down
Loading