Skip to content

Commit

Permalink
Merge branch 'develop' into feat/fo-assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
Br2850 committed Oct 22, 2024
2 parents 0ed6ab3 + adf51c9 commit 18ee976
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
32 changes: 23 additions & 9 deletions app/packages/components/src/components/Toast/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import React, { useState } from "react";
import { Snackbar, Button, SnackbarContent } from "@mui/material";
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import BoltIcon from '@mui/icons-material/Bolt'; // Icon for the lightning bolt
import React from "react";
import { atom, useRecoilState } from "recoil";
import { Box, Snackbar, SnackbarContent } from "@mui/material";

// Define types for the props
interface ToastProps {
action: React.ReactNode; // Accepts any valid React component, element, or JSX
message: React.ReactNode; // Accepts any valid React component, element, or JSX
message: React.ReactNode;
primary: (setOpen: React.Dispatch<React.SetStateAction<boolean>>) => React.ReactNode;
secondary: (setOpen: React.Dispatch<React.SetStateAction<boolean>>) => React.ReactNode;
duration?: number; // Optional duration, with a default value
}

const Toast: React.FC<ToastProps> = ({ action, message, duration = 5000 }) => {
const [open, setOpen] = useState(true);
const toastStateAtom = atom({
key: "toastOpenState",
default: true,
});

const Toast: React.FC<ToastProps> = ({message, primary, secondary, duration = 5000 }) => {

const [open, setOpen] = useRecoilState(toastStateAtom); // State management for toast visibility

const handleClose = (event, reason) => {
if (reason === "clickaway") {
Expand All @@ -21,6 +26,15 @@ const Toast: React.FC<ToastProps> = ({ action, message, duration = 5000 }) => {
setOpen(false);
};

const action = (
<div>
<Box display="flex" justifyContent="flex-end">
{primary(setOpen)} {/* Pass setOpen to primary button */}
{secondary(setOpen)} {/* Pass setOpen to secondary button */}
</Box>
</div>
);

return (
<Snackbar
anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
Expand Down
2 changes: 1 addition & 1 deletion app/packages/components/src/components/Toast/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {default as Toast} from "./Toast";
export { default } from "./Toast";
2 changes: 1 addition & 1 deletion app/packages/components/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ export { default as TabOption } from "./TabOption";
export { default as TextField } from "./TextField";
export { default as ThemeProvider, useFont, useTheme } from "./ThemeProvider";
export { default as Tooltip } from "./Tooltip";
export { Toast } from "./Toast";
export { default as Toast } from "./Toast";

export * from "./types";
2 changes: 1 addition & 1 deletion docs/source/plugins/developing_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,7 @@ The example code below shows how to access and update panel state.
def decrement(self, ctx):
count = ctx.panel.get_state("v_stack.h_stack.count", 0)
ctx.panel.set_state("v_stack.h_stack.count", count + 1)
ctx.panel.set_state("v_stack.h_stack.count", count - 1)
def render(self, ctx):
panel = types.Object()
Expand Down
19 changes: 14 additions & 5 deletions fiftyone/factory/repos/delegated_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def update_run_state(
else None
)

needs_pipeline_update = False

if run_state == ExecutionRunState.COMPLETED:
update = {
"$set": {
Expand All @@ -272,10 +274,11 @@ def update_run_state(
}
}

if outputs_schema:
update["$set"]["metadata.outputs_schema"] = {
"$ifNull": [outputs_schema, {}]
}
if outputs_schema:
update["$set"]["metadata.outputs_schema"] = (
outputs_schema or {}
)
needs_pipeline_update = True

elif run_state == ExecutionRunState.FAILED:
update = {
Expand Down Expand Up @@ -325,9 +328,15 @@ def update_run_state(
if required_state is not None:
collection_filter["run_state"] = required_state

# Using pipeline update instead of a single update doc fixes a case
# where `metadata` is null and so accessing the dotted field
# `metadata.output_schema` creates the document instead of erroring.
if needs_pipeline_update:
update = [update]

doc = self._collection.find_one_and_update(
filter=collection_filter,
update=[update],
update=update,
return_document=pymongo.ReturnDocument.AFTER,
)

Expand Down
30 changes: 30 additions & 0 deletions tests/unittests/operators/delegated_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from unittest import mock
from unittest.mock import patch

import bson
import pytest

import fiftyone
Expand Down Expand Up @@ -484,6 +485,35 @@ def test_sets_progress(
self.assertEqual(doc.status.label, "halfway there")
self.assertIsNotNone(doc.status.updated_at)

def test_output_schema_null_metadata(
self, mock_get_operator, mock_operator_exists
):
mock_outputs = MockOutputs()
doc = self.svc.queue_operation(
operator="@voxelfiftyone/operator/foo",
delegation_target="test_target",
context=ExecutionContext(request_params={"foo": "bar"}),
)

# Set metadata to null instead of being unset, to test that corner case
self.svc._repo._collection.find_one_and_update(
{"_id": bson.ObjectId(doc.id)}, {"$set": {"metadata": None}}
)

self.svc.set_completed(
doc.id,
result=ExecutionResult(outputs_schema=mock_outputs.to_json()),
)

doc = self.svc.get(doc_id=doc.id)
self.assertEqual(doc.run_state, ExecutionRunState.COMPLETED)
self.assertEqual(
doc.metadata,
{
"outputs_schema": mock_outputs.to_json(),
},
)

@patch(
"fiftyone.core.odm.utils.load_dataset",
)
Expand Down

0 comments on commit 18ee976

Please sign in to comment.