using new uid

This commit is contained in:
anovazzi1 2023-06-13 21:45:47 -03:00
commit 499ebad8d9
3 changed files with 22 additions and 9 deletions

View file

@ -49,6 +49,7 @@
"remark-gfm": "^3.0.1", "remark-gfm": "^3.0.1",
"remark-math": "^5.1.1", "remark-math": "^5.1.1",
"shadcn-ui": "^0.1.3", "shadcn-ui": "^0.1.3",
"short-unique-id": "^4.4.4",
"switch": "^0.0.0", "switch": "^0.0.0",
"table": "^6.8.1", "table": "^6.8.1",
"tailwind-merge": "^1.13.0", "tailwind-merge": "^1.13.0",
@ -8407,6 +8408,15 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/short-unique-id": {
"version": "4.4.4",
"resolved": "https://registry.npmjs.org/short-unique-id/-/short-unique-id-4.4.4.tgz",
"integrity": "sha512-oLF1NCmtbiTWl2SqdXZQbo5KM1b7axdp0RgQLq8qCBBLoq+o3A5wmLrNM6bZIh54/a8BJ3l69kTXuxwZ+XCYuw==",
"bin": {
"short-unique-id": "bin/short-unique-id",
"suid": "bin/short-unique-id"
}
},
"node_modules/side-channel": { "node_modules/side-channel": {
"version": "1.0.4", "version": "1.0.4",
"dev": true, "dev": true,

View file

@ -44,6 +44,7 @@
"remark-gfm": "^3.0.1", "remark-gfm": "^3.0.1",
"remark-math": "^5.1.1", "remark-math": "^5.1.1",
"shadcn-ui": "^0.1.3", "shadcn-ui": "^0.1.3",
"short-unique-id": "^4.4.4",
"switch": "^0.0.0", "switch": "^0.0.0",
"table": "^6.8.1", "table": "^6.8.1",
"tailwind-merge": "^1.13.0", "tailwind-merge": "^1.13.0",

View file

@ -17,10 +17,12 @@ import {
import { alertContext } from "./alertContext"; import { alertContext } from "./alertContext";
import { typesContext } from "./typesContext"; import { typesContext } from "./typesContext";
import { APITemplateType, TemplateVariableType } from "../types/api"; import { APITemplateType, TemplateVariableType } from "../types/api";
import { v4 as uuidv4 } from "uuid"; import ShortUniqueId from "short-unique-id";
import { addEdge } from "reactflow"; import { addEdge } from "reactflow";
import _ from "lodash"; import _ from "lodash";
const uid = new ShortUniqueId({ length: 4 });
const TabsContextInitialValue: TabsContextType = { const TabsContextInitialValue: TabsContextType = {
save: () => {}, save: () => {},
tabIndex: 0, tabIndex: 0,
@ -29,7 +31,7 @@ const TabsContextInitialValue: TabsContextType = {
removeFlow: (id: string) => {}, removeFlow: (id: string) => {},
addFlow: (flowData?: any) => {}, addFlow: (flowData?: any) => {},
updateFlow: (newFlow: FlowType) => {}, updateFlow: (newFlow: FlowType) => {},
incrementNodeId: () => uuidv4(), incrementNodeId: () => uid(),
downloadFlow: (flow: FlowType) => {}, downloadFlow: (flow: FlowType) => {},
uploadFlow: () => {}, uploadFlow: () => {},
hardReset: () => {}, hardReset: () => {},
@ -53,13 +55,13 @@ export function TabsProvider({ children }: { children: ReactNode }) {
const { setErrorData, setNoticeData } = useContext(alertContext); const { setErrorData, setNoticeData } = useContext(alertContext);
const [tabIndex, setTabIndex] = useState(0); const [tabIndex, setTabIndex] = useState(0);
const [flows, setFlows] = useState<Array<FlowType>>([]); const [flows, setFlows] = useState<Array<FlowType>>([]);
const [id, setId] = useState(uuidv4()); const [id, setId] = useState(uid());
const { templates, reactFlowInstance } = useContext(typesContext); const { templates, reactFlowInstance } = useContext(typesContext);
const [lastCopiedSelection, setLastCopiedSelection] = useState(null); const [lastCopiedSelection, setLastCopiedSelection] = useState(null);
const newNodeId = useRef(uuidv4()); const newNodeId = useRef(uid());
function incrementNodeId() { function incrementNodeId() {
newNodeId.current = uuidv4(); newNodeId.current = uid();
return newNodeId.current; return newNodeId.current;
} }
function save() { function save() {
@ -144,10 +146,10 @@ export function TabsProvider({ children }: { children: ReactNode }) {
}, [flows, id, tabIndex, newNodeId]); }, [flows, id, tabIndex, newNodeId]);
function hardReset() { function hardReset() {
newNodeId.current = uuidv4(); newNodeId.current = uid();
setTabIndex(0); setTabIndex(0);
setFlows([]); setFlows([]);
setId(uuidv4()); setId(uid());
} }
/** /**
@ -362,12 +364,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
let newFlow: FlowType = { let newFlow: FlowType = {
description, description,
name: flow?.name ?? "New Flow", name: flow?.name ?? "New Flow",
id: uuidv4(), id: uid(),
data, data,
}; };
// Increment the ID counter. // Increment the ID counter.
setId(uuidv4()); setId(uid());
// Add the new flow to the list of flows. // Add the new flow to the list of flows.