Skip to content

Commit

Permalink
Merge pull request #324 from liam-hq/feat/toggle-log
Browse files Browse the repository at this point in the history
📈: integrate toggle logging for sidebar and visibility button actions
  • Loading branch information
hoshinotsuyoshi authored Dec 19, 2024
2 parents 70aa9c0 + 7c75b53 commit 1a8ca43
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
6 changes: 6 additions & 0 deletions frontend/.changeset/ninety-llamas-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

📈: integrate toggle logging for sidebar and visibility button actions
6 changes: 6 additions & 0 deletions frontend/.changeset/slimy-cycles-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

📈 : add toggleLogEvent utility for logging toggle actions
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
getSidebarStateFromCookie,
} from '@liam-hq/ui'
import { ReactFlowProvider } from '@xyflow/react'
import type { FC } from 'react'
import { type FC, useCallback, useState } from 'react'
import { AppBar } from './AppBar'
import { ERDContent } from './ERDContent'
import styles from './ERDRenderer.module.css'
import { LeftPane } from './LeftPane'
import '@/styles/globals.css'
import { toggleLogEvent } from '@/features/gtm/utils'
import { useDBStructureStore, useUserEditingStore } from '@/stores'
// biome-ignore lint/nursery/useImportRestrictions: Fixed in the next PR.
import { Toolbar } from './ERDContent/Toolbar'
Expand All @@ -20,18 +21,32 @@ import { convertDBStructureToNodes } from './convertDBStructureToNodes'

export const ERDRenderer: FC = () => {
const defaultOpen = getSidebarStateFromCookie()
const [open, setOpen] = useState(defaultOpen)

const { showMode } = useUserEditingStore()
const dbStructure = useDBStructureStore()
const { nodes, edges } = convertDBStructureToNodes({
dbStructure,
showMode,
})

const handleChangeOpen = useCallback((open: boolean) => {
setOpen(open)
toggleLogEvent({
element: 'leftPane',
isShow: open,
})
}, [])

return (
<div className={styles.wrapper}>
<ToastProvider>
<AppBar />
<SidebarProvider defaultOpen={defaultOpen}>
<SidebarProvider
open={open}
defaultOpen={defaultOpen}
onOpenChange={handleChangeOpen}
>
<ReactFlowProvider>
<div className={styles.mainWrapper}>
<LeftPane />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toggleLogEvent } from '@/features/gtm/utils'
import { toggleHiddenNodeId } from '@/stores'
import { Eye, EyeClosed, SidebarMenuAction } from '@liam-hq/ui'
import { type FC, type MouseEvent, useCallback } from 'react'
Expand All @@ -13,8 +14,13 @@ export const VisibilityButton: FC<Props> = ({ tableName, hidden }) => {
(event: MouseEvent) => {
event.stopPropagation()
toggleHiddenNodeId(tableName)
toggleLogEvent({
element: 'tableNameMenuButton',
isShow: !!hidden,
tableId: tableName,
})
},
[tableName],
[tableName, hidden],
)

return (
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/erd-core/src/features/gtm/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './clickLogEvent'
export * from './selectTableLogEvent'
export * from './toggleLogEvent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { pushToDataLayer } from './pushToDataLayer'

type ToggleLogEvent = {
element: string
isShow: boolean
tableId?: string
}

export const toggleLogEvent = (params: ToggleLogEvent) => {
pushToDataLayer({
event: 'toggle',
...params,
})
}

0 comments on commit 1a8ca43

Please sign in to comment.