Skip to content

Commit

Permalink
feat: Track when adding/removing components: lock and hide (#883)
Browse files Browse the repository at this point in the history
* feat: Add tracking components Lock/Hide

* fix: Focus the canvas when adding a new asset

* fix: Remove console.log
  • Loading branch information
cyaiox authored Jan 31, 2024
1 parent 4e86ba6 commit fef3a76
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const Renderer: React.FC = () => {
itemPath: asset.asset.src,
isSmart: isSmart(asset)
})
canvasRef.current?.focus()
}

const importBuilderAsset = async (asset: Asset) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Entity, LastWriteWinElementSetComponentDefinition } from '@dcl/ecs'
import { WithSdkProps, withSdk } from '../../../hoc/withSdk'
import { useEntityComponent } from '../../../hooks/sdk/useEntityComponent'
import { SdkContextValue } from '../../../lib/sdk/context'
import { analytics, Event } from '../../../lib/logic/analytics'
import { getAssetByModel } from '../../../lib/logic/catalog'

import './ActionArea.css'

type Props = {
Expand All @@ -14,10 +17,12 @@ type Props = {

const ActionArea: React.FC<WithSdkProps & Props> = ({ sdk, ...props }) => {
const {
components: { Lock, Hide }
components: { Lock, Hide, GltfContainer }
} = sdk
const { entity } = props
const { addComponent, removeComponent } = useEntityComponent()
const { src: gltfSrc } = GltfContainer.getOrNull(entity) ?? { src: '' }
const asset = getAssetByModel(gltfSrc)

const isEntityLocked = useMemo(() => {
return Lock.getOrNull(entity) !== null
Expand All @@ -33,8 +38,18 @@ const ActionArea: React.FC<WithSdkProps & Props> = ({ sdk, ...props }) => {
entity,
Hide as unknown as LastWriteWinElementSetComponentDefinition<SdkContextValue['components']>
)
analytics.track(Event.REMOVE_COMPONENT, {
componentName: Hide.componentName,
itemId: asset?.id,
itemPath: gltfSrc
})
} else {
addComponent(entity, Hide.componentId, { value: true })
analytics.track(Event.ADD_COMPONENT, {
componentName: Hide.componentName,
itemId: asset?.id,
itemPath: gltfSrc
})
}
}, [entity, sdk, isEntityHidden])

Expand All @@ -44,8 +59,18 @@ const ActionArea: React.FC<WithSdkProps & Props> = ({ sdk, ...props }) => {
entity,
Lock as unknown as LastWriteWinElementSetComponentDefinition<SdkContextValue['components']>
)
analytics.track(Event.REMOVE_COMPONENT, {
componentName: Lock.componentName,
itemId: asset?.id,
itemPath: gltfSrc
})
} else {
addComponent(entity, Lock.componentId, { value: true })
analytics.track(Event.ADD_COMPONENT, {
componentName: Lock.componentName,
itemId: asset?.id,
itemPath: gltfSrc
})
}
}, [sdk, isEntityLocked])

Expand Down

0 comments on commit fef3a76

Please sign in to comment.