Skip to content

Commit

Permalink
Fix/validation in add new prompt studio (#60)
Browse files Browse the repository at this point in the history
* Add validation in add new tool from prompt studio

* Handle error validation for update API deployment
  • Loading branch information
mohamed-siddhiq authored Mar 6, 2024
1 parent 22a0c58 commit 28f7e20
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 181 deletions.
58 changes: 52 additions & 6 deletions frontend/package-lock.json

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

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"antd": "^5.5.1",
"axios": "^1.4.0",
"cron-validator": "^1.3.1",
"emoji-picker-react": "^4.8.0",
"emoji-regex": "^10.3.0",
"handlebars": "^4.7.8",
"http-proxy-middleware": "^2.0.6",
"js-yaml": "^4.1.0",
Expand Down
10 changes: 3 additions & 7 deletions frontend/src/components/agency/cards-list/CardsList.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CloseOutlined } from "@ant-design/icons";
import { Card, Col, Image, Progress, Row, Typography } from "antd";
import { Card, Col, Progress, Row, Typography } from "antd";
import PropTypes from "prop-types";
import { useRef } from "react";
import { useDrag, useDrop } from "react-dnd";
Expand All @@ -13,6 +13,7 @@ import { useWorkflowStore } from "../../../store/workflow-store";
import { ConfirmModal } from "../../widgets/confirm-modal/ConfirmModal";
import "../step-card/StepCard.css";
import "./CardList.css";
import { ToolIcon } from "../tool-icon/ToolIcon";

const CardsList = ({ step, index, activeTool, moveItem }) => {
const ref = useRef(null);
Expand Down Expand Up @@ -143,12 +144,7 @@ const CardsList = ({ step, index, activeTool, moveItem }) => {
<div className="card-col-div">
<Row align="middle">
<Col span={2}>
<Image
src={`data:image/svg+xml,${encodeURIComponent(step?.icon)}`}
preview={false}
height={20}
width={20}
/>
<ToolIcon iconSrc={step?.icon} showBorder={false} />
</Col>
<Col span={21}>
<div className="step-name">
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/components/agency/side-panel/SidePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function SidePanel() {
setActiveTabKey(key.toString());
};

const isObjectEmpty = (obj) => {
return Object.keys(obj).length === 0;
};

useEffect(() => {
const toolSettingsId = toolSettings?.tool_id;
if (!toolSettingsId) {
Expand All @@ -65,8 +69,15 @@ function SidePanel() {
setSpecLoading(true);
axiosPrivate(requestOptions)
.then((res) => {
setToolId(toolSettingsId);
setSpec(res?.data);
if (isObjectEmpty(res?.data?.properties)) {
// Disable tool settings & switch to Tools tab - when custom tool is selected
setSpec({});
setToolId("");
setActiveTabKey("1");
} else {
setToolId(toolSettingsId);
setSpec(res?.data);
}
})
.catch((err) => {})
.finally(() => {
Expand Down
55 changes: 40 additions & 15 deletions frontend/src/components/agency/tool-icon/ToolIcon.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
import { Image } from "antd";
import emojiRegex from "emoji-regex";
import PropTypes from "prop-types";

import "./ToolIcon.css";
import { useEffect, useState } from "react";

function ToolIcon({ iconSrc }) {
const [svgDataUri, setSvgDataUri] = useState("");
useEffect(() => {
if (!iconSrc) {
setSvgDataUri("");
return;
}
function ToolIcon({ iconSrc, showBorder }) {
const emojiregex = emojiRegex();
const isSVG =
iconSrc && typeof iconSrc === "string" && iconSrc.includes("<svg");

if (isSVG) {
// If it's an SVG, render it as an image
const uri = `data:image/svg+xml,${encodeURIComponent(iconSrc)}`;
setSvgDataUri(uri);
}, [iconSrc]);
return (
<div className="tool-icon-border display-flex-center">
<Image src={svgDataUri} preview={false} height={30} width={30} />
</div>
);
return (
<div
className={`display-flex-center ${
showBorder ? "tool-icon-border" : ""
}`}
>
<Image src={uri} preview={false} height={30} width={30} />
</div>
);
} else if (typeof iconSrc === "string" && emojiregex.test(iconSrc)) {
// If it's a string, render it using Typography
return (
<div
className={`display-flex-center ${
showBorder ? "tool-icon-border" : ""
}`}
>
{iconSrc}
</div>
);
} else {
// Handle other cases if needed
return (
<div
className={`display-flex-center ${
showBorder ? "tool-icon-border" : ""
}`}
>
{"🧰"}
</div>
);
}
}

ToolIcon.propTypes = {
iconSrc: PropTypes.string,
showBorder: PropTypes.bool,
};

export { ToolIcon };
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function ToolInfoCard({ toolInfo }) {
<Card className="toolinfo-card" ref={ref}>
<Row>
<Col span={4}>
<ToolIcon iconSrc={toolInfo?.icon} />
<ToolIcon iconSrc={toolInfo?.icon} showBorder={true} />
</Col>
<Col span={20}>
<div className="tool-info-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@

.add-cus-tool-gap {
margin-bottom: 16px;
}
}

.emoji-modal .ant-modal-content {
padding: 0;
width: fit-content;
}
Loading

0 comments on commit 28f7e20

Please sign in to comment.