implemented Refresh button on node toolbar dropdown that appears when the user edits and the component is outdated.
This commit is contained in:
parent
d559a61793
commit
4fcd7027ad
6 changed files with 30 additions and 22 deletions
|
|
@ -75,6 +75,7 @@ export default function GenericNode({
|
||||||
data.node?.description!,
|
data.node?.description!,
|
||||||
);
|
);
|
||||||
const [isOutdated, setIsOutdated] = useState(false);
|
const [isOutdated, setIsOutdated] = useState(false);
|
||||||
|
const [isUserEdited, setIsUserEdited] = useState(false);
|
||||||
const buildStatus = useFlowStore(
|
const buildStatus = useFlowStore(
|
||||||
(state) => state.flowBuildStatus[data.id]?.status,
|
(state) => state.flowBuildStatus[data.id]?.status,
|
||||||
);
|
);
|
||||||
|
|
@ -96,6 +97,7 @@ export default function GenericNode({
|
||||||
data.node!,
|
data.node!,
|
||||||
setNode,
|
setNode,
|
||||||
setIsOutdated,
|
setIsOutdated,
|
||||||
|
setIsUserEdited,
|
||||||
updateNodeInternals,
|
updateNodeInternals,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -170,7 +172,7 @@ export default function GenericNode({
|
||||||
deleteNode(data.id);
|
deleteNode(data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
useCheckCodeValidity(data, templates, setIsOutdated, types);
|
useCheckCodeValidity(data, templates, setIsOutdated, setIsUserEdited, types);
|
||||||
useUpdateValidationStatus(data?.id, flowPool, setValidationStatus);
|
useUpdateValidationStatus(data?.id, flowPool, setValidationStatus);
|
||||||
useValidationStatusString(validationStatus, setValidationString);
|
useValidationStatusString(validationStatus, setValidationString);
|
||||||
|
|
||||||
|
|
@ -329,8 +331,8 @@ export default function GenericNode({
|
||||||
showNode={showNode}
|
showNode={showNode}
|
||||||
openAdvancedModal={false}
|
openAdvancedModal={false}
|
||||||
onCloseAdvancedModal={() => {}}
|
onCloseAdvancedModal={() => {}}
|
||||||
selected={selected}
|
|
||||||
updateNode={handleUpdateCode}
|
updateNode={handleUpdateCode}
|
||||||
|
isOutdated={isOutdated && isUserEdited}
|
||||||
/>
|
/>
|
||||||
</NodeToolbar>
|
</NodeToolbar>
|
||||||
);
|
);
|
||||||
|
|
@ -344,6 +346,7 @@ export default function GenericNode({
|
||||||
showNode,
|
showNode,
|
||||||
updateNodeCode,
|
updateNodeCode,
|
||||||
isOutdated,
|
isOutdated,
|
||||||
|
isUserEdited,
|
||||||
selected,
|
selected,
|
||||||
shortcuts,
|
shortcuts,
|
||||||
// openWDoubleCLick,
|
// openWDoubleCLick,
|
||||||
|
|
@ -435,7 +438,7 @@ export default function GenericNode({
|
||||||
{data.node?.display_name}
|
{data.node?.display_name}
|
||||||
</div>
|
</div>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
{isOutdated && (
|
{isOutdated && !isUserEdited && (
|
||||||
<ShadTooltip content={TOOLTIP_OUTDATED_NODE}>
|
<ShadTooltip content={TOOLTIP_OUTDATED_NODE}>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleUpdateCode}
|
onClick={handleUpdateCode}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const useCheckCodeValidity = (
|
||||||
data: NodeDataType,
|
data: NodeDataType,
|
||||||
templates: { [key: string]: any },
|
templates: { [key: string]: any },
|
||||||
setIsOutdated: (value: boolean) => void,
|
setIsOutdated: (value: boolean) => void,
|
||||||
|
setIsUserEdited: (value: boolean) => void,
|
||||||
types,
|
types,
|
||||||
) => {
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -24,17 +25,12 @@ const useCheckCodeValidity = (
|
||||||
const currentCode = thisNodeTemplate.code?.value;
|
const currentCode = thisNodeTemplate.code?.value;
|
||||||
const thisNodesCode = data.node!.template?.code?.value;
|
const thisNodesCode = data.node!.template?.code?.value;
|
||||||
const componentsToIgnore = ["CustomComponent", "Prompt"];
|
const componentsToIgnore = ["CustomComponent", "Prompt"];
|
||||||
if (
|
setIsOutdated(
|
||||||
currentCode !== thisNodesCode &&
|
currentCode !== thisNodesCode && !componentsToIgnore.includes(data.type),
|
||||||
!componentsToIgnore.includes(data.type) &&
|
);
|
||||||
!(data.node?.edited ?? false)
|
setIsUserEdited(data.node?.edited ?? false);
|
||||||
) {
|
|
||||||
setIsOutdated(true);
|
|
||||||
} else {
|
|
||||||
setIsOutdated(false);
|
|
||||||
}
|
|
||||||
// template.code can be undefined
|
// template.code can be undefined
|
||||||
}, [data.node?.template?.code?.value, templates, setIsOutdated]);
|
}, [data.node?.template?.code?.value, templates, setIsOutdated, setIsUserEdited]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useCheckCodeValidity;
|
export default useCheckCodeValidity;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ const useUpdateNodeCode = (
|
||||||
dataNode: APIClassType, // Define YourNodeType according to your data structure
|
dataNode: APIClassType, // Define YourNodeType according to your data structure
|
||||||
setNode: (id: string, callback: (oldNode) => any) => void,
|
setNode: (id: string, callback: (oldNode) => any) => void,
|
||||||
setIsOutdated: (value: boolean) => void,
|
setIsOutdated: (value: boolean) => void,
|
||||||
|
setIsUserEdited: (value: boolean) => void,
|
||||||
updateNodeInternals: (id: string) => void,
|
updateNodeInternals: (id: string) => void,
|
||||||
) => {
|
) => {
|
||||||
const updateNodeCode = useCallback(
|
const updateNodeCode = useCallback(
|
||||||
|
|
@ -24,6 +25,7 @@ const useUpdateNodeCode = (
|
||||||
|
|
||||||
newNode.data.node.template[name].value = code;
|
newNode.data.node.template[name].value = code;
|
||||||
setIsOutdated(false);
|
setIsOutdated(false);
|
||||||
|
setIsUserEdited(false);
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ export default function NodeToolbarComponent({
|
||||||
numberOfOutputHandles,
|
numberOfOutputHandles,
|
||||||
showNode,
|
showNode,
|
||||||
name = "code",
|
name = "code",
|
||||||
selected,
|
|
||||||
setShowState,
|
setShowState,
|
||||||
onCloseAdvancedModal,
|
onCloseAdvancedModal,
|
||||||
updateNode,
|
updateNode,
|
||||||
|
isOutdated,
|
||||||
}: nodeToolbarPropsType): JSX.Element {
|
}: nodeToolbarPropsType): JSX.Element {
|
||||||
const version = useDarkStore((state) => state.version);
|
const version = useDarkStore((state) => state.version);
|
||||||
const [showModalAdvanced, setShowModalAdvanced] = useState(false);
|
const [showModalAdvanced, setShowModalAdvanced] = useState(false);
|
||||||
|
|
@ -90,13 +90,6 @@ export default function NodeToolbarComponent({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpdateWShortcut(e: KeyboardEvent) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (hasApiKey || hasStore) {
|
|
||||||
handleSelectChange("update");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleGroupWShortcut(e: KeyboardEvent) {
|
function handleGroupWShortcut(e: KeyboardEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
|
|
@ -609,6 +602,18 @@ export default function NodeToolbarComponent({
|
||||||
dataTestId="copy-button-modal"
|
dataTestId="copy-button-modal"
|
||||||
/>
|
/>
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
|
{isOutdated && (
|
||||||
|
<SelectItem value={"update"}>
|
||||||
|
<ToolbarSelectItem
|
||||||
|
shortcut={
|
||||||
|
shortcuts.find((obj) => obj.name === "Update")?.shortcut!
|
||||||
|
}
|
||||||
|
value={"Restore"}
|
||||||
|
icon={"RefreshCcwDot"}
|
||||||
|
dataTestId="update-button-modal"
|
||||||
|
/>
|
||||||
|
</SelectItem>
|
||||||
|
)}
|
||||||
{hasStore && (
|
{hasStore && (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={"Share"}
|
value={"Share"}
|
||||||
|
|
|
||||||
|
|
@ -562,7 +562,7 @@ export type nodeToolbarPropsType = {
|
||||||
name?: string;
|
name?: string;
|
||||||
openAdvancedModal?: boolean;
|
openAdvancedModal?: boolean;
|
||||||
onCloseAdvancedModal?: (close: boolean) => void;
|
onCloseAdvancedModal?: (close: boolean) => void;
|
||||||
selected: boolean;
|
isOutdated: boolean;
|
||||||
setShowState: (show: boolean | SetStateAction<boolean>) => void;
|
setShowState: (show: boolean | SetStateAction<boolean>) => void;
|
||||||
updateNode: () => void;
|
updateNode: () => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ import {
|
||||||
PocketKnife,
|
PocketKnife,
|
||||||
Redo,
|
Redo,
|
||||||
RefreshCcw,
|
RefreshCcw,
|
||||||
|
RefreshCcwDot,
|
||||||
Repeat,
|
Repeat,
|
||||||
RotateCcw,
|
RotateCcw,
|
||||||
Save,
|
Save,
|
||||||
|
|
@ -453,6 +454,7 @@ export const nodeIconsLucide: iconsType = {
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
SlidersHorizontal,
|
SlidersHorizontal,
|
||||||
Palette,
|
Palette,
|
||||||
|
RefreshCcwDot,
|
||||||
FolderUp,
|
FolderUp,
|
||||||
Blocks,
|
Blocks,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue