1- import type { KeyboardEvent } from "react" ;
21import { useCallback , useEffect , useState } from "react" ;
3- import { actions as globalActions } from "../../actions" ;
42import { usePersistence } from "../../hooks/usePersistence" ;
5- import { usePrevious } from "../../hooks/usePrevious" ;
6- import { useConfigSelector } from "../../store/config/useConfigSelector" ;
7- import { useInsightsSelector } from "../../store/insights/useInsightsSelector" ;
83import { useStore } from "../../store/useStore" ;
94import { isUndefined } from "../../typeGuards/isUndefined" ;
105import { changeScope } from "../../utils/actions/changeScope" ;
11- import { RegistrationDialog } from "../common/RegistrationDialog" ;
12- import type { RegistrationFormValues } from "../common/RegistrationDialog/types" ;
136import { useHistory } from "../Main/useHistory" ;
14- import { EmptyState } from "./EmptyState" ;
157import { useInsightsData } from "./hooks/useInsightsData" ;
16- import { InsightsCatalog } from "./InsightsCatalog" ;
17- import { InsightTicketRenderer } from "./InsightTicketRenderer" ;
18- import * as s from "./styles" ;
8+ import { InsightsContent } from "./InsightsContent" ;
199import type {
2010 GenericCodeObjectInsight ,
2111 InsightTicketInfo ,
@@ -30,16 +20,7 @@ export const Insights = ({ insightViewType }: InsightsProps) => {
3020 const { data, isLoading, refresh } = useInsightsData ( ) ;
3121 const [ infoToOpenJiraTicket , setInfoToOpenJiraTicket ] =
3222 useState < InsightTicketInfo < GenericCodeObjectInsight > > ( ) ;
33- const { backendInfo, userRegistrationEmail, environments } =
34- useConfigSelector ( ) ;
35- const previousUserRegistrationEmail = usePrevious ( userRegistrationEmail ) ;
36- const [ isRegistrationInProgress , setIsRegistrationInProgress ] =
37- useState ( false ) ;
38- const isRegistrationEnabled = false ;
39- const isRegistrationRequired =
40- isRegistrationEnabled && ! userRegistrationEmail ;
4123 const { setInsightViewType, resetInsights : reset } = useStore . getState ( ) ;
42- const { insightViewType : storedInsightViewType } = useInsightsSelector ( ) ;
4324 const { goTo } = useHistory ( ) ;
4425 const [ isInsightJiraTicketHintShown , setIsInsightJiraTicketHintShown ] =
4526 usePersistence < isInsightJiraTicketHintShownPayload > (
@@ -61,19 +42,6 @@ export const Insights = ({ insightViewType }: InsightsProps) => {
6142 setInsightViewType ( insightViewType ) ;
6243 } , [ insightViewType , setInsightViewType ] ) ;
6344
64- useEffect ( ( ) => {
65- if (
66- previousUserRegistrationEmail !== userRegistrationEmail &&
67- isRegistrationInProgress
68- ) {
69- setIsRegistrationInProgress ( false ) ;
70- }
71- } , [
72- userRegistrationEmail ,
73- isRegistrationInProgress ,
74- previousUserRegistrationEmail
75- ] ) ;
76-
7745 const handleJiraTicketPopupOpen = useCallback (
7846 ( insight : GenericCodeObjectInsight , spanCodeObjectId ?: string ) => {
7947 setInfoToOpenJiraTicket ( { insight, spanCodeObjectId } ) ;
@@ -86,91 +54,21 @@ export const Insights = ({ insightViewType }: InsightsProps) => {
8654 setInfoToOpenJiraTicket ( undefined ) ;
8755 } ;
8856
89- const handleRegistrationSubmit = ( formData : RegistrationFormValues ) => {
90- window . sendMessageToDigma ( {
91- action : globalActions . PERSONALIZE_REGISTER ,
92- payload : {
93- ...formData ,
94- scope : "insights view jira ticket info"
95- }
96- } ) ;
97-
98- setIsRegistrationInProgress ( true ) ;
99- } ;
100-
101- const handleRegistrationDialogClose = ( ) => {
102- setInfoToOpenJiraTicket ( undefined ) ;
103- } ;
104-
105- const handleOverlayKeyDown = ( e : KeyboardEvent < HTMLDivElement > ) => {
106- if ( e . key === "Escape" ) {
107- setInfoToOpenJiraTicket ( undefined ) ;
108- }
109- } ;
110-
111- const renderContent = ( ) : JSX . Element => {
112- const isInitialLoading =
113- ( ! data && isLoading ) || ! backendInfo || ! storedInsightViewType ;
114-
115- const handleGoToTab = ( tabId : string ) => {
116- goTo ( `/${ tabId } ` ) ;
117- } ;
118-
119- if ( isInitialLoading ) {
120- return < EmptyState preset = { "loading" } /> ;
121- }
122-
123- if ( ! environments ?. length ) {
124- return < EmptyState preset = { "noDataYet" } /> ;
125- }
126-
127- // switch (data?.insightsStatus) {
128- // case InsightsStatus.STARTUP:
129- // return <EmptyState preset={"nothingToShow"} />;
130- // case InsightsStatus.NO_INSIGHTS:
131- // return <EmptyState preset={"noInsights"} />;
132- // case InsightsStatus.INSIGHT_PENDING:
133- // return <EmptyState preset={"processing"} />;
134- // case InsightsStatus.NO_SPANS_DATA:
135- // return <EmptyState preset={"noDataYet"} />;
136- // case InsightsStatus.NO_OBSERVABILITY:
137- // return <EmptyState preset={"noObservability"} />;
138- // case InsightsStatus.DEFAULT:
139- // default:
140- return (
141- < InsightsCatalog
142- onJiraTicketCreate = { handleJiraTicketPopupOpen }
143- onRefresh = { refresh }
144- onGoToTab = { handleGoToTab }
145- onScopeChange = { changeScope }
146- isJiraTicketHintEnabled = { isJiraTicketHintEnabled }
147- />
148- ) ;
149- // }
57+ const handleGoToTab = ( tabId : string ) => {
58+ goTo ( `/${ tabId } ` ) ;
15059 } ;
15160
15261 return (
153- < s . Container >
154- { renderContent ( ) }
155- { infoToOpenJiraTicket && (
156- < s . Overlay onKeyDown = { handleOverlayKeyDown } tabIndex = { - 1 } >
157- < s . PopupContainer >
158- { isRegistrationRequired ? (
159- < RegistrationDialog
160- onSubmit = { handleRegistrationSubmit }
161- onClose = { handleRegistrationDialogClose }
162- isRegistrationInProgress = { isRegistrationInProgress }
163- />
164- ) : (
165- < InsightTicketRenderer
166- data = { infoToOpenJiraTicket }
167- onClose = { handleJiraTicketPopupClose }
168- backendInfo = { backendInfo }
169- />
170- ) }
171- </ s . PopupContainer >
172- </ s . Overlay >
173- ) }
174- </ s . Container >
62+ < InsightsContent
63+ onScopeChange = { changeScope }
64+ onGoToTab = { handleGoToTab }
65+ isLoading = { isLoading }
66+ data = { data }
67+ onRefresh = { refresh }
68+ isJiraTicketHintEnabled = { isJiraTicketHintEnabled }
69+ onJiraTicketPopupOpen = { handleJiraTicketPopupOpen }
70+ onJiraTicketPopupClose = { handleJiraTicketPopupClose }
71+ infoToOpenJiraTicket = { infoToOpenJiraTicket }
72+ />
17573 ) ;
17674} ;
0 commit comments