Skip to content

Commit ceb85ce

Browse files
meganrmCopilot
andauthored
Fix/vertical spacing (#160)
* adjusting height correctly * button stays in the same spot * remove commented out code * remove ref * fix bug * Update src/components/PackingInput/index.tsx Co-authored-by: Copilot <[email protected]> * Update src/components/PackingInput/index.tsx Co-authored-by: Copilot <[email protected]> * re-order imports * scroll within recipe container * maintain height * remove sider height * uselayouteffect * remove function --------- Co-authored-by: Copilot <[email protected]>
1 parent 9d07b50 commit ceb85ce

File tree

13 files changed

+145
-60
lines changed

13 files changed

+145
-60
lines changed

src/App.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222
}
2323

2424
.sider {
25-
height: calc(
26-
100vh - var(--header-height) - var(--footer-height)
27-
); /* full height minus header and footer */
28-
overflow-x: hidden;
29-
overflow-y: auto;
25+
overflow: hidden;
3026
padding: 0 40px;
3127
}
3228

src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const { Link } = Typography;
2525

2626
function App() {
2727
const [jobStatus, setJobStatus] = useState<string>("");
28+
2829
const setJobLogs = useSetJobLogs();
2930
const jobLogs = useJobLogs();
3031
const setJobId = useSetJobId();

src/components/ExpandableDescription/index.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Typography } from "antd";
2+
import { ArrowDownOutlined, ArrowUpOutlined } from "@ant-design/icons";
3+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
4+
import {
5+
DEFAULT_DESCRIPTION_HEIGHT,
6+
TEXT_BOTTOM_MARGIN,
7+
} from "../../constants";
8+
9+
import "./style.css";
10+
const { Paragraph } = Typography;
11+
12+
interface ExpandableTextProps {
13+
text: string;
14+
setCurrentHeight: (height: number) => void;
15+
}
16+
17+
const expandSymbol = (
18+
<span>
19+
expand <ArrowDownOutlined />
20+
</span>
21+
);
22+
23+
const collapseSymbol = (
24+
<span>
25+
collapse <ArrowUpOutlined />
26+
</span>
27+
);
28+
29+
const ExpandableText = ({ text, setCurrentHeight }: ExpandableTextProps) => {
30+
const [isExpanded, setIsExpanded] = useState<boolean>(false);
31+
const ref = useRef<HTMLParagraphElement>(null);
32+
33+
useEffect(() => {
34+
setIsExpanded(false);
35+
}, [text]);
36+
37+
useLayoutEffect(() => {
38+
setCurrentHeight(
39+
(ref.current?.clientHeight || DEFAULT_DESCRIPTION_HEIGHT) +
40+
TEXT_BOTTOM_MARGIN
41+
);
42+
}, [isExpanded, setCurrentHeight]);
43+
return (
44+
<Paragraph
45+
ref={ref}
46+
ellipsis={{
47+
rows: 2,
48+
expandable: "collapsible",
49+
onExpand: (_, info) => {
50+
setIsExpanded(info.expanded);
51+
},
52+
expanded: isExpanded,
53+
symbol: (expanded) =>
54+
expanded ? collapseSymbol : expandSymbol,
55+
}}
56+
>
57+
{text}
58+
</Paragraph>
59+
);
60+
};
61+
export default ExpandableText;
File renamed without changes.

src/components/JSONViewer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import { ViewableRecipe } from "../../types";
1111

1212
interface JSONViewerProps {
1313
title: string;
14+
availableHeight?: number;
1415
content?: ViewableRecipe;
1516
}
1617

1718
const JSONViewer = (props: JSONViewerProps): JSX.Element | null => {
18-
const { content } = props;
19+
const { content, availableHeight } = props;
1920

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

6970
return (
70-
<div className="full-recipe">
71+
<div className="full-recipe" style={{ height: availableHeight }}>
7172
<Descriptions
7273
size="small"
7374
bordered

src/components/JSONViewer/style.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
.full-recipe {
77
display: flex;
88
flex-direction: column;
9-
border: 1px solid #d9d9d9;
109
border-radius: 6px;
1110
font-size: 14px;
1211
}
@@ -20,5 +19,5 @@
2019
padding: 10px;
2120
font-size: 16px;
2221
font-weight: 600;
23-
border-top: 0.5px solid;
22+
border-top: 0.5px solid #d9d9d9;
2423
}

src/components/PackingInput/index.tsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect } from "react";
1+
import { useCallback, useEffect, useState } from "react";
22
import { Tabs } from "antd";
33

