@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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/pages/spans-list-page.tsx
2
2
  import { Box as Box18 } from "@mui/material";
3
- import { useCallback as useCallback5, useEffect as useEffect6, useMemo as useMemo6, useRef as useRef3, useState as useState9 } from "react";
3
+ import { useCallback as useCallback5, useEffect as useEffect6, useMemo as useMemo6, useRef as useRef4, useState as useState9 } from "react";
4
4
 
5
5
  // src/api/use-api.tsx
6
6
  import { createContext, useContext } from "react";
@@ -3208,7 +3208,7 @@ import { ArrowBack } from "@mui/icons-material";
3208
3208
  import { Box as Box17, Button as Button5, Drawer, Paper as Paper2 } from "@mui/material";
3209
3209
  import { styled } from "@mui/material/styles";
3210
3210
  import { ReactFlowProvider } from "@xyflow/react";
3211
- import { useCallback as useCallback4, useEffect as useEffect5, useState as useState8 } from "react";
3211
+ import { useCallback as useCallback4, useEffect as useEffect5, useRef as useRef3, useState as useState8 } from "react";
3212
3212
 
3213
3213
  // src/components/event-details/event-details.tsx
3214
3214
  import { Box as Box13, Chip as Chip3, Divider as Divider2, Stack, Typography as Typography9 } from "@mui/material";
@@ -4034,7 +4034,7 @@ function renderKeyValue(key, value) {
4034
4034
  // src/components/trace-graph/trace-graph.tsx
4035
4035
  import "@xyflow/react/dist/base.css";
4036
4036
  import { Alert as Alert3, Button as Button4, useTheme as useTheme2 } from "@mui/material";
4037
- import { Background, ReactFlow, useNodesState, useReactFlow as useReactFlow2 } from "@xyflow/react";
4037
+ import { Background, ReactFlow, useNodesState } from "@xyflow/react";
4038
4038
  import { useEffect as useEffect4, useState as useState7 } from "react";
4039
4039
 
4040
4040
  // src/components/trace-graph/service-node.tsx
@@ -4262,21 +4262,6 @@ var getLayoutedNodesAndEdges = (inputNodes, inputEdges) => {
4262
4262
  });
4263
4263
  return { edges: inputEdges, nodes: layoutedNodes };
4264
4264
  };
4265
- var getNodesMinMaxX = (nodes) => {
4266
- if (nodes.length === 0) return { maxX: 0, minX: 0 };
4267
- let minX = Number.POSITIVE_INFINITY;
4268
- let maxX = Number.NEGATIVE_INFINITY;
4269
- for (const node of nodes) {
4270
- minX = Math.min(minX, node.position.x);
4271
- maxX = Math.max(maxX, node.position.x);
4272
- }
4273
- return { maxX, minX };
4274
- };
4275
- var calculateCenterX = (focusNodeX, viewPortPixelWidth, minX, maxX) => {
4276
- const nodeWidth = 200;
4277
- const desiredCenter = focusNodeX + viewPortPixelWidth / 2;
4278
- return Math.min(Math.max(desiredCenter, minX + viewPortPixelWidth / 2), maxX - viewPortPixelWidth / 2 + nodeWidth);
4279
- };
4280
4265
 
4281
4266
  // src/components/trace-graph/xyflow/controls.tsx
4282
4267
  import { Add, FitScreen, Remove } from "@mui/icons-material";
