Skip to content

Commit

Permalink
revert changes in app and move to udcduck
Browse files Browse the repository at this point in the history
  • Loading branch information
daveajrussell committed Oct 30, 2024
1 parent 83eb87f commit 9d212e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 47 deletions.
67 changes: 21 additions & 46 deletions src/browser/modules/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { setEditorTheme } from 'neo4j-arc/cypher-language-support'
import React, { useCallback, useEffect, useRef } from 'react'
import React, { useEffect, useRef } from 'react'
import { connect } from 'react-redux'
import { withBus } from 'react-suber'
import { ThemeProvider } from 'styled-components'
Expand Down Expand Up @@ -96,10 +96,6 @@ import {
updateUdcData
} from 'shared/modules/udc/udcDuck'
import { getTelemetrySettings } from 'shared/utils/selectors'
import {
PREVIEW_EVENT,
trackPageLoad
} from 'shared/modules/preview/previewDuck'

export const MAIN_WRAPPER_DOM_ID = 'MAIN_WRAPPER_DOM_ID'

Expand All @@ -123,56 +119,36 @@ export function App(props: any) {
const eventMetricsCallback = useRef((_: MetricsData) => _)
const segmentTrackCallback = useRef((_: MetricsData) => _)

const invokeTrackingCallbacks = useCallback(
({ category, label, data }: MetricsData) => {
if (!isRunningE2ETest() && props.telemetrySettings.allowUserStats) {
const extendedData = {
browserVersion: version,
neo4jEdition: props.edition,
connectedTo: props.connectedTo,
...data
}

eventMetricsCallback &&
eventMetricsCallback.current &&
eventMetricsCallback.current({ category, label, data: extendedData })

segmentTrackCallback &&
segmentTrackCallback.current &&
segmentTrackCallback.current({ category, label, data: extendedData })
}
},
[props.telemetrySettings.allowUserStats]
)

useEffect(() => {
const unsub =
props.bus &&
props.bus.take(METRICS_EVENT, (metricsData: MetricsData) => {
invokeTrackingCallbacks(metricsData)
})
return () => unsub && unsub()
}, [props.bus, invokeTrackingCallbacks])

useEffect(() => {
const unsub =
props.bus &&
props.bus.take(PREVIEW_EVENT, (metricsData: MetricsData) => {
invokeTrackingCallbacks(metricsData)
})
props.bus.take(
METRICS_EVENT,
({ category, label, data: originalData }: MetricsData) => {
if (!isRunningE2ETest() && props.telemetrySettings.allowUserStats) {
const data = {
browserVersion: version,
neo4jEdition: props.edition,
connectedTo: props.connectedTo,
...originalData
}
eventMetricsCallback &&
eventMetricsCallback.current &&
eventMetricsCallback.current({ category, label, data })
segmentTrackCallback &&
segmentTrackCallback.current &&
segmentTrackCallback.current({ category, label, data })
}
}
)
return () => unsub && unsub()
}, [props.bus, invokeTrackingCallbacks])
}, [props.telemetrySettings.allowUserStats, props.bus])

useEffect(() => {
const initAction = udcInit()
props.bus && props.bus.send(initAction.type, initAction)
}, [props.bus])

useEffect(() => {
const pageLoadAction = trackPageLoad()
props.bus && props.bus.send(pageLoadAction.type, pageLoadAction)
}, [props.bus, props.telemetrySettings.allowUserStats])

const {
browserSyncAuthStatus,
browserSyncConfig,
Expand Down Expand Up @@ -205,7 +181,6 @@ export function App(props: any) {
}, [titleString])

const wrapperClassNames = codeFontLigatures ? '' : 'disable-font-ligatures'

return (
<ErrorBoundary>
<DesktopApi
Expand Down
11 changes: 11 additions & 0 deletions src/shared/modules/udc/udcDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
TRACK_CANNY_FEATURE_REQUEST
} from 'shared/modules/sidebar/sidebarDuck'
import cmdHelper from 'shared/services/commandInterpreterHelper'
import { PREVIEW_EVENT } from '../preview/previewDuck'

// Action types
export const NAME = 'udc'
Expand Down Expand Up @@ -324,3 +325,13 @@ export const trackErrorFramesEpic: Epic<Action, GlobalState> = (
}
})
.ignoreElements()

export const trackPreviewEpic: Epic<Action, GlobalState> = action$ => {
return action$.ofType(PREVIEW_EVENT).map((action: any) => {
return metricsEvent({
category: 'preview',
label: action.label,
data: action.data
})
})
}
4 changes: 3 additions & 1 deletion src/shared/rootEpic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
import {
trackCommandUsageEpic,
trackErrorFramesEpic,
trackPreviewEpic,
trackReduxActionsEpic,
udcStartupEpic
} from './modules/udc/udcDuck'
Expand Down Expand Up @@ -148,5 +149,6 @@ export default combineEpics(
trackReduxActionsEpic,
initializeCypherEditorEpic,
updateEditorSupportSchemaEpic,
fetchRemoteGuideEpic
fetchRemoteGuideEpic,
trackPreviewEpic
)

0 comments on commit 9d212e7

Please sign in to comment.