Removed unused console.log and fixed takeSnapshot logic

This commit is contained in:
Lucas Oliveira 2023-11-29 16:42:45 -03:00
commit 47885cd5f0
7 changed files with 8 additions and 16 deletions

View file

@ -120,6 +120,9 @@ export default function ParameterComponent({
const handleOnNewValue = ( const handleOnNewValue = (
newValue: string | string[] | boolean | Object[] newValue: string | string[] | boolean | Object[]
): void => { ): void => {
if (data.node!.template[name].value === newValue) {
return;
}
takeSnapshot(); takeSnapshot();
data.node!.template[name].value = newValue; data.node!.template[name].value = newValue;
// Set state to pending // Set state to pending

View file

@ -134,7 +134,10 @@ export default function GenericNode({
<NodeToolbarComponent <NodeToolbarComponent
position={{ x: xPos, y: yPos }} position={{ x: xPos, y: yPos }}
data={data} data={data}
deleteNode={deleteNode} deleteNode={(id) => {
takeSnapshot();
deleteNode(id);
}}
setShowNode={(showNode: boolean) => { setShowNode={(showNode: boolean) => {
data.showNode = showNode; data.showNode = showNode;
}} }}

View file

@ -337,7 +337,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
const currentfile = (e.target as HTMLInputElement).files![0]; const currentfile = (e.target as HTMLInputElement).files![0];
let text = await currentfile.text(); let text = await currentfile.text();
let fileData: FlowType = await JSON.parse(text); let fileData: FlowType = await JSON.parse(text);
console.log(isComponent, fileData);
if ( if (
(!fileData.is_component && isComponent === true) || (!fileData.is_component && isComponent === true) ||

View file

@ -12,7 +12,6 @@ import { APIKindType } from "../types/api";
import { typesContextType } from "../types/typesContext"; import { typesContextType } from "../types/typesContext";
import { alertContext } from "./alertContext"; import { alertContext } from "./alertContext";
import { AuthContext } from "./authContext"; import { AuthContext } from "./authContext";
import { undoRedoContext } from "./undoRedoContext";
//context to share types adn functions from nodes to flow //context to share types adn functions from nodes to flow
@ -44,7 +43,6 @@ export function TypesProvider({ children }: { children: ReactNode }) {
const [fetchError, setFetchError] = useState(false); const [fetchError, setFetchError] = useState(false);
const { setLoading } = useContext(alertContext); const { setLoading } = useContext(alertContext);
const { getAuthentication } = useContext(AuthContext); const { getAuthentication } = useContext(AuthContext);
const { takeSnapshot } = useContext(undoRedoContext);
const [getFilterEdge, setFilterEdge] = useState([]); const [getFilterEdge, setFilterEdge] = useState([]);
useEffect(() => { useEffect(() => {
@ -100,7 +98,6 @@ export function TypesProvider({ children }: { children: ReactNode }) {
} }
function deleteNode(idx: string | Array<string>) { function deleteNode(idx: string | Array<string>) {
takeSnapshot();
if (reactFlowInstance === null) return; if (reactFlowInstance === null) return;
const edges = reactFlowInstance! const edges = reactFlowInstance!
.getEdges() .getEdges()
@ -116,7 +113,6 @@ export function TypesProvider({ children }: { children: ReactNode }) {
}); });
} }
function deleteEdge(idx: string | Array<string>) { function deleteEdge(idx: string | Array<string>) {
takeSnapshot();
reactFlowInstance!.deleteElements({ reactFlowInstance!.deleteElements({
edges: edges:
typeof idx === "string" ? [{ id: idx }] : idx.map((id) => ({ id })), typeof idx === "string" ? [{ id: idx }] : idx.map((id) => ({ id })),

View file

@ -71,7 +71,6 @@ export default function ShareModal({
res?.results?.forEach((element: any) => { res?.results?.forEach((element: any) => {
unavaliableNames.push(element.name); unavaliableNames.push(element.name);
}); });
console.log(unavaliableNames);
setUnavaliableNames(unavaliableNames); setUnavaliableNames(unavaliableNames);
}); });
} }

View file

@ -15,7 +15,6 @@ import ReactFlow, {
EdgeChange, EdgeChange,
NodeChange, NodeChange,
NodeDragHandler, NodeDragHandler,
OnEdgesDelete,
OnSelectionChangeParams, OnSelectionChangeParams,
SelectionDragHandler, SelectionDragHandler,
addEdge, addEdge,
@ -124,6 +123,7 @@ export default function Page({
lastSelection lastSelection
) { ) {
event.preventDefault(); event.preventDefault();
takeSnapshot();
deleteNode(lastSelection.nodes.map((node) => node.id)); deleteNode(lastSelection.nodes.map((node) => node.id));
deleteEdge(lastSelection.edges.map((edge) => edge.id)); deleteEdge(lastSelection.edges.map((edge) => edge.id));
} }
@ -271,11 +271,6 @@ export default function Page({
takeSnapshot(); takeSnapshot();
}, [takeSnapshot]); }, [takeSnapshot]);
const onEdgesDelete: OnEdgesDelete = useCallback(() => {
// 👇 make deleting edges undoable
takeSnapshot();
}, [takeSnapshot]);
const onDragOver = useCallback((event: React.DragEvent) => { const onDragOver = useCallback((event: React.DragEvent) => {
event.preventDefault(); event.preventDefault();
if (event.dataTransfer.types.some((types) => types === "nodedata")) { if (event.dataTransfer.types.some((types) => types === "nodedata")) {
@ -461,7 +456,6 @@ export default function Page({
onSelectionDragStart={onSelectionDragStart} onSelectionDragStart={onSelectionDragStart}
onSelectionEnd={onSelectionEnd} onSelectionEnd={onSelectionEnd}
onSelectionStart={onSelectionStart} onSelectionStart={onSelectionStart}
onEdgesDelete={onEdgesDelete}
connectionLineComponent={ConnectionLineComponent} connectionLineComponent={ConnectionLineComponent}
onDragOver={onDragOver} onDragOver={onDragOver}
onDrop={onDrop} onDrop={onDrop}

View file

@ -17,8 +17,6 @@ export function getTagsIds(
tags: string[], tags: string[],
tagListId: { name: string; id: string }[] tagListId: { name: string; id: string }[]
) { ) {
console.log(tags);
console.log(tagListId);
return tags return tags
.map((tag) => tagListId.find((tagObj) => tagObj.name === tag))! .map((tag) => tagListId.find((tagObj) => tagObj.name === tag))!
.map((tag) => tag!.id); .map((tag) => tag!.id);