44
import {
@@ -13,8 +13,15 @@ import {
1313
import Dropdown from "../Dropdown";
1414
import JSONViewer from "../JSONViewer";
1515
import RecipeForm from "../RecipeForm";
16-
import { ExpandableText } from "../ExpandableDescription";
16+
import ExpandableText from "../ExpandableText";
1717
import "./style.css";
18+
import { useSiderHeight } from "../../hooks/useSiderHeight";
19+
import {
20+
DEFAULT_DESCRIPTION_HEIGHT,
21+
SELECT_HEIGHT,
22+
TABS_HEADER_HEIGHT,
23+
TEXT_BOTTOM_MARGIN,
24+
} from "../../constants";
1825

1926
interface PackingInputProps {
2027
startPacking: (
@@ -34,6 +41,20 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
3441
const loadAllRecipes = useLoadAllRecipes();
3542
const selectRecipe = useSelectRecipe();
3643
const storeStartPacking = useStartPacking();
44+
const siderHeight = useSiderHeight();
45+
46+
const [descriptionHeight, setDescriptionHeight] = useState<number>(
47+
DEFAULT_DESCRIPTION_HEIGHT + TEXT_BOTTOM_MARGIN
48+
);
49+
const [availableRecipeHeight, setAvailableRecipeHeight] = useState<number>(
50+
siderHeight - descriptionHeight - SELECT_HEIGHT
51+
);
52+
53+
useEffect(() => {
54+
const newAvailableHeight =
55+
siderHeight - descriptionHeight - SELECT_HEIGHT;
56+
setAvailableRecipeHeight(newAvailableHeight);
57+
}, [siderHeight, descriptionHeight]);
3758

3859
const preFetchInputsAndRecipes = useCallback(async () => {
3960
await loadInputOptions();
@@ -73,14 +94,30 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
7394
) : (
7495
<>
7596
{recipeObj.description && (
76-
<ExpandableText text={recipeObj.description} />
97+
<div className="recipe-description">
98+
<ExpandableText
99+
text={recipeObj.description}
100+
setCurrentHeight={setDescriptionHeight}
101+
/>
102+
</div>
77103
)}
78104
<Tabs defaultActiveKey="1" className="recipe-content">
79105
<Tabs.TabPane tab="Editable fields" key="1">
80-
<RecipeForm onStartPacking={handleStartPacking} />
106+
<RecipeForm
107+
onStartPacking={handleStartPacking}
108+
availableHeight={
109+
availableRecipeHeight - TABS_HEADER_HEIGHT
110+
}
111+
/>
81112
</Tabs.TabPane>
82113
<Tabs.TabPane tab="Full Recipe" key="2">
83-
<JSONViewer title="Recipe" content={recipeObj} />
114+
<JSONViewer
115+
title="Recipe"
116+
content={recipeObj}
117+
availableHeight={
118+
availableRecipeHeight - TABS_HEADER_HEIGHT
119+
}
120+
/>
84121
</Tabs.TabPane>
85122
</Tabs>
86123
</>

src/components/PackingInput/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
height: var(--recipe-select-height);
77
}
88

9-
.recipe-content {
10-
height: calc(100% - var(--recipe-select-height));
9+
.ant-tabs-content-holder {
10+
overflow-y: auto;
1111
}

src/components/RecipeForm/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ import {
1010

1111
interface RecipeFormProps {
1212
onStartPacking: () => Promise<void>;
13+
availableHeight: number;
1314
}
1415

15-
const RecipeForm = ({ onStartPacking }: RecipeFormProps) => {
16+
const RecipeForm = ({ onStartPacking, availableHeight }: RecipeFormProps) => {
1617
const recipeId = useSelectedRecipeId();
1718
const fieldsToDisplay = useFieldsToDisplay();
1819
const isPacking = useIsPacking();
1920
const isOriginalRecipe = useIsOriginalRecipe();
2021

2122
return (
22-
<div className="recipe-form">
23+
<div className="recipe-form" style={{ height: availableHeight }}>
2324
{fieldsToDisplay && (
2425
<div className="input-container">
2526
{fieldsToDisplay.map((field) => (
@@ -48,10 +49,11 @@ const RecipeForm = ({ onStartPacking }: RecipeFormProps) => {
4849
>
4950
<Button
5051
onClick={onStartPacking}
52+
className="packing-button"
5153
color="primary"
5254
variant="filled"
5355
disabled={isPacking || isOriginalRecipe}
54-
style={{ width: "100%" }}
56+
style={{ width: "100%", minHeight: 38 }}
5557
>
5658
<strong>Re-run</strong>
5759
</Button>

0 commit comments

Comments
 (0)