From eece3b13f3e19f7699563a0160b155db0cc0a3df Mon Sep 17 00:00:00 2001 From: olehp Date: Wed, 28 Aug 2024 22:53:06 +0300 Subject: [PATCH 1/5] Added Affected endpoint --- .../AffectedEndpointsSelector.stories.tsx | 39 +++++++++++ .../AffectedEndpointsSelector/index.tsx | 65 +++++++++++++++++++ .../AffectedEndpointsSelector/styles.ts | 14 ++++ .../AffectedEndpointsSelector/types.ts | 29 +++++++++ .../InsightCard/EndpointOption/index.tsx | 39 +++++++++++ .../InsightCard/EndpointOption/styles.ts | 59 +++++++++++++++++ .../InsightCard/EndpointOption/types.ts | 14 ++++ .../common/InsightCard/Select/index.tsx | 13 +++- 8 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/AffectedEndpointsSelector.stories.tsx create mode 100644 src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/index.tsx create mode 100644 src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/styles.ts create mode 100644 src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/types.ts create mode 100644 src/components/Insights/InsightsCatalog/InsightsPage/insightCards/common/InsightCard/EndpointOption/index.tsx create mode 100644 src/components/Insights/InsightsCatalog/InsightsPage/insightCards/common/InsightCard/EndpointOption/styles.ts create mode 100644 src/components/Insights/InsightsCatalog/InsightsPage/insightCards/common/InsightCard/EndpointOption/types.ts diff --git a/src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/AffectedEndpointsSelector.stories.tsx b/src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/AffectedEndpointsSelector.stories.tsx new file mode 100644 index 000000000..d9dcaa287 --- /dev/null +++ b/src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/AffectedEndpointsSelector.stories.tsx @@ -0,0 +1,39 @@ +import { Meta, StoryObj } from "@storybook/react"; +import { AffectedEndpointsSelector } from "."; + +// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction +const meta: Meta = { + title: "Insights/InsightsCatalog/InsightPage/AffectedEndpointsSelector", + component: AffectedEndpointsSelector, + parameters: { + // More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout + layout: "fullscreen" + } +}; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = { + args: { + value: "spanCodeObjectId1", + options: [ + { + route: "test", + serviceName: "test1", + spanCodeObjectId: "spanCodeObjectId1" + }, + { + route: "test", + serviceName: "test1", + spanCodeObjectId: "spanCodeObjectId2" + }, + { + route: "test", + serviceName: "test1", + spanCodeObjectId: "spanCodeObjectId2" + } + ] + } +}; diff --git a/src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/index.tsx b/src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/index.tsx new file mode 100644 index 000000000..881d69e85 --- /dev/null +++ b/src/components/Insights/InsightsCatalog/InsightsPage/AffectedEndpointsSelector/index.tsx @@ -0,0 +1,65 @@ +import { ReactNode } from "react"; +import { trimEndpointScheme } from "../../../../../utils/trimEndpointScheme"; +import { EndpointOption } from "../insightCards/common/InsightCard/EndpointOption"; +import { Select } from "../insightCards/common/InsightCard/Select"; +import { CustomContentProps } from "../insightCards/common/InsightCard/Select/types"; +import * as s from "./styles"; +import { AffectedEndpointsSelectorProps, Option } from "./types"; + +const renderOptions = ( + endpoints: Option[], + handleLinkClick: (spanCodeObjectId?: string) => void +): { + label: string; + customContent: (props: CustomContentProps) => ReactNode; + value: string; +}[] => + endpoints.map((x) => { + const spanCodeObjectId = x.spanCodeObjectId; + const route = trimEndpointScheme(x.route); + return { + label: route, + customContent: ({ isSelected, onClick }) => ( + + ), + value: spanCodeObjectId + }; + }); + +export const AffectedEndpointsSelector = ({ + onAssetLinkClick, + insightType, + value, + options, + onChange +}: AffectedEndpointsSelectorProps) => { + const handleSpanLinkClick = (spanCodeObjectId?: string) => { + spanCodeObjectId && onAssetLinkClick(spanCodeObjectId, insightType); + }; + + return ( + { const selected = endpoints.find( (x) => - x.endpointInfo.entrySpanCodeObjectId === selectedOption + x.endpointInfo.entrySpanCodeObjectId === + selectedOption?.spanCodeObjectId ) ?? null; setSelectedEndpoint(selected); }} - options={renderOptions(endpoints, handleSpanLinkClick)} + options={endpoints.map((x) => ({ + route: x.endpointInfo.route, + serviceName: x.endpointInfo.serviceName, + spanCodeObjectId: x.endpointInfo.entrySpanCodeObjectId + }))} + insightType={insight.type} + onAssetLinkClick={handleSpanLinkClick} /> {isJaegerEnabled && selectedEndpoint && ( diff --git a/src/components/Insights/InsightsCatalog/InsightsPage/insightCards/SpanEndpointBottleneckInsightCard/index.tsx b/src/components/Insights/InsightsCatalog/InsightsPage/insightCards/SpanEndpointBottleneckInsightCard/index.tsx index 79efc8b0f..b8e8fa3a8 100644 --- a/src/components/Insights/InsightsCatalog/InsightsPage/insightCards/SpanEndpointBottleneckInsightCard/index.tsx +++ b/src/components/Insights/InsightsCatalog/InsightsPage/insightCards/SpanEndpointBottleneckInsightCard/index.tsx @@ -1,4 +1,4 @@ -import { ReactNode, useState } from "react"; +import { useState } from "react"; import { useGlobalStore } from "../../../../../../containers/Main/stores/useGlobalStore"; import { isNull } from "../../../../../../typeGuards/isNull"; import { getDurationString } from "../../../../../../utils/getDurationString"; @@ -6,37 +6,15 @@ import { trimEndpointScheme } from "../../../../../../utils/trimEndpointScheme"; import { TraceIcon } from "../../../../../common/icons/12px/TraceIcon"; import { Button } from "../../../../../common/v3/Button"; import { Tooltip } from "../../../../../common/v3/Tooltip"; -import { BottleneckEndpointInfo, InsightType, Trace } from "../../../../types"; +import { InsightType, Trace } from "../../../../types"; +import { AffectedEndpointsSelector } from "../../AffectedEndpointsSelector"; import { InsightCard } from "../common/InsightCard"; import { ColumnsContainer } from "../common/InsightCard/ColumnsContainer"; -import { EndpointSelectedOption } from "../common/InsightCard/EndpointSelectedOption"; import { KeyValue } from "../common/InsightCard/KeyValue"; -import { Select } from "../common/InsightCard/Select"; import { ContentContainer, Description, Details } from "../styles"; import * as s from "./styles"; import { SpanEndpointBottleneckInsightCardProps } from "./types"; -const renderOptions = ( - endpoints: BottleneckEndpointInfo[], - handleLinkClick: (spanCodeObjectId?: string) => void -): { label: string; customContent: ReactNode; value: string }[] => - endpoints.map((x) => { - const spanCodeObjectId = x.endpointInfo.spanCodeObjectId; - const route = trimEndpointScheme(x.endpointInfo.route); - return { - label: route, - customContent: ( - - ), - value: spanCodeObjectId - }; - }); - export const SpanEndpointBottleneckInsightCard = ({ insight, onJiraTicketCreate, @@ -100,17 +78,25 @@ export const SpanEndpointBottleneckInsightCard = ({ Affected Endpoints ({slowEndpoints.length}) -