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

Retain browser setting for modal dynamic groups #5149

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions app/packages/state/src/hooks/useSetModalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { CallbackInterface, RecoilState } from "recoil";

import { useRelayEnvironment } from "react-relay";
import { useRecoilCallback } from "recoil";
import { dynamicGroupsViewMode } from "../recoil";
import * as atoms from "../recoil/atoms";
import * as filterAtoms from "../recoil/filters";
import * as groupAtoms from "../recoil/groups";
Expand Down Expand Up @@ -45,8 +44,6 @@ export default () => {
];
}),

[dynamicGroupsViewMode(true), dynamicGroupsViewMode(false)],

[atoms.cropToContent(true), atoms.cropToContent(false)],
[atoms.sortFilterResults(true), atoms.sortFilterResults(false)],
[groupAtoms.groupStatistics(true), groupAtoms.groupStatistics(false)],
Expand Down
36 changes: 31 additions & 5 deletions app/packages/state/src/recoil/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
mediaFieldsFragment,
mediaFieldsFragment$key,
} from "@fiftyone/relay";
import { atomFamily, selector, selectorFamily } from "recoil";
import { DefaultValue, atomFamily, selector, selectorFamily } from "recoil";
import { getBrowserStorageEffectForKey } from "./customEffects";
import { datasetSampleCount } from "./dataset";
import { fieldPaths } from "./schema";
Expand Down Expand Up @@ -55,17 +55,43 @@ export const selectedMediaField = selectorFamily<string, boolean>({
set(selectedMediaFieldAtomFamily(modal), value),
});

export const dynamicGroupsViewMode = atomFamily<
"carousel" | "pagination" | "video",
export const dynamicGroupsViewModeStore = atomFamily<
"carousel" | "pagination" | "video" | null,
boolean
>({
key: "dynamicGroupsViewMode",
default: "pagination",
key: "dynamicGroupsViewModeStore",
default: null,
effects: (modal) => [
getBrowserStorageEffectForKey(`dynamicGroupsViewMode-${modal}`),
],
});

export const dynamicGroupsViewMode = selectorFamily({
key: "dynamicGroupsViewModeStore",
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 20, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix potential key conflict in selector definition

The selector is using the same key as the atomFamily ("dynamicGroupsViewModeStore"), which could cause state management issues.

-  key: "dynamicGroupsViewModeStore",
+  key: "dynamicGroupsViewMode",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
key: "dynamicGroupsViewModeStore",
key: "dynamicGroupsViewMode",

Copy link
Contributor

Choose a reason for hiding this comment

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

🐰 is right, there's a key conflict

Copy link
Contributor

Choose a reason for hiding this comment

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

@sashankaryal, glad you agree. Updating the selector's key to "dynamicGroupsViewMode" will resolve the conflict:

key: "dynamicGroupsViewMode",

Let me know if you need any further assistance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ope

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

get:
(modal: boolean) =>
({ get }) => {
const value = get(dynamicGroupsViewModeStore(modal));

if (!value) {
return modal
? get(dynamicGroupsViewModeStore(false)) ?? "pagination"
: "pagination";
}

return value;
},
set:
(modal: boolean) =>
({ reset, set }, newValue) => {
const instance = dynamicGroupsViewModeStore(modal);

newValue instanceof DefaultValue
? reset(instance)
: set(instance, newValue);
},
});

export const isLargeVideo = selector<boolean>({
key: "isLargeVideo",
get: ({ get }) => {
Expand Down
Loading