@localstack/appinspector-ui 1.0.39 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4299,21 +4299,6 @@ var getLayoutedNodesAndEdges = (inputNodes, inputEdges) => {
4299
4299
  });
4300
4300
  return { edges: inputEdges, nodes: layoutedNodes };
4301
4301
  };
4302
- var getNodesMinMaxX = (nodes) => {
4303
- if (nodes.length === 0) return { maxX: 0, minX: 0 };
4304
- let minX = Number.POSITIVE_INFINITY;
4305
- let maxX = Number.NEGATIVE_INFINITY;
4306
- for (const node of nodes) {
4307
- minX = Math.min(minX, node.position.x);
4308
- maxX = Math.max(maxX, node.position.x);
4309
- }
4310
- return { maxX, minX };
4311
- };
4312
- var calculateCenterX = (focusNodeX, viewPortPixelWidth, minX, maxX) => {
4313
- const nodeWidth = 200;
4314
- const desiredCenter = focusNodeX + viewPortPixelWidth / 2;
4315
- return Math.min(Math.max(desiredCenter, minX + viewPortPixelWidth / 2), maxX - viewPortPixelWidth / 2 + nodeWidth);
4316
- };
4317
4302
 
4318
4303
  // src/components/trace-graph/xyflow/controls.tsx
4319
4304
  var import_icons_material10 = require("@mui/icons-material");
