Skip to content

Commit e166f0d

Browse files
authored
[gradio] Fix Margin of Title / Global Parameters (#1109)
[gradio] Fix Margin of Title / Global Parameters # [gradio] Fix Margin of Title / Global Parameters In gradio, the prompt menu button has styles overridden by gradio button styles and therefore has no padding. This messes up the alignment of the title/description and global parameters compared to the prompts: ![Screenshot 2024-02-01 at 11 23 00 AM](https://github.com/lastmile-ai/aiconfig/assets/5060851/d6f6ac96-f47e-4ccb-ad9f-47104433fb4d) Similarly, in readOnly mode there is no prompt menu button but we still had the left margin on the title/description and global parameters: ![Screenshot 2024-02-01 at 11 26 04 AM](https://github.com/lastmile-ai/aiconfig/assets/5060851/bdf2dd50-9436-45c8-940b-533f168aa55a) This PR fixes both situations by: - Explicitly setting the padding/margin for the prompt menu button in gradio theme to have higher specificity than gradio button styles - Dynamically handling the left margin of the title/description and global parameters based on readOnly or not Notes: - Not sure how to test vscode theme here really since the actual vs code package has different styles, etc. from what's in prod. As best-effort, I just made sure the global parametersContainer and parametersContainerReadonly styles override local style when set (so they can be used as needed in vscode theme after) ## Testing: - Gradio theme: ![Screenshot 2024-02-01 at 11 28 52 AM](https://github.com/lastmile-ai/aiconfig/assets/5060851/5155fec0-bf6f-4652-9e60-e5fa8f173364) ![Screenshot 2024-02-01 at 11 29 04 AM](https://github.com/lastmile-ai/aiconfig/assets/5060851/70447498-88e1-45b0-be50-1dfa039e91d1) - Local theme: ![Screenshot 2024-02-01 at 11 29 13 AM](https://github.com/lastmile-ai/aiconfig/assets/5060851/0f9f8c2a-f5b9-44fa-b37f-5692f15e9d75) ![Screenshot 2024-02-01 at 11 29 21 AM](https://github.com/lastmile-ai/aiconfig/assets/5060851/46616263-c5df-4453-a7a0-bc418d4150de) --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/1109). * __->__ #1109 * #1105 * #1104 * #1103 * #1102 * #1101 * #1100 * #1099 * #1098 * #1097 * #1096 * #1095
2 parents 9b2d20d + dfa8d94 commit e166f0d

File tree

7 files changed

+307
-193
lines changed

7 files changed

+307
-193
lines changed

python/src/aiconfig/editor/client/src/components/ConfigNameDescription.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default memo(function ConfigNameDescription({
9999
<Stack
100100
ref={isEditing ? inputSectionRef : undefined}
101101
spacing="xs"
102-
ml="36px"
102+
ml={readOnly ? "auto" : "36px"}
103103
mr="0.5em"
104104
>
105105
{isEditing ? (

python/src/aiconfig/editor/client/src/components/GlobalParametersContainer.tsx

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
import { Accordion, Text } from "@mantine/core";
1+
import { Accordion, Text, createStyles } from "@mantine/core";
22
import { JSONObject } from "aiconfig";
3-
import { memo, useState } from "react";
3+
import { memo, useContext, useState } from "react";
44
import ParametersRenderer from "./ParametersRenderer";
5+
import AIConfigContext from "../contexts/AIConfigContext";
56

67
type Props = {
78
initialValue: JSONObject;
89
onUpdateParameters: (newParameters: JSONObject) => void;
910
};
1011

12+
const useStyles = createStyles(() => ({
13+
parametersContainer: {
14+
margin: "16px auto 16px 36px",
15+
},
16+
parametersContainerReadonly: {
17+
margin: "16px auto",
18+
},
19+
}));
20+
1121
export default memo(function GlobalParametersContainer({
1222
initialValue,
1323
onUpdateParameters,
1424
}: Props) {
1525
const [isParametersDrawerOpen, setIsParametersDrawerOpen] = useState(false);
1626

27+
const { classes } = useStyles();
28+
const { readOnly } = useContext(AIConfigContext);
29+
1730
return (
18-
<div className="parametersContainer">
31+
// Set local and global classname. Global will override if specified
32+
// Local is readonly or not. Global will always have parametersContainer class
33+
// and if readonly, will also have parametersContainerReadonly class (to allow overrides)
34+
<div
35+
className={`${
36+
readOnly
37+
? classes.parametersContainerReadonly
38+
: classes.parametersContainer
39+
} parametersContainer ${readOnly ? "parametersContainerReadonly" : ""}`}
40+
>
1941
<Accordion
2042
styles={{
2143
item: { borderBottom: 0 },

python/src/aiconfig/editor/client/src/components/prompt/PromptContainer.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,13 @@ export default memo(function PromptContainer({
156156
isRunning={prompt._ui.isRunning}
157157
isRunButtonDisabled={isRunButtonDisabled}
158158
/>
159-
<PromptOutputBar />
160-
{prompt.outputs && <PromptOutputsRenderer outputs={prompt.outputs} />}
159+
160+
{prompt.outputs && prompt.outputs.length > 0 && (
161+
<>
162+
<PromptOutputBar />
163+
<PromptOutputsRenderer outputs={prompt.outputs} />
164+
</>
165+
)}
161166
</Flex>
162167
</Card>
163168
<div className="sidePanel">

python/src/aiconfig/editor/client/src/components/prompt/PromptMenuButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default memo(function PromptMenuButton({
2424
size="xs"
2525
variant="subtle"
2626
color="dark"
27-
className={classes.promptMenuButton}
27+
className={`${classes.promptMenuButton} promptMenuButton`}
2828
>
2929
<IconDotsVertical size={14} />
3030
</Button>

python/src/aiconfig/editor/client/src/components/prompt/prompt_input/PromptInputConfigRenderer.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default memo(function PromptInputConfigRenderer({
1313
input,
1414
onChangeInput,
1515
}: Props) {
16-
const {readOnly} = useContext(AIConfigContext);
16+
const { readOnly } = useContext(AIConfigContext);
1717
return readOnly ? (
1818
<div style={{ padding: "0.5em" }}>
1919
<Spoiler
@@ -26,8 +26,9 @@ export default memo(function PromptInputConfigRenderer({
2626
<TextRenderer content={input as string} />
2727
</Spoiler>
2828
</div>
29-
): (
29+
) : (
3030
<Textarea
31+
label="Prompt"
3132
value={input as string}
3233
onChange={(e) => onChangeInput(e.target.value)}
3334
disabled={readOnly}

0 commit comments

Comments
 (0)