@@ -4398,13 +4383,10 @@ var TraceGraph = ({
4398
4383
  initialFocusEventId,
4399
4384
  onEventSelect,
4400
4385
  onRefresh,
4401
- spans,
4402
- viewPortPixelWidth
4386
+ spans
4403
4387
  }) => {
4404
4388
  const [nodes, setNodes, onNodesChange] = useNodesState([]);
4405
4389
  const [edges, setEdges] = useState7([]);
4406
- const [initialViewSet, setInitialViewSet] = useState7(false);
4407
- const { fitView, setCenter } = useReactFlow2();
4408
4390
  useEffect4(() => {
4409
4391
  const spansMap = /* @__PURE__ */ new Map();
4410
4392
  const rootSpans = [];
@@ -4440,26 +4422,6 @@ var TraceGraph = ({
4440
4422
  setNodes(layoutedNodes);
4441
4423
  setEdges(layoutedEdges);
4442
4424
  }, [spans.data, initialFocusEventId, setNodes]);
4443
- useEffect4(() => {
4444
- const shouldSetInitialView = !spans.loading && nodes.length > 0 && !initialViewSet;
4445
- if (shouldSetInitialView) {
4446
- if (initialFocusEventId) {
4447
- const focusNode = nodes.find((node) => node.id === initialFocusEventId);
4448
- if (focusNode) {
4449
- const { maxX, minX } = getNodesMinMaxX(nodes);
4450
- const centerX = calculateCenterX(focusNode.position.x, viewPortPixelWidth, minX, maxX);
4451
- void setCenter(centerX, focusNode.position.y, {
4452
- duration: 500,
4453
- zoom: 0.8
4454
- });
4455
- onEventSelect(focusNode.data.event);
4456
- }
4457
- } else {
4458
- void fitView({ duration: 500 });
4459
- }
4460
- setInitialViewSet(true);
4461
- }
4462
- }, [spans.loading, nodes, initialFocusEventId, viewPortPixelWidth, setCenter, fitView, onEventSelect, initialViewSet]);
4463
4425
  const theme = useTheme2();
4464
4426
  return /* @__PURE__ */ jsxs132(Fragment6, { children: [
4465
4427
  spans.error && /* @__PURE__ */ jsxs132(
@@ -4480,16 +4442,16 @@ var TraceGraph = ({
4480
4442
  ReactFlow,
4481
4443
  {
4482
4444
  "data-testid": "trace-graph",
4483
- defaultViewport: { x: 0, y: 0, zoom: 1 },
4484
4445
  edges,
4485
4446
  fitView: true,
4447
+ fitViewOptions: initialFocusEventId ? { maxZoom: 1, nodes: [{ id: initialFocusEventId }], padding: 0.2 } : void 0,
4486
4448
  maxZoom: 1.5,
4487
4449
  minZoom: 0.1,
4488
4450
  nodes,
4489
4451
  nodesDraggable: false,
4490
4452
  nodeTypes,
4491
4453
  onNodeClick: (_event, node) => {
4492
- onEventSelect(node.data.event);
4454
+ onEventSelect(node.data.event.span_id);
4493
4455
  },
4494
4456
  onNodesChange,
4495
4457
  selectNodesOnDrag: false,
@@ -4554,8 +4516,7 @@ var TraceGraphView = ({
4554
4516
  spans,
4555
4517
  status,
4556
4518
  statusError,
4557
- traceId,
4558
- viewPortPixelWidth
4519
+ traceId
4559
4520
  }) => {
4560
4521
  const shouldShowStatusMessage = Boolean(statusError) || status?.status === "DISABLED";
4561
4522
  return /* @__PURE__ */ jsxs133(
@@ -4614,8 +4575,7 @@ var TraceGraphView = ({
4614
4575
  data: spans,
4615
4576
  error: fetchError,
4616
4577
  loading
4617
- },
4618
- viewPortPixelWidth
4578
+ }
4619
4579
  }
4620
4580
  ) })
4621
4581
  }
@@ -4654,35 +4614,20 @@ var TraceGraphPage = ({ onClose, spanId, traceId }) => {
4654
4614
  void fetchSpans();
4655
4615
  }, [fetchSpans]);
4656
4616
  const [open, setOpen] = useState8(true);
4657
- const [selectedEvent, setSelectedEvent] = useState8();
4658
- const [viewPortPixelWidth, setViewPortPixelWidth] = useState8(0);
4659
- const { checkStatus, error: statusError, status } = useStatus();
4660
- const calculateDrawerWidth = useCallback4(() => {
4661
- const percentageMatch = /(\d+)%/.exec(DRAWER_WIDTH);
4662
- if (percentageMatch && open) {
4663
- const percentage = Number.parseInt(percentageMatch[1], 10);
4664
- return window.innerWidth * percentage / 100;
4665
- }
4666
- return 0;
4667
- }, [open]);
4617
+ const [selectedEvent, setSelectedEvent] = useState8(() => spans?.find((span) => span.span_id === spanId));
4618
+ const spansReference = useRef3();
4668
4619
  useEffect5(() => {
4669
- const updateViewportWidth = () => {
4670
- const totalWidth = window.innerWidth;
4671
- const drawerPixelWidth = open ? calculateDrawerWidth() : 0;
4672
- setViewPortPixelWidth(totalWidth - drawerPixelWidth);
4673
- };
4674
- updateViewportWidth();
4675
- const timeoutId = setTimeout(updateViewportWidth, 50);
4676
- window.addEventListener("resize", updateViewportWidth);
4677
- return () => {
4678
- window.removeEventListener("resize", updateViewportWidth);
4679
- clearTimeout(timeoutId);
4680
- };
4681
- }, [open, calculateDrawerWidth]);
4682
- const handleEventSelect = useCallback4((event) => {
4683
- setSelectedEvent(event);
4620
+ if (!spansReference.current && spans) {
4621
+ setSelectedEvent(spans.find((span) => span.span_id === spanId));
4622
+ spansReference.current = spans;
4623
+ }
4624
+ }, [spans, setSelectedEvent, spanId]);
4625
+ const { checkStatus, error: statusError, status } = useStatus();
4626
+ const handleEventSelect = useCallback4((spanId2) => {
4627
+ const span = spans?.find((s) => s.span_id === spanId2);
4628
+ setSelectedEvent(span);
4684
4629
  setOpen(true);
4685
- }, []);
4630
+ }, [spans]);
4686
4631
  const handleRetry = useCallback4(() => {
4687
4632
  void checkStatus();
4688
4633
  }, [checkStatus]);
@@ -4707,8 +4652,7 @@ var TraceGraphPage = ({ onClose, spanId, traceId }) => {
4707
4652
  spans,
4708
4653
  status,
4709
4654
  statusError,
4710
- traceId,
4711
- viewPortPixelWidth
4655
+ traceId
4712
4656
  }
4713
4657
  );
4714
4658
  };
@@ -4720,9 +4664,9 @@ var SpansListPage = () => {
4720
4664
  const api = useAppInspectorApi();
4721
4665
  const [spans, setSpans] = useState9();
4722
4666
  const [loading, setLoading] = useState9(false);
4723
- const hasFetched = useRef3(false);
4667
+ const hasFetched = useRef4(false);
4724
4668
  const [includeReadOperations, setIncludeReadOperations] = useLocalStorage("includeReadOperations", false);
4725
- const mapPageToNextCursor = useRef3({});
4669
+ const mapPageToNextCursor = useRef4({});
4726
4670
  const [page, setPage] = useState9(0);
4727
4671
  const [pageSize, setPageSize] = useState9(100);
4728
4672
  const [spanCount, setSpanCount] = useState9(0);