Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
align-items: center;
height: var(--header-height);
box-sizing: border-box;
border-bottom: 1px solid;
border-bottom: 1px solid #ddd;
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

This CSS color change is unrelated to the PR's purpose of disabling the button based on parameter changes. This change should be removed or submitted in a separate PR.

Suggested change
border-bottom: 1px solid #ddd;

Copilot uses AI. Check for mistakes.
}

.sider {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface DropdownProps {
const Dropdown = (props: DropdownProps): JSX.Element => {
const { placeholder, options, onChange, defaultValue } = props;
const selectOptions = map(options, (opt, key) => ({
label: opt.name || key,
value: opt.recipe,
label: opt.displayName || key,
value: opt.recipeId,
}));

return (
Expand Down
16 changes: 5 additions & 11 deletions src/components/GradientInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { Select, Slider } from "antd";
import { GradientOption } from "../../types";
import {
useSelectedRecipeId,
useUpdateRecipeObj,
useGetCurrentValue,
useCurrentRecipeString,
useEditRecipe,
} from "../../state/store";
import { getSelectedGradient, deriveGradientStrength, round2 } from "../../utils/gradient";
import "./style.css";
Expand All @@ -19,10 +18,8 @@ interface GradientInputProps {
const GradientInput = (props: GradientInputProps): JSX.Element => {
const { displayName, description, gradientOptions, defaultValue } = props;
const selectedRecipeId = useSelectedRecipeId();
const updateRecipeObj = useUpdateRecipeObj();
const editRecipe = useEditRecipe();
const getCurrentValue = useGetCurrentValue();
// Force re-render after restore/navigation
useCurrentRecipeString();

const { currentGradient, selectedOption } = getSelectedGradient(
gradientOptions,
Expand All @@ -36,19 +33,16 @@ const GradientInput = (props: GradientInputProps): JSX.Element => {
if (!selectedRecipeId) return;
const selectedOption = gradientOptions.find(option => option.value === value);
if (!selectedOption || !selectedOption.path) return;

// Make changes to JSON recipe
const changes: Record<string, string | number> = {[selectedOption.path]: value};
if (selectedOption.packing_mode && selectedOption.packing_mode_path) {
changes[selectedOption.packing_mode_path] = selectedOption.packing_mode;
editRecipe(selectedRecipeId, selectedOption.packing_mode_path, selectedOption.packing_mode);
}
updateRecipeObj(selectedRecipeId, changes);
editRecipe(selectedRecipeId, selectedOption.path, value);
};

const handleStrengthChange = (val: number | null) => {
if (val == null || !selectedRecipeId || !gradientStrengthData) return;
const uiVal = round2(val);
updateRecipeObj(selectedRecipeId, { [gradientStrengthData.path]: uiVal });
editRecipe(selectedRecipeId, gradientStrengthData.path, uiVal);
};

const selectOptions = gradientOptions.map((option) => ({
Expand Down
12 changes: 6 additions & 6 deletions src/components/InputSwitch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Input, InputNumber, Select, Slider } from "antd";
import { GradientOption } from "../../types";
import {
useSelectedRecipeId,
useUpdateRecipeObj,
useGetCurrentValue,
useCurrentRecipeString,
useEditRecipe,
useRecipes,
} from "../../state/store";
import GradientInput from "../GradientInput";
import "./style.css";
Expand All @@ -28,9 +28,9 @@ const InputSwitch = (props: InputSwitchProps): JSX.Element => {
const { displayName, inputType, dataType, description, min, max, options, id, gradientOptions, conversionFactor, unit } = props;

const selectedRecipeId = useSelectedRecipeId();
const updateRecipeObj = useUpdateRecipeObj();
const editRecipe = useEditRecipe();
const getCurrentValue = useGetCurrentValue();
const recipeVersion = useCurrentRecipeString();
const recipes = useRecipes();

// Conversion factor for numeric inputs where we want to display a
// different unit in the UI than is stored in the recipe
Expand Down Expand Up @@ -59,7 +59,7 @@ const InputSwitch = (props: InputSwitchProps): JSX.Element => {
// Reset local state when store value (or recipe) changes
useEffect(() => {
setValue(getCurrentValueMemo());
}, [getCurrentValueMemo, recipeVersion]);
}, [getCurrentValueMemo, recipes]);

const handleInputChange = (value: string | number | null) => {
if (value == null || !selectedRecipeId) return;
Expand All @@ -68,7 +68,7 @@ const InputSwitch = (props: InputSwitchProps): JSX.Element => {
// Convert back to original units for updating recipe object
value = value / conversion;
}
updateRecipeObj(selectedRecipeId, { [id]: value });
editRecipe(selectedRecipeId, id, value);
};

switch (inputType) {
Expand Down
9 changes: 3 additions & 6 deletions src/components/JSONViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import {
returnOneElement,
} from "./formattingUtils";
import "./style.css";
import { ViewableRecipe } from "../../types";

interface JSONViewerProps {
title: string;
content: string;
isEditable: boolean;
onChange: (value: string) => void;
content?: ViewableRecipe;
}

const JSONViewer = (props: JSONViewerProps): JSX.Element | null => {
Expand All @@ -22,8 +21,6 @@ const JSONViewer = (props: JSONViewerProps): JSX.Element | null => {
return null;
}

const contentAsObj = JSON.parse(content);

// descriptions for top level key-value pairs
const descriptions: DescriptionsItemProps[] = [];
// trees for nested objects like 'objects', 'composition', 'gradients'
Expand All @@ -44,7 +41,7 @@ const JSONViewer = (props: JSONViewerProps): JSX.Element | null => {
};

// top level objects, like name, bounding_box, etc.
Object.entries(contentAsObj).forEach(([key, value]) => {
Object.entries(content).forEach(([key, value]) => {
if (typeof value === "string") {
descriptions.push({
label: convertUnderscoreToSpace(key),
Expand Down
22 changes: 5 additions & 17 deletions src/components/PackingInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { Tabs } from "antd";

import {
useSelectedRecipeId,
useCurrentRecipeString,
useFieldsToDisplay,
useInputOptions,
useIsLoading,
useLoadInputOptions,
useSelectRecipe,
useUpdateRecipeString,
useStartPacking,
useLoadAllRecipes,
useCurrentRecipeObject,
useInputOptions,
useLoadInputOptions,
} from "../../state/store";
import Dropdown from "../Dropdown";
import JSONViewer from "../JSONViewer";
Expand All @@ -29,15 +27,13 @@ interface PackingInputProps {
const PackingInput = (props: PackingInputProps): JSX.Element => {
const { startPacking } = props;
const selectedRecipeId = useSelectedRecipeId();
const recipeString = useCurrentRecipeString();
const fieldsToDisplay = useFieldsToDisplay();
const recipeObj = useCurrentRecipeObject();
const inputOptions = useInputOptions();
const isLoading = useIsLoading();

const loadInputOptions = useLoadInputOptions();
const loadAllRecipes = useLoadAllRecipes();
const selectRecipe = useSelectRecipe();
const updateRecipeString = useUpdateRecipeString();
const storeStartPacking = useStartPacking();

const preFetchInputsAndRecipes = useCallback(async () => {
Expand All @@ -54,12 +50,6 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
await storeStartPacking(startPacking);
};

const handleRecipeStringChange = (newString: string) => {
if (selectedRecipeId) {
updateRecipeString(selectedRecipeId, newString);
}
};

if (isLoading) {
return <div>Loading...</div>;
}
Expand All @@ -82,9 +72,7 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
<Tabs.TabPane tab="Full Recipe" key="2">
<JSONViewer
title="Recipe"
content={recipeString}
isEditable={fieldsToDisplay === undefined}
onChange={handleRecipeStringChange}
content={recipeObj}
/>
</Tabs.TabPane>
</Tabs>
Expand Down
26 changes: 17 additions & 9 deletions src/components/RecipeForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Button } from "antd";
import { Button, Tooltip } from "antd";
import InputSwitch from "../InputSwitch";
import "./style.css";
import {
useSelectedRecipeId,
useFieldsToDisplay,
useIsPacking,
useIsOriginalRecipe,
} from "../../state/store";

interface RecipeFormProps {
Expand All @@ -15,6 +16,7 @@ const RecipeForm = ({ onStartPacking }: RecipeFormProps) => {
const recipeId = useSelectedRecipeId();
const fieldsToDisplay = useFieldsToDisplay();
const isPacking = useIsPacking();
const isOriginalRecipe = useIsOriginalRecipe();

return (
<div className="recipe-form">
Expand All @@ -39,15 +41,21 @@ const RecipeForm = ({ onStartPacking }: RecipeFormProps) => {
</div>
)}
{recipeId && (
<Button
onClick={onStartPacking}
color="primary"
variant="filled"
disabled={isPacking}
style={{ width: "100%" }}
<Tooltip
title={
isOriginalRecipe ? "Adjust any parameter to re-run" : ""
}
>
Re-run
</Button>
<Button
onClick={onStartPacking}
color="primary"
variant="filled"
disabled={isPacking || isOriginalRecipe}
style={{ width: "100%" }}
>
<strong>Re-run</strong>
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The button text change from 'Re-run' to 'Re-run' is unrelated to the PR's purpose of disabling the button when parameters haven't changed. This styling change should be removed or submitted in a separate PR focused on UI improvements.

Suggested change
<strong>Re-run</strong>
Re-run

Copilot uses AI. Check for mistakes.
</Button>
</Tooltip>
)}
</div>
);
Expand Down
Loading