Added tooltip and handler to update node

This commit is contained in:
Lucas Oliveira 2024-06-07 12:23:25 -03:00
commit 50eb7766f2
4 changed files with 49 additions and 60 deletions

View file

@ -10,6 +10,7 @@ import {
RUN_TIMESTAMP_PREFIX, RUN_TIMESTAMP_PREFIX,
STATUS_BUILD, STATUS_BUILD,
STATUS_BUILDING, STATUS_BUILDING,
TOOLTIP_OUTDATED_NODE,
} from "../../constants/constants"; } from "../../constants/constants";
import { BuildStatus } from "../../constants/enums"; import { BuildStatus } from "../../constants/enums";
import { countHandlesFn } from "../helpers/count-handles"; import { countHandlesFn } from "../helpers/count-handles";
@ -34,6 +35,8 @@ import useValidationStatusString from "../hooks/use-validation-status-string";
import getFieldTitle from "../utils/get-field-title"; import getFieldTitle from "../utils/get-field-title";
import sortFields from "../utils/sort-fields"; import sortFields from "../utils/sort-fields";
import ParameterComponent from "./components/parameterComponent"; import ParameterComponent from "./components/parameterComponent";
import { postCustomComponent } from "../../controllers/API";
import { cloneDeep } from "lodash";
export default function GenericNode({ export default function GenericNode({
data, data,
@ -201,6 +204,37 @@ export default function GenericNode({
setShowNode(data.showNode ?? true); setShowNode(data.showNode ?? true);
}, [data.showNode]); }, [data.showNode]);
const handleUpdateCode = () => {
takeSnapshot();
// to update we must get the code from the templates in useTypesStore
const thisNodeTemplate = templates[data.type]?.template;
// if the template does not have a code key
// return
if (!thisNodeTemplate?.code) return;
const currentCode = thisNodeTemplate.code.value;
if (data.node) {
postCustomComponent(currentCode, data.node)
.then((apiReturn) => {
const { data } = apiReturn;
if (data && updateNodeCode) {
updateNodeCode(data, currentCode, "code");
}
})
.catch((err) => {
console.log(err);
});
setNode(data.id, (oldNode) => {
let newNode = cloneDeep(oldNode);
newNode.data = {
...data,
};
newNode.data.node.template.code.value = currentCode;
return newNode;
});
}
};
const memoizedNodeToolbarComponent = useMemo(() => { const memoizedNodeToolbarComponent = useMemo(() => {
return ( return (
<NodeToolbar> <NodeToolbar>
@ -221,8 +255,6 @@ export default function GenericNode({
showNode={showNode} showNode={showNode}
openAdvancedModal={false} openAdvancedModal={false}
onCloseAdvancedModal={() => {}} onCloseAdvancedModal={() => {}}
updateNodeCode={updateNodeCode}
isOutdated={isOutdated}
selected={selected} selected={selected}
/> />
</NodeToolbar> </NodeToolbar>
@ -439,12 +471,18 @@ export default function GenericNode({
<> <>
<div className="flex flex-shrink-0 items-center gap-1"> <div className="flex flex-shrink-0 items-center gap-1">
{isOutdated && ( {isOutdated && (
<Button variant="secondary" className={"h-9 px-1.5"}> <ShadTooltip content={TOOLTIP_OUTDATED_NODE}>
<Button
onClick={handleUpdateCode}
variant="secondary"
className={"h-9 px-1.5"}
>
<IconComponent <IconComponent
name="AlertTriangle" name="AlertTriangle"
className="h-5 w-5 text-status-yellow" className="h-5 w-5 text-status-yellow"
/> />
</Button> </Button>
</ShadTooltip>
)} )}
<ShadTooltip <ShadTooltip
content={ content={

View file

@ -661,6 +661,9 @@ export const OUTPUT_TYPES = new Set([
export const CHAT_FIRST_INITIAL_TEXT = export const CHAT_FIRST_INITIAL_TEXT =
"Start a conversation and click the agent's thoughts"; "Start a conversation and click the agent's thoughts";
export const TOOLTIP_OUTDATED_NODE =
"Your component is outdated. Click to update (data may be lost)";
export const CHAT_SECOND_INITIAL_TEXT = "to inspect the chaining process."; export const CHAT_SECOND_INITIAL_TEXT = "to inspect the chaining process.";
export const ZERO_NOTIFICATIONS = "No new notifications"; export const ZERO_NOTIFICATIONS = "No new notifications";

View file

@ -40,10 +40,8 @@ export default function NodeToolbarComponent({
showNode, showNode,
name = "code", name = "code",
selected, selected,
updateNodeCode,
setShowState, setShowState,
onCloseAdvancedModal, onCloseAdvancedModal,
isOutdated,
}: nodeToolbarPropsType): JSX.Element { }: nodeToolbarPropsType): JSX.Element {
const nodeLength = Object.keys(data.node!.template).filter( const nodeLength = Object.keys(data.node!.template).filter(
(templateField) => (templateField) =>
@ -179,37 +177,6 @@ export default function NodeToolbarComponent({
paneY: nodes.find((node) => node.id === data.id)?.position.y, paneY: nodes.find((node) => node.id === data.id)?.position.y,
}, },
); );
break;
case "update":
takeSnapshot();
// to update we must get the code from the templates in useTypesStore
const thisNodeTemplate = templates[data.type]?.template;
// if the template does not have a code key
// return
if (!thisNodeTemplate?.code) return;
const currentCode = thisNodeTemplate.code.value;
if (data.node) {
postCustomComponent(currentCode, data.node)
.then((apiReturn) => {
const { data } = apiReturn;
if (data && updateNodeCode) {
updateNodeCode(data, currentCode, "code");
}
})
.catch((err) => {
console.log(err);
});
setNode(data.id, (oldNode) => {
let newNode = cloneDeep(oldNode);
newNode.data = {
...data,
};
newNode.data.node.template.code.value = currentCode;
return newNode;
});
}
break; break;
} }
}; };
@ -508,19 +475,6 @@ export default function NodeToolbarComponent({
dataTestId="copy-button-modal" dataTestId="copy-button-modal"
/> />
</SelectItem> </SelectItem>
{isOutdated && (
<SelectItem value={"update"}>
<ToolbarSelectItem
keyboardKey="U"
isMac={navigator.userAgent.toUpperCase().includes("MAC")}
shift={false}
value={"Update"}
icon={"Code"}
dataTestId="update-button-modal"
ping={isOutdated}
/>
</SelectItem>
)}
{hasStore && ( {hasStore && (
<SelectItem <SelectItem
value={"Share"} value={"Share"}

View file

@ -538,13 +538,7 @@ export type nodeToolbarPropsType = {
openAdvancedModal?: boolean; openAdvancedModal?: boolean;
onCloseAdvancedModal?: (close: boolean) => void; onCloseAdvancedModal?: (close: boolean) => void;
selected: boolean; selected: boolean;
updateNodeCode?: (
newNodeClass: APIClassType,
code: string,
name: string,
) => void;
setShowState: (show: boolean | SetStateAction<boolean>) => void; setShowState: (show: boolean | SetStateAction<boolean>) => void;
isOutdated?: boolean;
}; };
export type parsedDataType = { export type parsedDataType = {