-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/hackathon-3000-feed-properties
# Conflicts: # frontend/src/scenes/notebooks/Notebook/Editor.tsx # frontend/src/scenes/notebooks/Notebook/utils.ts # frontend/src/scenes/notebooks/NotebooksTable/ContainsTypeFilter.tsx # frontend/src/scenes/persons/PersonFeedCanvas.tsx # frontend/src/types.ts
- Loading branch information
Showing
17 changed files
with
719 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MAPLIBRE_STYLE_URL=https://api.example.com/style.json?key=mykey |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { Marker } from 'maplibre-gl' | ||
|
||
import { Map, MapComponent } from './Map' | ||
|
||
const meta: Meta<typeof Map> = { | ||
title: 'Components/Map', | ||
component: Map, | ||
tags: ['autodocs'], | ||
} | ||
type Story = StoryObj<typeof Map> | ||
|
||
const coordinates: [number, number] = [0.119167, 52.205276] | ||
|
||
export const Unavailable: Story = {} | ||
|
||
export const Basic: Story = { | ||
render: (args) => ( | ||
<MapComponent | ||
mapLibreStyleUrl="" // TODO: set this value for the publish storybook and visual regression tests | ||
{...args} | ||
/> | ||
), | ||
args: { | ||
center: coordinates, | ||
markers: [new Marker({ color: 'var(--primary)' }).setLngLat(coordinates)], | ||
className: 'h-60', | ||
}, | ||
} | ||
|
||
export default meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useEffect, useRef } from 'react' | ||
import { Map as RawMap, Marker } from 'maplibre-gl' | ||
import useResizeObserver from 'use-resize-observer' | ||
|
||
import 'maplibre-gl/dist/maplibre-gl.css' | ||
|
||
/** Latitude and longtitude in degrees (+lat is east, -lat is west, +lon is south, -lon is north). */ | ||
export interface MapProps { | ||
/** Coordinates to center the map on by default. */ | ||
center: [number, number] | ||
/** Markers to show. */ | ||
markers?: Marker[] | ||
/** Map container class names. */ | ||
className?: string | ||
/** The map's MapLibre style. This must be a JSON object conforming to the schema described in the MapLibre Style Specification, or a URL to such JSON. */ | ||
mapLibreStyleUrl: string | ||
} | ||
|
||
export function Map({ className, ...rest }: Omit<MapProps, 'mapLibreStyleUrl'>): JSX.Element { | ||
if (!window.JS_MAPLIBRE_STYLE_URL) { | ||
return ( | ||
<div className={`w-full h-full flex flex-col items-center justify-center text-muted p-3 ${className}`}> | ||
<h1>Map unavailable</h1> | ||
<p> | ||
The <code>MAPLIBRE_STYLE_URL</code> setting is not defined. Please configure this setting with a | ||
valid MapLibre Style URL to display maps. | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
return <MapComponent mapLibreStyleUrl={window.JS_MAPLIBRE_STYLE_URL} className={className} {...rest} /> | ||
} | ||
|
||
export function MapComponent({ center, markers, className, mapLibreStyleUrl }: MapProps): JSX.Element { | ||
const mapContainer = useRef<HTMLDivElement>(null) | ||
const map = useRef<RawMap | null>(null) | ||
|
||
useEffect(() => { | ||
map.current = new RawMap({ | ||
container: mapContainer.current as HTMLElement, | ||
style: mapLibreStyleUrl, | ||
center, | ||
zoom: 4, | ||
maxZoom: 10, | ||
}) | ||
if (markers) { | ||
for (const marker of markers) { | ||
marker.addTo(map.current) | ||
} | ||
} | ||
}, []) | ||
|
||
useResizeObserver({ | ||
ref: mapContainer, | ||
onResize: () => { | ||
if (map.current) { | ||
map.current.resize() | ||
} | ||
}, | ||
}) | ||
|
||
return <div ref={mapContainer} className={className} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Marker } from 'maplibre-gl' | ||
|
||
import { NotebookNodeType } from '~/types' | ||
import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper' | ||
import { personLogic } from 'scenes/persons/personLogic' | ||
import { useValues } from 'kea' | ||
import { LemonSkeleton } from '@posthog/lemon-ui' | ||
import { NotFound } from 'lib/components/NotFound' | ||
import { Map } from '../../../lib/components/Map/Map' | ||
import { notebookNodeLogic } from './notebookNodeLogic' | ||
import { NotebookNodeProps } from 'scenes/notebooks/Notebook/utils' | ||
import { NotebookNodeEmptyState } from './components/NotebookNodeEmptyState' | ||
|
||
const Component = ({ attributes }: NotebookNodeProps<NotebookNodeMapAttributes>): JSX.Element | null => { | ||
const { id } = attributes | ||
const { expanded } = useValues(notebookNodeLogic) | ||
|
||
const logic = personLogic({ id }) | ||
const { person, personLoading } = useValues(logic) | ||
|
||
if (personLoading) { | ||
return <LemonSkeleton className="h-6" /> | ||
} else if (!person) { | ||
return <NotFound object="person" /> | ||
} | ||
|
||
if (!expanded) { | ||
return null | ||
} | ||
|
||
const longtitude = person?.properties?.['$geoip_longitude'] | ||
const latitude = person?.properties?.['$geoip_latitude'] | ||
const personCoordinates: [number, number] | null = | ||
!isNaN(longtitude) && !isNaN(latitude) ? [longtitude, latitude] : null | ||
|
||
if (!personCoordinates) { | ||
return <NotebookNodeEmptyState message="No map available." /> | ||
} | ||
|
||
return ( | ||
<Map | ||
center={personCoordinates} | ||
markers={[new Marker({ color: 'var(--primary)' }).setLngLat(personCoordinates)]} | ||
className="h-full" | ||
/> | ||
) | ||
} | ||
|
||
type NotebookNodeMapAttributes = { | ||
id: string | ||
} | ||
|
||
export const NotebookNodeMap = createPostHogWidgetNode<NotebookNodeMapAttributes>({ | ||
nodeType: NotebookNodeType.Map, | ||
titlePlaceholder: 'Location', | ||
Component, | ||
resizeable: true, | ||
heightEstimate: 150, | ||
expandable: true, | ||
startExpanded: true, | ||
attributes: { | ||
id: {}, | ||
}, | ||
}) |
11 changes: 11 additions & 0 deletions
11
frontend/src/scenes/notebooks/Nodes/components/NotebookNodeEmptyState.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type NotebookNodeEmptyStateProps = { | ||
message: string | ||
} | ||
|
||
export function NotebookNodeEmptyState({ message }: NotebookNodeEmptyStateProps): JSX.Element { | ||
return ( | ||
<div className="w-full h-full flex flex-col items-center justify-center text-muted p-3"> | ||
<i>{message}</i> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.