Skip to content
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
6 changes: 1 addition & 5 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
}

.sider {
height: calc(
100vh - var(--header-height) - var(--footer-height)
); /* full height minus header and footer */
overflow-x: hidden;
overflow-y: auto;
overflow: hidden;
padding: 0 40px;
}

Expand Down
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { Link } = Typography;

function App() {
const [jobStatus, setJobStatus] = useState<string>("");

const setJobLogs = useSetJobLogs();
const jobLogs = useJobLogs();
const setJobId = useSetJobId();
Expand Down
37 changes: 0 additions & 37 deletions src/components/ExpandableDescription/index.tsx

This file was deleted.

61 changes: 61 additions & 0 deletions src/components/ExpandableText/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Typography } from "antd";
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 renamed this folder so the component name matched the file name

import { ArrowDownOutlined, ArrowUpOutlined } from "@ant-design/icons";
import { useEffect, useLayoutEffect, useRef, useState } from "react";
import {
DEFAULT_DESCRIPTION_HEIGHT,
TEXT_BOTTOM_MARGIN,
} from "../../constants";

import "./style.css";
const { Paragraph } = Typography;

interface ExpandableTextProps {
text: string;
setCurrentHeight: (height: number) => void;
}

const expandSymbol = (
<span>
expand <ArrowDownOutlined />
</span>
);

const collapseSymbol = (
<span>
collapse <ArrowUpOutlined />
</span>
);

const ExpandableText = ({ text, setCurrentHeight }: ExpandableTextProps) => {
const [isExpanded, setIsExpanded] = useState<boolean>(false);
const ref = useRef<HTMLParagraphElement>(null);

useEffect(() => {
setIsExpanded(false);
}, [text]);

useLayoutEffect(() => {
setCurrentHeight(
(ref.current?.clientHeight || DEFAULT_DESCRIPTION_HEIGHT) +
TEXT_BOTTOM_MARGIN
);
}, [isExpanded, setCurrentHeight]);
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The useLayoutEffect hook is missing text in its dependency array. When the text changes, useEffect resets isExpanded to false, but the height may not be recalculated if setCurrentHeight is a stable reference. This can lead to stale height values. Add text to the dependency array of useLayoutEffect.

Suggested change
}, [isExpanded, setCurrentHeight]);
}, [isExpanded, setCurrentHeight, text]);

Copilot uses AI. Check for mistakes.
return (
<Paragraph
ref={ref}
ellipsis={{
rows: 2,
expandable: "collapsible",
onExpand: (_, info) => {
setIsExpanded(info.expanded);
},
expanded: isExpanded,
symbol: (expanded) =>
expanded ? collapseSymbol : expandSymbol,
}}
>
{text}
</Paragraph>
);
};
export default ExpandableText;
5 changes: 3 additions & 2 deletions src/components/JSONViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { ViewableRecipe } from "../../types";

interface JSONViewerProps {
title: string;
availableHeight?: number;
content?: ViewableRecipe;
}

const JSONViewer = (props: JSONViewerProps): JSX.Element | null => {
const { content } = props;
const { content, availableHeight } = props;

if (!content) {
return null;
Expand Down Expand Up @@ -67,7 +68,7 @@ const JSONViewer = (props: JSONViewerProps): JSX.Element | null => {
});

return (
<div className="full-recipe">
<div className="full-recipe" style={{ height: availableHeight }}>
<Descriptions
size="small"
bordered
Expand Down
3 changes: 1 addition & 2 deletions src/components/JSONViewer/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
.full-recipe {
display: flex;
flex-direction: column;
border: 1px solid #d9d9d9;
border-radius: 6px;
font-size: 14px;
}
Expand All @@ -20,5 +19,5 @@
padding: 10px;
font-size: 16px;
font-weight: 600;
border-top: 0.5px solid;
border-top: 0.5px solid #d9d9d9;
}
47 changes: 42 additions & 5 deletions src/components/PackingInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect } from "react";
import { useCallback, useEffect, useState } from "react";
import { Tabs } from "antd";

