Skip to content

Commit

Permalink
operator views enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
imanjra committed Jul 18, 2024
1 parent 0c85106 commit 5726176
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ import { getComponentProps } from "../utils";

export default function ImageView(props) {
const { schema, data } = props;
const { height, width, alt } = schema?.view || {};
const imageURI = data ?? schema?.default;

return (
<Box {...getComponentProps(props, "container")}>
<HeaderView {...props} nested />
<img src={imageURI} {...getComponentProps(props, "image")} />
<img
src={imageURI}
height={height}
width={width}
alt={alt}
{...getComponentProps(props, "image")}
/>
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { generateSchema } from "../utils";
import DynamicIO from "./DynamicIO";

export default function InferredView(props) {
const { schema = {} } = props;
const { data, schema = {} } = props;
const { view = {}, default: defaultValue, readOnly } = schema;
const generatedSchema = generateSchema(defaultValue, {
const value = data ?? defaultValue;
const generatedSchema = generateSchema(value, {
label: view.label,
readOnly: readOnly || view.readOnly,
});
const schemaWithDefault = { ...generatedSchema, default: defaultValue };
const schemaWithDefault = { ...generatedSchema, default: value };
return <DynamicIO {...props} schema={schemaWithDefault} />;
}
25 changes: 20 additions & 5 deletions app/packages/core/src/plugins/SchemaIO/components/LinkView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@ import { getComponentProps } from "../utils";

export default function LinkView(props) {
const { schema, data = {} } = props;
const { view = {} } = schema;
const { label: viewLabel, href: viewHref } = view;
const { label, href } = data;
const { view = {}, default: defaultValue } = schema;
const { new_window, newWindow } = view;
let { label, href } = view;
const value = data ?? defaultValue;
if (typeof value === "string") {
href = value;
} else {
if (value?.href) {
href = value.href;
}
if (value?.label) {
label = value.label;
}
}
return (
<Box {...getComponentProps(props, "container")}>
<Link href={href || viewHref} {...getComponentProps(props, "link")}>
{label || viewLabel}
<Link
href={href}
target={new_window || newWindow ? "_blank" : undefined}
{...getComponentProps(props, "link")}
>
{label}
</Link>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { getComponentProps } from "../utils";

export default function MediaPlayerView(props) {
const { schema, data } = props;
const { default: defaultValue, playerProps = {} } = schema;
const actualData = data ?? defaultValue;
const mediaUrl = actualData?.url;
const { default: defaultValue } = schema;
const value = data ?? defaultValue;
const mediaUrl = typeof value === "string" ? value : value?.url;
const { view = {} } = schema;

const handleEvent =
(event) =>
Expand All @@ -32,7 +33,7 @@ export default function MediaPlayerView(props) {
<HeaderView {...props} nested />
<ReactPlayer
url={mediaUrl}
{...playerProps}
{...view}
{...eventHandlers}
{...getComponentProps(props, "react-player")}
/>
Expand Down
48 changes: 48 additions & 0 deletions fiftyone/operators/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,54 @@ def arrow_nav(
)
return self.view(name, view, **kwargs)

def map(self, name, key_type, value_type, **kwargs):
"""Defines a map property on the object.
Args:
name: the name of the property
key_type: the type of the keys in the map
value_type: the type of the values in the map
Returns:
a :class:`Map`
"""
map_view = MapView(**kwargs)
map_type = Map(key_type=key_type, value_type=value_type)
self.define_property(name, map_type, view=map_view, **kwargs)
return map_type

def oneof(self, name, types, **kwargs):
"""Defines a one-of property on the object.
Args:
name: the name of the property
types: list of types that are instances of :class:`BaseType`
Returns:
a :class:`OneOf`
"""

one_of = OneOf(types)
self.define_property(name, one_of, **kwargs)
return one_of

def tuple(self, name, *items, **kwargs):
"""Defines a tuple property on the object.
Args:
name: the name of the property
*items: the types of the items in the tuple
Returns:
a :class:`Tuple`
"""
tuple_view = TupleView(**kwargs)
tuple_type = Tuple(*items)
self.define_property(name, tuple_type, view=tuple_view, **kwargs)
return tuple_type

def clone(self):
"""Clones the definition of the object.
Expand Down

0 comments on commit 5726176

Please sign in to comment.