@@ -4435,13 +4420,10 @@ var TraceGraph = ({
4435
4420
  initialFocusEventId,
4436
4421
  onEventSelect,
4437
4422
  onRefresh,
4438
- spans,
4439
- viewPortPixelWidth
4423
+ spans
4440
4424
  }) => {
4441
4425
  const [nodes, setNodes, onNodesChange] = (0, import_react21.useNodesState)([]);
4442
4426
  const [edges, setEdges] = (0, import_react22.useState)([]);
4443
- const [initialViewSet, setInitialViewSet] = (0, import_react22.useState)(false);
4444
- const { fitView, setCenter } = (0, import_react21.useReactFlow)();
4445
4427
  (0, import_react22.useEffect)(() => {
4446
4428
  const spansMap = /* @__PURE__ */ new Map();
4447
4429
  const rootSpans = [];
@@ -4477,26 +4459,6 @@ var TraceGraph = ({
4477
4459
  setNodes(layoutedNodes);
4478
4460
  setEdges(layoutedEdges);
4479
4461
  }, [spans.data, initialFocusEventId, setNodes]);
4480
- (0, import_react22.useEffect)(() => {
4481
- const shouldSetInitialView = !spans.loading && nodes.length > 0 && !initialViewSet;
4482
- if (shouldSetInitialView) {
4483
- if (initialFocusEventId) {
4484
- const focusNode = nodes.find((node) => node.id === initialFocusEventId);
4485
- if (focusNode) {
4486
- const { maxX, minX } = getNodesMinMaxX(nodes);
4487
- const centerX = calculateCenterX(focusNode.position.x, viewPortPixelWidth, minX, maxX);
4488
- void setCenter(centerX, focusNode.position.y, {
4489
- duration: 500,
4490
- zoom: 0.8
4491
- });
4492
- onEventSelect(focusNode.data.event);
4493
- }
4494
- } else {
4495
- void fitView({ duration: 500 });
4496
- }
4497
- setInitialViewSet(true);
4498
- }
4499
- }, [spans.loading, nodes, initialFocusEventId, viewPortPixelWidth, setCenter, fitView, onEventSelect, initialViewSet]);
4500
4462
  const theme = (0, import_material18.useTheme)();
4501
4463
  return /* @__PURE__ */ (0, import_jsx_runtime139.jsxs)(import_jsx_runtime139.Fragment, { children: [
4502
4464
  spans.error && /* @__PURE__ */ (0, import_jsx_runtime139.jsxs)(
@@ -4517,16 +4479,16 @@ var TraceGraph = ({
4517
4479
  import_react21.ReactFlow,
4518
4480
  {
4519
4481
  "data-testid": "trace-graph",
4520
- defaultViewport: { x: 0, y: 0, zoom: 1 },
4521
4482
  edges,
4522
4483
  fitView: true,
4484
+ fitViewOptions: initialFocusEventId ? { maxZoom: 1, nodes: [{ id: initialFocusEventId }], padding: 0.2 } : void 0,
4523
4485
  maxZoom: 1.5,
4524
4486
  minZoom: 0.1,
4525
4487
  nodes,
4526
4488
  nodesDraggable: false,
4527
4489
  nodeTypes,
4528
4490
  onNodeClick: (_event, node) => {
4529
- onEventSelect(node.data.event);
4491
+ onEventSelect(node.data.event.span_id);
4530
4492
  },
4531
4493
  onNodesChange,
4532
4494
  selectNodesOnDrag: false,
@@ -4591,8 +4553,7 @@ var TraceGraphView = ({
4591
4553
  spans,
4592
4554
  status,
4593
4555
  statusError,
4594
- traceId,
4595
- viewPortPixelWidth
4556
+ traceId
4596
4557
  }) => {
4597
4558
  const shouldShowStatusMessage = Boolean(statusError) || status?.status === "DISABLED";
4598
4559
  return /* @__PURE__ */ (0, import_jsx_runtime140.jsxs)(
@@ -4651,8 +4612,7 @@ var TraceGraphView = ({
4651
4612
  data: spans,
4652
4613
  error: fetchError,
4653
4614
  loading
4654
- },
4655
- viewPortPixelWidth
4615
+ }
4656
4616
  }
4657
4617
  ) })
4658
4618
  }
@@ -4691,35 +4651,20 @@ var TraceGraphPage = ({ onClose, spanId, traceId }) => {
4691
4651
  void fetchSpans();
4692
4652
  }, [fetchSpans]);
4693
4653
  const [open, setOpen] = (0, import_react24.useState)(true);
4694
- const [selectedEvent, setSelectedEvent] = (0, import_react24.useState)();
4695
- const [viewPortPixelWidth, setViewPortPixelWidth] = (0, import_react24.useState)(0);
4696
- const { checkStatus, error: statusError, status } = useStatus();
4697
- const calculateDrawerWidth = (0, import_react24.useCallback)(() => {
4698
- const percentageMatch = /(\d+)%/.exec(DRAWER_WIDTH);
4699
- if (percentageMatch && open) {
4700
- const percentage = Number.parseInt(percentageMatch[1], 10);
4701
- return window.innerWidth * percentage / 100;
4702
- }
4703
- return 0;
4704
- }, [open]);
4654
+ const [selectedEvent, setSelectedEvent] = (0, import_react24.useState)(() => spans?.find((span) => span.span_id === spanId));
4655
+ const spansReference = (0, import_react24.useRef)();
4705
4656
  (0, import_react24.useEffect)(() => {
4706
- const updateViewportWidth = () => {
4707
- const totalWidth = window.innerWidth;
4708
- const drawerPixelWidth = open ? calculateDrawerWidth() : 0;
4709
- setViewPortPixelWidth(totalWidth - drawerPixelWidth);
4710
- };
4711
- updateViewportWidth();
4712
- const timeoutId = setTimeout(updateViewportWidth, 50);
4713
- window.addEventListener("resize", updateViewportWidth);
4714
- return () => {
4715
- window.removeEventListener("resize", updateViewportWidth);
4716
- clearTimeout(timeoutId);
4717
- };
4718
- }, [open, calculateDrawerWidth]);
4719
- const handleEventSelect = (0, import_react24.useCallback)((event) => {
4720
- setSelectedEvent(event);
4657
+ if (!spansReference.current && spans) {
4658
+ setSelectedEvent(spans.find((span) => span.span_id === spanId));
4659
+ spansReference.current = spans;
4660
+ }
4661
+ }, [spans, setSelectedEvent, spanId]);
4662
+ const { checkStatus, error: statusError, status } = useStatus();
4663
+ const handleEventSelect = (0, import_react24.useCallback)((spanId2) => {
4664
+ const span = spans?.find((s) => s.span_id === spanId2);
4665
+ setSelectedEvent(span);
4721
4666
  setOpen(true);
4722
- }, []);
4667
+ }, [spans]);
4723
4668
  const handleRetry = (0, import_react24.useCallback)(() => {
4724
4669
  void checkStatus();
4725
4670
  }, [checkStatus]);
@@ -4744,8 +4689,7 @@ var TraceGraphPage = ({ onClose, spanId, traceId }) => {
4744
4689
  spans,
4745
4690
  status,
4746
4691
  statusError,
4747
- traceId,
4748
- viewPortPixelWidth
4692
+ traceId
4749
4693
  }
4750
4694
  );
4751
4695
  };