Repository: voxel51/fiftyone
Pull request: Maintain active dataset fields
Resolves #1852 

Problem statement:
[BUG] Changing session.view resets field visibility choices
On `fiftyone==0.16.2`, updating `session.view` resets any field visibility toggles I may have set (eg, unselected all label fields), and forces the defaults (all label fields visible). I don't think this used to be the case though?

This came up when I was trying to work with an interactive plot. I just wanted to see images with no labels, but every time I made a selection in the linked plot, the labels kept re-appearing, which was annoying. I don't recall facing this issue before.

Of course persisting sidebar settings is a bit tricky because views can change the label schema.

Hints from issue discussion:

Commit message: reset active field only on dataset change

Patch to review:
diff --git a/app/packages/app/src/Root/Datasets/Dataset.tsx b/app/packages/app/src/Root/Datasets/Dataset.tsx
index cce7f8843d3..a0f86b00407 100644
--- a/app/packages/app/src/Root/Datasets/Dataset.tsx
+++ b/app/packages/app/src/Root/Datasets/Dataset.tsx
@@ -1,18 +1,19 @@
 import { Route, RouterContext } from "@fiftyone/components";
+import { toCamelCase } from "@fiftyone/utilities";
 import React, { useContext, useEffect } from "react";
 import { graphql, usePreloadedQuery } from "react-relay";
+import { useRecoilValue } from "recoil";
 
 import DatasetComponent from "../../components/Dataset";
 import { useStateUpdate } from "../../utils/hooks";
 import { DatasetQuery } from "./__generated__/DatasetQuery.graphql";
 import { datasetName } from "../../recoil/selectors";
-import { useRecoilValue } from "recoil";
 import transformDataset from "./transformDataset";
+import * as atoms from "../../recoil/atoms";
 import { filters } from "../../recoil/filters";
 import { _activeFields } from "../../recoil/schema";
 import { State } from "../../recoil/types";
 import { similarityParameters } from "../../components/Actions/Similar";
-import { toCamelCase } from "@fiftyone/utilities";
 
 const Query = graphql`
   query DatasetQuery($name: String!, $view: JSONArray) {
@@ -97,17 +98,24 @@ export const Dataset: Route<DatasetQuery> = ({ prepared }) => {
   const update = useStateUpdate();
 
   useEffect(() => {
-    update(({ reset }) => {
+    update(({ reset, get }) => {
       reset(filters);
-      reset(_activeFields({ modal: false }));
       reset(similarityParameters);
 
+      const newDataset = transformDataset(dataset);
+
+      const oldDataset = get(atoms.dataset);
+      oldDataset && console.log(oldDataset.id, newDataset.id);
+      if (!oldDataset || oldDataset.id !== newDataset.id) {
+        reset(_activeFields({ modal: false }));
+      }
+
       return {
         colorscale: router.state.colorscale,
         config: router.state.config
           ? (toCamelCase(router.state.config) as State.Config)
           : undefined,
-        dataset: transformDataset(dataset),
+        dataset: newDataset,
         state: router.state.state,
       };
     });


Code review comments:
diff_hunk: @@ -97,17 +98,24 @@ export const Dataset: Route<DatasetQuery> = ({ prepared }) => {
   const update = useStateUpdate();
 
   useEffect(() => {
-    update(({ reset }) => {
+    update(({ reset, get }) => {
       reset(filters);
-      reset(_activeFields({ modal: false }));
       reset(similarityParameters);
 
+      const newDataset = transformDataset(dataset);
+
+      const oldDataset = get(atoms.dataset);
+      oldDataset && console.log(oldDataset.id, newDataset.id);
+      if (!oldDataset || oldDataset.id !== newDataset.id) {
+        reset(_activeFields({ modal: false }));
path: app/packages/app/src/Root/Datasets/Dataset.tsx
text: @user1:
Is there a reason this isn't in `useStateUpdate()`? Looks like there are similar things there.

@author:
Good point, fixed

diff_hunk: @@ -97,17 +98,24 @@ export const Dataset: Route<DatasetQuery> = ({ prepared }) => {
   const update = useStateUpdate();
 
   useEffect(() => {
-    update(({ reset }) => {
+    update(({ reset, get }) => {
       reset(filters);
-      reset(_activeFields({ modal: false }));
       reset(similarityParameters);
 
+      const newDataset = transformDataset(dataset);
+
+      const oldDataset = get(atoms.dataset);
+      oldDataset && console.log(oldDataset.id, newDataset.id);
path: app/packages/app/src/Root/Datasets/Dataset.tsx
text: @user1:
Stray console.log?

@author:
Yes, thanks