Skip to content

Commit

Permalink
add properties node
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Oct 18, 2023
1 parent ac0ad71 commit 6c26f97
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
55 changes: 55 additions & 0 deletions frontend/src/scenes/notebooks/Nodes/NotebookNodeProperties.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { NotebookNodeType } from '~/types'
import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper'
import { NotebookNodeProps } from '../Notebook/utils'
import { LemonLabel } from '@posthog/lemon-ui'
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo'
import { PropertiesTable } from 'lib/components/PropertiesTable'

const Component = ({
attributes,
updateAttributes,
}: NotebookNodeProps<NotebookNodePropertiesAttributes>): JSX.Element => {
const { nodeId } = attributes

const person = {
properties: {
$geoip_city_name: 'Modena',
$geoip_continent_code: 'EU',
$geoip_continent_name: 'Europe',
$geoip_country_code: 'IT',
$geoip_country_name: 'Italy',
$geoip_latitude: 44.6511,
$geoip_longitude: 10.9211,
$geoip_postal_code: '41124',
$geoip_subdivision_1_code: '45',
$geoip_subdivision_1_name: 'Emilia-Romagna',
$geoip_subdivision_2_code: 'MO',
$geoip_subdivision_2_name: 'Province of Modena',
$geoip_time_zone: 'Europe/Rome',
},
}

return (
<div className="p-2">
{Object.entries(person.properties).map(([key, value]) => (
<div key={key}>
<LemonLabel>
<PropertyKeyInfo value={key} />
</LemonLabel>
<PropertiesTable properties={value} rootKey={key} />
</div>
))}
</div>
)
}

type NotebookNodePropertiesAttributes = {}

export const NotebookNodeProperties = createPostHogWidgetNode<NotebookNodePropertiesAttributes>({
nodeType: NotebookNodeType.Properties,
titlePlaceholder: 'Properties',
Component,
resizeable: true,
expandable: false,
attributes: {},
})
2 changes: 2 additions & 0 deletions frontend/src/scenes/notebooks/Notebook/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { lemonToast } from '@posthog/lemon-ui'
import { NotebookNodeType } from '~/types'
import { NotebookNodeImage } from '../Nodes/NotebookNodeImage'
import { NotebookNodeMap } from '../Nodes/NotebookNodeMap'
import { NotebookNodeProperties } from '../Nodes/NotebookNodeProperties'

import { EditorFocusPosition, EditorRange, JSONContent, Node, textContent } from './utils'
import { SlashCommandsExtension } from './SlashCommands'
Expand Down Expand Up @@ -111,6 +112,7 @@ export function Editor(): JSX.Element {
NotebookNodeSurvey,
NotebookNodeImage,
NotebookNodeMap,
NotebookNodeProperties,
SlashCommandsExtension,
BacklinkCommandsExtension,
NodeGapInsertionExtension,
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/scenes/notebooks/Notebook/SlashCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ order by count() desc
icon: <IconRecording />,
command: (chain) => chain.insertContent({ type: NotebookNodeType.Map, attrs: {} }),
},
{
title: 'Properties',
search: 'properties',
icon: <IconRecording />,
command: (chain) => chain.insertContent({ type: NotebookNodeType.Properties, attrs: {} }),
},
]

export const SlashCommands = forwardRef<SlashCommandsRef, SlashCommandsProps>(function SlashCommands(
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3067,6 +3067,7 @@ export enum NotebookNodeType {
ReplayTimestamp = 'ph-replay-timestamp',
Image = 'ph-image',
Map = 'ph-map',
Properties = 'ph-properties',
}

export type NotebookNodeResource = {
Expand Down

0 comments on commit 6c26f97

Please sign in to comment.