Skip to content

Commit

Permalink
Maintain active dataset fields (#1878)
Browse files Browse the repository at this point in the history
* reset active field only on dataset change

* rm log

* address feedback, fix patches
  • Loading branch information
benjaminpkane authored Jun 20, 2022
1 parent d782744 commit 9406199
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 2 additions & 4 deletions app/packages/app/src/Root/Datasets/Dataset.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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 { 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: BSONArray) {
Expand Down Expand Up @@ -99,7 +98,6 @@ export const Dataset: Route<DatasetQuery> = ({ prepared }) => {
useEffect(() => {
update(({ reset }) => {
reset(filters);
reset(_activeFields({ modal: false }));
reset(similarityParameters);

return {
Expand Down
12 changes: 9 additions & 3 deletions app/packages/app/src/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { getDatasetName } from "./generic";
import { RouterContext } from "@fiftyone/components";
import { RGB } from "@fiftyone/looker";
import { DatasetQuery } from "../Root/Datasets/__generated__/DatasetQuery.graphql";
import { _activeFields } from "../recoil/schema";

export const useEventHandler = (
target,
Expand Down Expand Up @@ -310,7 +311,7 @@ export const useStateUpdate = () => {
const { colorscale, config, dataset, state } =
resolve instanceof Function ? resolve(t) : resolve;

const { get, set } = t;
const { get, reset, set } = t;

if (state) {
const view = get(viewAtoms.view);
Expand Down Expand Up @@ -351,16 +352,21 @@ export const useStateUpdate = () => {
dataset.evaluations = Object.values(dataset.evaluations || {});

const groups = resolveGroups(dataset);
const current = get(sidebarGroupsDefinition(false));
const currentSidebar = get(sidebarGroupsDefinition(false));

if (JSON.stringify(groups) !== JSON.stringify(current)) {
if (JSON.stringify(groups) !== JSON.stringify(currentSidebar)) {
set(sidebarGroupsDefinition(false), groups);
set(
aggregationAtoms.aggregationsTick,
get(aggregationAtoms.aggregationsTick) + 1
);
}

const previousDataset = get(atoms.dataset);
if (!previousDataset || previousDataset.id !== dataset.id) {
reset(_activeFields({ modal: false }));
}

set(atoms.dataset, dataset);
}

Expand Down
6 changes: 2 additions & 4 deletions fiftyone/server/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ async def resolver(
view = fov.DatasetView._build(ds, view or [])
if view._dataset != ds:
d = view._dataset._serialize()
dataset.id = (
ObjectId()
) # if it is not the root dataset, change the id (relay requires it)
dataset.id = view._dataset._doc.id
dataset.media_type = d["media_type"]
dataset.sample_fields = [
from_dict(SampleField, s)
Expand Down Expand Up @@ -285,7 +283,7 @@ def serialize_dataset(dataset: fod.Dataset, view: fov.DatasetView) -> t.Dict:
if view is not None and view._dataset != dataset:
d = view._dataset._serialize()
data.media_type = d["media_type"]
data.id = ObjectId()
data.id = view._dataset._doc.id
data.sample_fields = [
from_dict(SampleField, s)
for s in _flatten_fields([], d["sample_fields"])
Expand Down

0 comments on commit 9406199

Please sign in to comment.