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

add collapsible drawer to show/hide prompt #2269

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"plotly.js": "^2.35.2",
"react": "^18.3.1",
"react-bootstrap": "^2.10.6",
"react-collapse": "^5.1.1",
"react-detect-print": "^0.1.2",
"react-dom": "^18.3.1",
"react-ga": "^3.3.1",
Expand Down
116 changes: 100 additions & 16 deletions src/pages/policy/output/Analysis.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { MarkdownFormatter } from "../../../layout/MarkdownFormatter";
import { countryApiCall } from "../../../api/call";
import { getImpactReps } from "./ImpactTypes";
import ErrorComponent from "../../../layout/ErrorComponent";
import { motion } from "framer-motion";
import { CaretDownOutlined, FileTextOutlined } from "@ant-design/icons";
import { Collapse } from "react-collapse";

export default function Analysis(props) {
const { impact, policyLabel, metadata, policy, region, timePeriod } = props;
Expand Down Expand Up @@ -237,25 +240,106 @@ export default function Analysis(props) {
<ErrorComponent message="There was an error generating the analysis." />
)}
</div>
<div
<motion.div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
marginBottom: 20,
margin: "20px 0",
backgroundColor: "#fff",
}}
>
<Button
text={showPrompt ? "Hide prompt" : "Show prompt"}
type="secondary"
onClick={() => setShowPrompt(!showPrompt)}
style={{ maxWidth: 250, margin: "20px auto 10px" }}
/>
</div>
{showPrompt ? (
<CodeBlock lines={lines} language={"markdown"} data={prompt} />
) : null}
<motion.div
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue, blocking: Please match this to our existing style.

As implemented here, this component doesn't quite match our visual style. Using the "Input" and "Ouptut" components at https://policyengine.org/us/api, could you refactor this to better match our visual style?

This issue could probably even be solved by just refactoring the existing code component to allow for full collapsibility on default, without the need for react-collapse and motion.

style={{
border: "1px solid #E6E8EB",
borderRadius: "12px",
overflow: "hidden",
}}
whileHover={{
boxShadow:
"0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08)",
}}
transition={{ duration: 0.2 }}
>
<motion.button
onClick={() => setShowPrompt(!showPrompt)}
style={{
width: "100%",
padding: "16px 24px",
backgroundColor: "#fff",
border: "none",
display: "flex",
justifyContent: "space-between",
alignItems: "center",
cursor: "pointer",
}}
whileHover={{ backgroundColor: "#f8f9fa" }}
whileTap={{ backgroundColor: "#f1f3f5" }}
transition={{ duration: 0.2 }}
>
<motion.div
style={{
display: "flex",
alignItems: "center",
gap: "12px",
}}
initial={false}
>
<FileTextOutlined
style={{
fontSize: "20px",
color: showPrompt ? "#1A1F36" : "#697386",
}}
/>
<div style={{ textAlign: "left" }}>
<div
style={{
fontWeight: 500,
color: "#1A1F36",
fontSize: "15px",
}}
>
Prompt Details
</div>
<div
style={{
fontSize: "13px",
color: "#697386",
marginTop: "4px",
}}
>
View the AI prompt used for this analysis
</div>
</div>
</motion.div>
<motion.span
animate={{ rotate: showPrompt ? 180 : 0 }}
transition={{ duration: 0.3 }}
>
<CaretDownOutlined
style={{
fontSize: "12px",
color: showPrompt ? "#1A1F36" : "#697386",
}}
/>
</motion.span>
</motion.button>
<Collapse isOpened={showPrompt}>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.3 }}
>
<div
style={{
padding: "24px",
borderTop: "1px solid #E6E8EB",
backgroundColor: "#FAFAFA",
}}
>
<CodeBlock lines={lines} language={"markdown"} data={prompt} />
</div>
</motion.div>
</Collapse>
</motion.div>
</motion.div>
</>
);
}
Loading