Skip to content

Commit e64fccb

Browse files
committed
refactoring, renaming
1 parent 8edffef commit e64fccb

3 files changed

Lines changed: 31 additions & 28 deletions

File tree

packages/web-console/src/components/TopBar/toolbar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { PopperHover, Placement } from "../"
2121
import { useTheme } from "styled-components"
2222
import { TelemetryTable } from "../../consts";
2323
import { TelemetryConfigShape } from "../../store/Telemetry/types";
24-
import { sendEntTelemetry } from "../../utils/telemetry";
24+
import { sendServerInfoTelemetry } from "../../utils/telemetry";
2525

2626
const EnvIconWrapper = styled.div<{ $background?: string }>`
2727
display: flex;
@@ -423,8 +423,8 @@ export const Toolbar = () => {
423423

424424
const response = await quest.query<TelemetryConfigShape>(`${TelemetryTable.CONFIG} limit -1`)
425425
if (response.type === QuestDB.Type.DQL && response.count === 1) {
426-
const config = response.data[0] as TelemetryConfigShape
427-
sendEntTelemetry(config)
426+
const serverInfo = response.data[0] as TelemetryConfigShape
427+
sendServerInfoTelemetry(serverInfo)
428428
}
429429
return
430430
}

packages/web-console/src/store/Telemetry/epics.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,18 @@ import {
3636
TelemetryAction,
3737
TelemetryAT,
3838
TelemetryConfigShape,
39-
TelemetryRemoteConfigShape,
4039
} from "../../types"
4140

4241
import { fromFetch } from "../../utils"
4342
import * as QuestDB from "../../utils/questdb"
4443
import { getValue } from "../../utils/localStorage"
4544
import { StoreKey } from "../../utils/localStorage/types"
4645
import { AuthPayload } from "../../modules/OAuth2/types"
47-
import { sendEntTelemetry } from "../../utils/telemetry";
46+
import { sendServerInfoTelemetry, getTelemetryTimestamp } from "../../utils/telemetry";
4847

4948
const quest = new QuestDB.Client()
5049

51-
export const getConfig: Epic<StoreAction, TelemetryAction, StoreShape> = (
50+
export const getServerInfo: Epic<StoreAction, TelemetryAction, StoreShape> = (
5251
action$,
5352
) =>
5453
action$.pipe(
@@ -92,31 +91,19 @@ export const getConfig: Epic<StoreAction, TelemetryAction, StoreShape> = (
9291
}),
9392
)
9493

95-
export const getRemoteConfig: Epic<StoreAction, TelemetryAction, StoreShape> = (
94+
export const getLatestTelemetryTimestamp: Epic<StoreAction, TelemetryAction, StoreShape> = (
9695
action$,
9796
state$,
9897
) =>
9998
action$.pipe(
10099
ofType<StoreAction, SetTelemetryConfigAction>(TelemetryAT.SET_CONFIG),
101100
withLatestFrom(state$),
102101
switchMap(([_, state]) => {
103-
const config = selectors.telemetry.getConfig(state)
104-
if (config) {
105-
sendEntTelemetry(config)
106-
}
107-
108-
if (config?.enabled) {
109-
return fromFetch<Partial<TelemetryRemoteConfigShape>>(
110-
`${API}/config`,
111-
{
112-
method: "POST",
113-
body: JSON.stringify(config),
114-
},
115-
false,
116-
)
102+
const serverInfo = selectors.telemetry.getConfig(state)
103+
if (serverInfo) {
104+
sendServerInfoTelemetry(serverInfo)
117105
}
118-
119-
return NEVER
106+
return getTelemetryTimestamp(serverInfo)
120107
}),
121108
switchMap((response) => {
122109
if (response.error) {
@@ -224,4 +211,4 @@ export const startTelemetry: Epic<StoreAction, TelemetryAction, StoreShape> = (
224211
}),
225212
)
226213

227-
export default [getConfig, getRemoteConfig, startTelemetry]
214+
export default [getServerInfo, getLatestTelemetryTimestamp, startTelemetry]
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
import { getValue } from "./localStorage";
22
import { StoreKey } from "./localStorage/types";
33
import { API } from "../consts";
4-
import { TelemetryConfigShape } from "../store/Telemetry/types";
4+
import { TelemetryConfigShape, TelemetryRemoteConfigShape } from "../store/Telemetry/types";
5+
import { fromFetch } from "./fromFetch";
6+
import { NEVER } from "rxjs"
57

6-
export const sendEntTelemetry = (config: Readonly<TelemetryConfigShape>) => {
8+
export const sendServerInfoTelemetry = (serverInfo: Readonly<TelemetryConfigShape>) => {
79
const releaseType = getValue(StoreKey.RELEASE_TYPE);
8-
if (releaseType === "EE" || config?.enabled) {
10+
if (releaseType === "EE" || serverInfo?.enabled) {
911
fetch(`${API}/add-ent`, {
1012
method: "POST",
1113
headers: {
1214
"Content-Type": "application/json",
1315
},
14-
body: JSON.stringify({...config, releaseType}),
16+
body: JSON.stringify({...serverInfo, releaseType}),
1517
}).catch(() => {
1618
})
1719
}
1820
}
21+
22+
export const getTelemetryTimestamp = (serverInfo: Readonly<TelemetryConfigShape> | undefined) => {
23+
if (serverInfo?.enabled) {
24+
return fromFetch<Partial<TelemetryRemoteConfigShape>>(
25+
`${API}/config`,
26+
{
27+
method: "POST",
28+
body: JSON.stringify(serverInfo),
29+
},
30+
false,
31+
)
32+
}
33+
return NEVER
34+
}

0 commit comments

Comments
 (0)