import {
Expand All @@ -13,8 +13,15 @@ import {
import Dropdown from "../Dropdown";
import JSONViewer from "../JSONViewer";
import RecipeForm from "../RecipeForm";
import { ExpandableText } from "../ExpandableDescription";
import ExpandableText from "../ExpandableText";
import "./style.css";
import { useSiderHeight } from "../../hooks/useSiderHeight";
import {
DEFAULT_DESCRIPTION_HEIGHT,
SELECT_HEIGHT,
TABS_HEADER_HEIGHT,
TEXT_BOTTOM_MARGIN,
} from "../../constants";

interface PackingInputProps {
startPacking: (
Expand All @@ -34,6 +41,20 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
const loadAllRecipes = useLoadAllRecipes();
const selectRecipe = useSelectRecipe();
const storeStartPacking = useStartPacking();
const siderHeight = useSiderHeight();

const [descriptionHeight, setDescriptionHeight] = useState<number>(
DEFAULT_DESCRIPTION_HEIGHT + TEXT_BOTTOM_MARGIN
);
const [availableRecipeHeight, setAvailableRecipeHeight] = useState<number>(
siderHeight - descriptionHeight - SELECT_HEIGHT
);

useEffect(() => {
const newAvailableHeight =
siderHeight - descriptionHeight - SELECT_HEIGHT;
setAvailableRecipeHeight(newAvailableHeight);
}, [siderHeight, descriptionHeight]);

const preFetchInputsAndRecipes = useCallback(async () => {
await loadInputOptions();
Expand Down Expand Up @@ -73,14 +94,30 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
) : (
<>
{recipeObj.description && (
<ExpandableText text={recipeObj.description} />
<div className="recipe-description">
<ExpandableText
text={recipeObj.description}
setCurrentHeight={setDescriptionHeight}
/>
</div>
)}
<Tabs defaultActiveKey="1" className="recipe-content">
<Tabs.TabPane tab="Editable fields" key="1">
<RecipeForm onStartPacking={handleStartPacking} />
<RecipeForm
onStartPacking={handleStartPacking}
availableHeight={
availableRecipeHeight - TABS_HEADER_HEIGHT
}
/>
</Tabs.TabPane>
<Tabs.TabPane tab="Full Recipe" key="2">
<JSONViewer title="Recipe" content={recipeObj} />
<JSONViewer
title="Recipe"
content={recipeObj}
availableHeight={
availableRecipeHeight - TABS_HEADER_HEIGHT
}
/>
</Tabs.TabPane>
</Tabs>
</>
Expand Down
4 changes: 2 additions & 2 deletions src/components/PackingInput/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
height: var(--recipe-select-height);
}

.recipe-content {
height: calc(100% - var(--recipe-select-height));
.ant-tabs-content-holder {
overflow-y: auto;
}
8 changes: 5 additions & 3 deletions src/components/RecipeForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import {

interface RecipeFormProps {
onStartPacking: () => Promise<void>;
availableHeight: number;
}

const RecipeForm = ({ onStartPacking }: RecipeFormProps) => {
const RecipeForm = ({ onStartPacking, availableHeight }: RecipeFormProps) => {
const recipeId = useSelectedRecipeId();
const fieldsToDisplay = useFieldsToDisplay();
const isPacking = useIsPacking();
const isOriginalRecipe = useIsOriginalRecipe();

return (
<div className="recipe-form">
<div className="recipe-form" style={{ height: availableHeight }}>
{fieldsToDisplay && (
<div className="input-container">
{fieldsToDisplay.map((field) => (
Expand Down Expand Up @@ -48,10 +49,11 @@ const RecipeForm = ({ onStartPacking }: RecipeFormProps) => {
>
<Button
onClick={onStartPacking}
className="packing-button"
color="primary"
variant="filled"
disabled={isPacking || isOriginalRecipe}
style={{ width: "100%" }}
style={{ width: "100%", minHeight: 38 }}
>
<strong>Re-run</strong>
</Button>
Expand Down
8 changes: 4 additions & 4 deletions src/components/RecipeForm/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
display: flex;
flex-direction: column;
justify-content: space-between;
height: calc(
100vh - var(--header-height) - var(--recipe-select-height) -
var(--tab-height) - var(--footer-height) - var(--description-height)
);
}

.packing-button {
margin-bottom: 20px;
}
4 changes: 4 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const DEFAULT_DESCRIPTION_HEIGHT = 58;
export const TEXT_BOTTOM_MARGIN = 14;
export const SELECT_HEIGHT = 52;
export const TABS_HEADER_HEIGHT = 62;
21 changes: 21 additions & 0 deletions src/hooks/useSiderHeight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useState, useEffect } from "react";
const HEADER_HEIGHT = 48;
const FOOTER_HEIGHT = 51;

export function useSiderHeight() {
const [siderHeight, setSiderHeight] = useState<number>(
window.innerHeight - HEADER_HEIGHT - FOOTER_HEIGHT
);

useEffect(() => {
function handleResize() {
setSiderHeight(window.innerHeight - HEADER_HEIGHT - FOOTER_HEIGHT);
}
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
Comment on lines +10 to +18
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The height calculation logic is duplicated in the initial state (line 7) and the resize handler (line 12). Extract this into a helper function to avoid duplication and ensure consistency.

Copilot uses AI. Check for mistakes.

return siderHeight;
}