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

fix issue with disabled schedule exec option #5219

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions app/packages/operators/src/ExecutionOptionItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useTheme } from "@fiftyone/components";

export default function ExecutionOptionItem({ label, tag, disabled }) {
ritch marked this conversation as resolved.
Show resolved Hide resolved
const theme = useTheme();
const tagEl = tag ? (
<span
style={{
fontSize: "11px",
color: disabled ? theme.text.secondary : theme.custom.primarySoft,
marginLeft: "5px",
}}
>
{tag}
</span>
) : null;
return (
<div style={{ display: "flex", alignItems: "center" }}>
{label}
{tagEl}
</div>
);
}
26 changes: 3 additions & 23 deletions app/packages/operators/src/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@mui/material";
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
import { onEnter } from "./utils";
import { useTheme } from "@fiftyone/components";
import ExecutionOptionItem from "./ExecutionOptionItem";

const ButtonStylesOverrides: ButtonProps["sx"] = {
color: (theme) => theme.palette.text.secondary,
Expand Down Expand Up @@ -63,6 +63,7 @@ export default function SplitButton({
};

const handleSelect = (option) => {
if (!option.onSelect) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed this bug while testing. Clicking on the Schedule button in the modal threw an error. This fixes it.

option.onSelect();
setOpen(false);
};
Expand Down Expand Up @@ -142,7 +143,7 @@ export default function SplitButton({
: theme.palette.text.disabled,
}}
primary={
<PrimaryWithTag
<ExecutionOptionItem
label={option.choiceLabel || option.label}
tag={option.tag}
disabled={option.disabled || !option.onClick}
Expand Down Expand Up @@ -171,24 +172,3 @@ export default function SplitButton({
</React.Fragment>
);
}

function PrimaryWithTag({ label, tag, disabled }) {
const theme = useTheme();
const tagEl = tag ? (
<span
style={{
fontSize: "11px",
color: disabled ? theme.text.secondary : theme.custom.primarySoft,
marginLeft: "5px",
}}
>
{tag}
</span>
) : null;
return (
<div style={{ display: "flex", alignItems: "center" }}>
{label}
{tagEl}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Menu, MenuItem, Stack, Typography } from "@mui/material";
import React from "react";
import { OperatorExecutionOption } from "../../state";
import ExecutionOptionItem from "../../ExecutionOptionItem";

/**
* Component which provides a context menu for executing an operator using a
Expand Down Expand Up @@ -28,24 +28,42 @@ export const OperatorExecutionMenu = ({
return (
<Menu anchorEl={anchor} open={open} onClose={onClose}>
{executionOptions.map((target) => (
<MenuItem
<Item
key={target.id}
onClick={() => {
onClose?.();
onOptionClick?.(target);
target.onClick();
}}
>
<Stack direction="column" spacing={1}>
<Typography fontWeight="bold">
{target.choiceLabel ?? target.label}
</Typography>
<Typography color="secondary">{target.description}</Typography>
</Stack>
</MenuItem>
target={target}
disabled={target.isDisabledSchedule || !target.onClick}
onClose={onClose}
onOptionClick={onOptionClick}
/>
))}
</Menu>
);
};

export default OperatorExecutionMenu;

function Item({ target, disabled, onClose, onOptionClick }) {
return (
<MenuItem
key={target.id}
onClick={() => {
if (disabled) return;
onClose?.();
onOptionClick?.(target);
target.onClick();
}}
sx={{ cursor: disabled ? "default" : "pointer" }}
>
<Stack direction="column" spacing={1}>
<Typography fontWeight="bold">
<ExecutionOptionItem
label={target.choiceLabel ?? target.label}
tag={target.tag}
disabled={disabled}
/>
</Typography>
<Typography color="secondary">{target.description}</Typography>
</Stack>
</MenuItem>
);
}
ritch marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions app/packages/operators/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export type OperatorExecutionOption = {
default?: boolean;
selected?: boolean;
onSelect?: () => void;
isDisabledSchedule?: boolean;
};

const useOperatorPromptSubmitOptions = (
Expand Down Expand Up @@ -346,6 +347,7 @@ const useOperatorPromptSubmitOptions = (
id: "disabled-schedule",
description: markdownDesc,
isDelegated: true,
isDisabledSchedule: true,
});
}

Expand Down
Loading