Skip to content

Commit 81ea6c2

Browse files
committed
fix(GraphPlayground): implement unique block index generation using timestamp
1 parent 63bf33d commit 81ea6c2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/stories/Playground/GraphPlayground.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export function GraphPLayground() {
146146
drawLine,
147147
});
148148

149+
const getNextBlockIndex = useFn(() => {
150+
return Date.now();
151+
});
152+
149153
const updateVisibleConfig = useFn(() => {
150154
const config = graph.rootStore.getAsConfig();
151155
editorRef?.current.setContent({
@@ -203,8 +207,9 @@ export function GraphPLayground() {
203207
}
204208
let block: TBlock;
205209
const pullSourceAnchor = graph.rootStore.blocksList.getBlockState(sourceBlockId).getAnchorById(sourceAnchorId);
210+
const nextIndex = getNextBlockIndex();
206211
if (pullSourceAnchor?.state.type === EAnchorType.IN) {
207-
block = createActionBlock(point.x - 126, point.y - 63, graph.rootStore.blocksList.$blocksMap.value.size + 1);
212+
block = createActionBlock(point.x - 126, point.y - 63, nextIndex);
208213
graph.api.addBlock(block);
209214
graph.api.addConnection({
210215
sourceBlockId: block.id,
@@ -213,7 +218,7 @@ export function GraphPLayground() {
213218
targetAnchorId: sourceAnchorId,
214219
});
215220
} else {
216-
block = createActionBlock(point.x, point.y - 63, graph.rootStore.blocksList.$blocksMap.value.size + 1);
221+
block = createActionBlock(point.x, point.y - 63, nextIndex);
217222
graph.api.addBlock(block);
218223
graph.api.addConnection({
219224
sourceBlockId: sourceBlockId,
@@ -243,7 +248,8 @@ export function GraphPLayground() {
243248
const rect = graph.api.getUsableRect();
244249
const x = random(rect.x, rect.x + rect.width + 100);
245250
const y = random(rect.y, rect.y + rect.height + 100);
246-
const block = createActionBlock(x, y, graph.rootStore.blocksList.$blocksMap.value.size + 1);
251+
const nextIndex = getNextBlockIndex();
252+
const block = createActionBlock(x, y, nextIndex);
247253
graph.api.addBlock(block);
248254
graph.zoomTo([block.id], { transition: 250 });
249255
updateVisibleConfig();

0 commit comments

Comments
 (0)