fix(App.tsx): remove unused useContext import and hardReset function call
refactor(App.tsx): remove hardReset function call and add comment indicating any reset function refactor(flowsContext.tsx): remove hardReset function and update comment for tabId property refactor(flowsContext.tsx): remove hardReset function from useEffect hook refactor(flowsContext.tsx): remove hardReset function and update comment for hardReset function refactor(flowManagerStore.ts): add nodeId property and incrementNodeId function refactor(tabs/index.ts): remove hardReset function from FlowsContextType
This commit is contained in:
parent
aa44a70a02
commit
c61c67cc7c
4 changed files with 10 additions and 23 deletions
|
|
@ -16,7 +16,6 @@ import {
|
||||||
FETCH_ERROR_MESSAGE,
|
FETCH_ERROR_MESSAGE,
|
||||||
} from "./constants/constants";
|
} from "./constants/constants";
|
||||||
import { alertContext } from "./contexts/alertContext";
|
import { alertContext } from "./contexts/alertContext";
|
||||||
import { FlowsContext } from "./contexts/flowsContext";
|
|
||||||
import { locationContext } from "./contexts/locationContext";
|
import { locationContext } from "./contexts/locationContext";
|
||||||
import { typesContext } from "./contexts/typesContext";
|
import { typesContext } from "./contexts/typesContext";
|
||||||
import Router from "./routes";
|
import Router from "./routes";
|
||||||
|
|
@ -30,7 +29,6 @@ export default function App() {
|
||||||
setShowSideBar(true);
|
setShowSideBar(true);
|
||||||
setIsStackedOpen(true);
|
setIsStackedOpen(true);
|
||||||
}, [location.pathname, setCurrent, setIsStackedOpen, setShowSideBar]);
|
}, [location.pathname, setCurrent, setIsStackedOpen, setShowSideBar]);
|
||||||
const { hardReset } = useContext(FlowsContext);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
errorData,
|
errorData,
|
||||||
|
|
@ -136,10 +134,7 @@ export default function App() {
|
||||||
<div className="flex h-full flex-col">
|
<div className="flex h-full flex-col">
|
||||||
<ErrorBoundary
|
<ErrorBoundary
|
||||||
onReset={() => {
|
onReset={() => {
|
||||||
window.localStorage.removeItem("tabsData");
|
// any reset function
|
||||||
window.localStorage.clear();
|
|
||||||
hardReset();
|
|
||||||
window.location.href = window.location.href;
|
|
||||||
}}
|
}}
|
||||||
FallbackComponent={CrashErrorComponent}
|
FallbackComponent={CrashErrorComponent}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ import { typesContext } from "./typesContext";
|
||||||
const uid = new ShortUniqueId({ length: 5 });
|
const uid = new ShortUniqueId({ length: 5 });
|
||||||
|
|
||||||
const FlowsContextInitialValue: FlowsContextType = {
|
const FlowsContextInitialValue: FlowsContextType = {
|
||||||
|
//Remove tab id and get current id from url
|
||||||
tabId: "",
|
tabId: "",
|
||||||
setTabId: (index: string) => {},
|
setTabId: (index: string) => {},
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
|
|
@ -83,7 +84,6 @@ const FlowsContextInitialValue: FlowsContextType = {
|
||||||
uploadFlow: async () => "",
|
uploadFlow: async () => "",
|
||||||
isBuilt: false,
|
isBuilt: false,
|
||||||
setIsBuilt: (state: boolean) => {},
|
setIsBuilt: (state: boolean) => {},
|
||||||
hardReset: () => {},
|
|
||||||
saveFlow: async (flow?: FlowType, silent?: boolean) => {},
|
saveFlow: async (flow?: FlowType, silent?: boolean) => {},
|
||||||
lastCopiedSelection: null,
|
lastCopiedSelection: null,
|
||||||
setLastCopiedSelection: (selection: any) => {},
|
setLastCopiedSelection: (selection: any) => {},
|
||||||
|
|
@ -209,12 +209,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
setEdgesInternal(newChange);
|
setEdgesInternal(newChange);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isAuthenticated) {
|
|
||||||
hardReset();
|
|
||||||
}
|
|
||||||
}, [isAuthenticated]);
|
|
||||||
|
|
||||||
const newNodeId = useRef(uid());
|
const newNodeId = useRef(uid());
|
||||||
|
|
||||||
function incrementNodeId() {
|
function incrementNodeId() {
|
||||||
|
|
@ -295,14 +289,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
setFlows(tabsData);
|
setFlows(tabsData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hardReset() {
|
|
||||||
newNodeId.current = uid();
|
|
||||||
setTabId("");
|
|
||||||
setFlows([]);
|
|
||||||
setIsLoading(true);
|
|
||||||
setId(uid());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the current flow as a JSON file
|
* Downloads the current flow as a JSON file
|
||||||
*/
|
*/
|
||||||
|
|
@ -799,7 +785,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
setIsBuilt,
|
setIsBuilt,
|
||||||
lastCopiedSelection,
|
lastCopiedSelection,
|
||||||
setLastCopiedSelection,
|
setLastCopiedSelection,
|
||||||
hardReset,
|
|
||||||
tabId,
|
tabId,
|
||||||
setTabId,
|
setTabId,
|
||||||
flows,
|
flows,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@ import {
|
||||||
applyEdgeChanges,
|
applyEdgeChanges,
|
||||||
applyNodeChanges,
|
applyNodeChanges,
|
||||||
} from "reactflow";
|
} from "reactflow";
|
||||||
|
import ShortUniqueId from "short-unique-id";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
const uid = new ShortUniqueId({ length: 5 });
|
||||||
|
|
||||||
type RFState = {
|
type RFState = {
|
||||||
nodes: Node[];
|
nodes: Node[];
|
||||||
|
|
@ -27,6 +29,8 @@ type RFState = {
|
||||||
position: { x: number; y: number; paneX?: number; paneY?: number }
|
position: { x: number; y: number; paneX?: number; paneY?: number }
|
||||||
) => void;
|
) => void;
|
||||||
lastCopiedSelection: { nodes: any; edges: any };
|
lastCopiedSelection: { nodes: any; edges: any };
|
||||||
|
nodeId: string;
|
||||||
|
incrementNodeId: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
||||||
|
|
@ -63,6 +67,10 @@ const useStore = create<RFState>((set, get) => ({
|
||||||
},
|
},
|
||||||
paste: (selection, position) => {},
|
paste: (selection, position) => {},
|
||||||
lastCopiedSelection: { nodes: [], edges: [] },
|
lastCopiedSelection: { nodes: [], edges: [] },
|
||||||
|
nodeId: uid(),
|
||||||
|
incrementNodeId: () => {
|
||||||
|
set((state) => ({ nodeId: uid() }));
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default useStore;
|
export default useStore;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ export type FlowsContextType = {
|
||||||
isComponent?: boolean;
|
isComponent?: boolean;
|
||||||
position?: XYPosition;
|
position?: XYPosition;
|
||||||
}) => Promise<String | never>;
|
}) => Promise<String | never>;
|
||||||
hardReset: () => void;
|
|
||||||
getNodeId: (nodeType: string) => string;
|
getNodeId: (nodeType: string) => string;
|
||||||
isPending: boolean;
|
isPending: boolean;
|
||||||
setPending: (pending: boolean) => void;
|
setPending: (pending: boolean) => void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue