Skip to content

Commit 7a51aa3

Browse files
authored
fix: fix way to select rect for zoomToBlocks (#187)
1 parent f303aff commit 7a51aa3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/api/PublicGraphApi.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { selectBlockById } from "../store/block/selectors";
1010
import { TConnection, TConnectionId } from "../store/connection/ConnectionState";
1111
import { selectConnectionById } from "../store/connection/selectors";
1212
import { TGraphSettingsConfig } from "../store/settings";
13-
import { getElementsRect, startAnimation } from "../utils/functions";
13+
import { getBlocksRect, getElementsRect, startAnimation } from "../utils/functions";
1414
import { TRect } from "../utils/types/shapes";
1515

1616
export type ZoomConfig = {
@@ -36,10 +36,13 @@ export class PublicGraphApi {
3636
* ```
3737
*/
3838
public zoomToBlocks(blockIds: TBlockId[], zoomConfig?: ZoomConfig) {
39-
return this.zoomToElements(
40-
this.graph.rootStore.blocksList.getBlockStates(blockIds).map((blockState) => blockState.getViewComponent()),
41-
zoomConfig
42-
);
39+
const blocks = this.graph.rootStore.blocksList.getBlocks(blockIds);
40+
if (blocks.length === 0) {
41+
return false;
42+
}
43+
const blocksRect = getBlocksRect(blocks);
44+
this.zoomToRect(blocksRect, zoomConfig);
45+
return true;
4346
}
4447

4548
/**

src/store/block/BlocksList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,6 @@ export class BlockListStore {
446446
* @returns {BlockState[]} Block states
447447
*/
448448
public getBlockStates(ids: BlockState["id"][]) {
449-
return ids.map((id) => this.getBlockState(id)).filter(Boolean);
449+
return ids.map((id) => this.getBlockState(id)).filter((block): block is BlockState => block !== undefined);
450450
}
451451
}

0 commit comments

Comments
 (0)