From 099cbd0fc3ef4918f323705bdefa34c1b2602d00 Mon Sep 17 00:00:00 2001 From: Alex Gyujin Kim Date: Thu, 16 Dec 2021 09:36:05 -0800 Subject: [PATCH] Type `LineGraph.jsx` and deprecate Posthog/Chart.js dependency (#7722) --- frontend/src/custom.d.ts | 7 + .../Annotations/AnnotationMarker.tsx | 21 +- .../components/Annotations/Annotations.tsx | 33 +- .../Annotations/annotationsLogic.ts | 60 +- .../components/ChartFilter/ChartFilter.tsx | 4 +- .../lib/components/LemonTable/LemonTable.tsx | 2 +- frontend/src/lib/constants.tsx | 1 + frontend/src/lib/utils.tsx | 4 + .../src/scenes/dashboard/DashboardItem.tsx | 4 +- .../src/scenes/funnels/FunnelLineGraph.tsx | 40 +- .../src/scenes/insights/InsightContainer.tsx | 8 +- .../InsightTabs/InsightDisplayConfig.tsx | 33 +- .../InsightTooltip/InsightTooltip.tsx | 4 +- .../{LineGraph.jsx => LEGACY_LineGraph.jsx} | 59 +- .../scenes/insights/LineGraph/LineGraph.tsx | 720 ++++++++++++++++++ .../src/scenes/insights/LineGraph/index.js | 1 - .../scenes/retention/RetentionLineGraph.tsx | 18 +- frontend/src/scenes/trends/Trends.tsx | 4 +- ...alueGraph.tsx => ActionsHorizontalBar.tsx} | 41 +- .../scenes/trends/viz/ActionsLineGraph.tsx | 46 +- frontend/src/scenes/trends/viz/ActionsPie.tsx | 41 +- .../src/scenes/trends/viz/ActionsTable.tsx | 4 +- frontend/src/scenes/trends/viz/index.ts | 2 +- frontend/src/types.ts | 60 +- package.json | 6 +- yarn.lock | 36 +- 26 files changed, 1007 insertions(+), 252 deletions(-) rename frontend/src/scenes/insights/LineGraph/{LineGraph.jsx => LEGACY_LineGraph.jsx} (92%) create mode 100644 frontend/src/scenes/insights/LineGraph/LineGraph.tsx delete mode 100644 frontend/src/scenes/insights/LineGraph/index.js rename frontend/src/scenes/trends/viz/{ActionsBarValueGraph.tsx => ActionsHorizontalBar.tsx} (72%) diff --git a/frontend/src/custom.d.ts b/frontend/src/custom.d.ts index cb017b415bf..3d7f0961ba1 100644 --- a/frontend/src/custom.d.ts +++ b/frontend/src/custom.d.ts @@ -15,3 +15,10 @@ declare module '*.mp3' { const content: any export default content } + +// This fixes TS errors when importing chartjs-plugin-crosshair +declare module 'chartjs-plugin-crosshair' { + const CrosshairPlugin: any + type CrosshairOptions = any + export { CrosshairPlugin, CrosshairOptions } +} diff --git a/frontend/src/lib/components/Annotations/AnnotationMarker.tsx b/frontend/src/lib/components/Annotations/AnnotationMarker.tsx index d6db7f42258..0e51f8f9169 100644 --- a/frontend/src/lib/components/Annotations/AnnotationMarker.tsx +++ b/frontend/src/lib/components/Annotations/AnnotationMarker.tsx @@ -31,12 +31,12 @@ function coordinateContains(e: MouseEvent, element: DOMRect): boolean { } interface AnnotationMarkerProps { - elementId: string + elementId?: string label: string - annotations: AnnotationType[] + annotations?: AnnotationType[] left: number top: number - onCreate: (textInput: string, applyAll: boolean) => void + onCreate?: (textInput: string, applyAll: boolean) => void onDelete?: (annotation: AnnotationType) => void onClick?: () => void onClose?: () => void @@ -45,17 +45,17 @@ interface AnnotationMarkerProps { color: string | null accessoryColor: string | null insightId?: number - currentDateMarker: string + currentDateMarker?: string | null dynamic?: boolean graphColor: string | null - index: number + index?: number getPopupContainer?: () => HTMLElement } export function AnnotationMarker({ elementId, label, - annotations, + annotations = [], left, top, onCreate, @@ -95,8 +95,7 @@ export function AnnotationMarker({ const { user } = useValues(userLogic) const { currentTeam } = useValues(teamLogic) const { currentOrganization } = useValues(organizationLogic) - - const { diffType, groupedAnnotations } = useValues(annotationsLogic({ insightId: insightId })) + const { diffType, groupedAnnotations } = useValues(annotationsLogic({ insightId })) function closePopup(): void { setFocused(false) @@ -171,8 +170,8 @@ export function AnnotationMarker({