Skip to content

Commit

Permalink
Merge branch 'master' into dn-fix/table-stickies
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored Dec 5, 2023
2 parents e7d8165 + 82f3ff4 commit 25af306
Show file tree
Hide file tree
Showing 123 changed files with 2,687 additions and 4,879 deletions.
97 changes: 86 additions & 11 deletions ee/frontend/mobile-replay/__snapshots__/transform.test.ts.snap

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions ee/frontend/mobile-replay/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,25 @@ describe('replay/transform', () => {
])
expect(textEvent).toMatchSnapshot()
})
test('omitting x and y is equivalent to setting them to 0', () => {
expect(
posthogEEModule.mobileReplay?.transformToWeb([
{
type: 2,
data: {
wireframes: [
{
id: 12345,
width: 100,
height: 30,
type: 'image',
},
],
},
timestamp: 1,
},
])
).toMatchSnapshot()
})
})
})
64 changes: 46 additions & 18 deletions ee/frontend/mobile-replay/wireframeStyle.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import { MobileStyles, wireframe } from './mobile.types'

function isNumber(candidate: unknown): candidate is number {
return typeof candidate === 'number'
}

function isString(candidate: unknown): candidate is string {
return typeof candidate === 'string'
}

function isUnitLike(candidate: unknown): candidate is string | number {
return isNumber(candidate) || (isString(candidate) && candidate.length > 0)
}

function ensureUnit(value: string | number): string {
return typeof value === 'number' ? `${value}px` : value.replace(/px$/g, '') + 'px'
return isNumber(value) ? `${value}px` : value.replace(/px$/g, '') + 'px'
}

function makeBorderStyles(wireframe: wireframe): string {
let styles = ''

if (wireframe.style?.borderWidth) {
if (!wireframe.style) {
return styles
}

if (isUnitLike(wireframe.style.borderWidth)) {
const borderWidth = ensureUnit(wireframe.style.borderWidth)
styles += `border-width: ${borderWidth};`
}
if (wireframe.style?.borderRadius) {
if (isUnitLike(wireframe.style.borderRadius)) {
const borderRadius = ensureUnit(wireframe.style.borderRadius)
styles += `border-radius: ${borderRadius};`
}
Expand All @@ -29,13 +45,17 @@ function makeBorderStyles(wireframe: wireframe): string {
export function makeSvgBorder(style: MobileStyles | undefined): Record<string, string> {
const svgBorderStyles: Record<string, string> = {}

if (style?.borderWidth) {
svgBorderStyles['stroke-width'] = style.borderWidth.toString()
if (!style) {
return svgBorderStyles
}

if (isUnitLike(style.borderWidth)) {
svgBorderStyles['stroke-width'] = ensureUnit(style.borderWidth)
}
if (style?.borderColor) {
if (style.borderColor) {
svgBorderStyles.stroke = style.borderColor
}
if (style?.borderRadius) {
if (isUnitLike(style.borderRadius)) {
svgBorderStyles.rx = ensureUnit(style.borderRadius)
}

Expand All @@ -44,19 +64,22 @@ export function makeSvgBorder(style: MobileStyles | undefined): Record<string, s

export function makePositionStyles(wireframe: wireframe): string {
let styles = ''
if (wireframe.width) {
if (isNumber(wireframe.width)) {
styles += `width: ${ensureUnit(wireframe.width)};`
}
if (wireframe.height) {
if (isNumber(wireframe.height)) {
styles += `height: ${ensureUnit(wireframe.height)};`
}
if (wireframe.x || wireframe.y) {
styles += `position: absolute;`
if (wireframe.x) {
styles += `left: ${ensureUnit(wireframe.x)};`

const posX = wireframe.x || 0
const posY = wireframe.y || 0
if (isNumber(posX) || isNumber(posY)) {
styles += `position: fixed;`
if (isNumber(posX)) {
styles += `left: ${ensureUnit(posX)};`
}
if (wireframe.y) {
styles += `top: ${ensureUnit(wireframe.y)};`
if (isNumber(posY)) {
styles += `top: ${ensureUnit(posY)};`
}
}
return styles
Expand All @@ -82,11 +105,16 @@ function makeLayoutStyles(wireframe: wireframe): string {

function makeFontStyles(wireframe: wireframe): string {
let styles = ''
if (wireframe.style?.fontSize) {

if (!wireframe.style) {
return styles
}

if (isUnitLike(wireframe.style.fontSize)) {
styles += `font-size: ${ensureUnit(wireframe.style?.fontSize)};`
}
if (wireframe.style?.fontFamily) {
styles += `font-family: ${wireframe.style?.fontFamily};`
if (wireframe.style.fontFamily) {
styles += `font-family: ${wireframe.style.fontFamily};`
}
return styles
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const sidePanelSettingsLogic = kea<sidePanelSettingsLogicType>([

listeners(({ actions, values }) => ({
openSettingsPanel: ({ settingsLogicProps }) => {
if (!values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'control') {
LemonDialog.open({
title: 'Settings',
content: <Settings {...settingsLogicProps} hideSections logicKey="modal" />,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation-3000/themeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const themeLogic = kea<themeLogicType>([
}
// Dark mode is a PostHog 3000 feature
// User-saved preference is used when set, oterwise we fall back to the system value
return featureFlags[FEATURE_FLAGS.POSTHOG_3000]
return featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test'
? user?.theme_mode
? user.theme_mode === 'dark'
: darkModeSystemPreference
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation/TopBar/NotebookButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { notebookPanelLogic } from 'scenes/notebooks/NotebookPanel/notebookPanel
export function NotebookButton(): JSX.Element {
const { visibility } = useValues(notebookPanelLogic)
const { toggleVisibility } = useActions(notebookPanelLogic)
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

const overrides3000: Partial<LemonButtonWithSideActionProps> = is3000
? {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation/TopBar/SitePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export function SitePopoverOverlay(): JSX.Element {
</SitePopoverSection>
)}
<SitePopoverSection>
<FlaggedFeature flag={FEATURE_FLAGS.POSTHOG_3000}>
<FlaggedFeature flag={FEATURE_FLAGS.POSTHOG_3000} match="test">
<ThemeSwitcher />
</FlaggedFeature>
<LemonButton
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function CodeSnippet({
/>
</div>
<SyntaxHighlighter
style={featureFlags[FEATURE_FLAGS.POSTHOG_3000] ? synthwave84 : okaidia}
style={featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test' ? synthwave84 : okaidia}
language={language}
wrapLines={wrap}
lineProps={{ style: { whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' } }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CommandResults } from './CommandResults'
export function CommandPalette(): JSX.Element {
const { featureFlags } = useValues(featureFlagLogic)

const isUsingCmdKSearch = featureFlags[FEATURE_FLAGS.POSTHOG_3000]
const isUsingCmdKSearch = featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test'

if (isUsingCmdKSearch) {
return <CommandBar />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
selectors({
isUsingCmdKSearch: [
(selectors) => [selectors.featureFlags],
(featureFlags) => featureFlags[FEATURE_FLAGS.POSTHOG_3000],
(featureFlags) => featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test',
],
isSqueak: [
(selectors) => [selectors.input],
Expand Down Expand Up @@ -1008,7 +1008,7 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
actions.registerCommand(createDashboard)
actions.registerCommand(shareFeedback)
actions.registerCommand(debugCopySessionRecordingURL)
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test') {
actions.registerCommand(toggleTheme)
actions.registerCommand(toggleHedgehogMode)
actions.registerCommand(shortcuts)
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/lib/components/NotFound/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './NotFound.scss'

import { LemonButton } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { Link } from 'lib/lemon-ui/Link'
import { capitalizeFirstLetter } from 'lib/utils'
import { useNotebookNode } from 'scenes/notebooks/Nodes/NotebookNodeContext'
Expand All @@ -17,6 +18,7 @@ interface NotFoundProps {
export function NotFound({ object, caption }: NotFoundProps): JSX.Element {
const { preflight } = useValues(preflightLogic)
const { openSupportForm } = useActions(supportLogic)
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

const nodeLogic = useNotebookNode()

Expand Down Expand Up @@ -47,7 +49,11 @@ export function NotFound({ object, caption }: NotFoundProps): JSX.Element {
</p>
<div className="flex justify-center">
{nodeLogic && (
<LemonButton type="primary" status="danger" onClick={() => nodeLogic.actions.deleteNode()}>
<LemonButton
type={is3000 ? 'secondary' : 'primary'}
status="danger"
onClick={() => nodeLogic.actions.deleteNode()}
>
Remove from Notebook
</LemonButton>
)}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/components/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export function PageHeader({
delimited,
notebookProps,
}: PageHeaderProps): JSX.Element | null {
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')
const { actionsContainer } = useValues(breadcrumbsLogic)

return (
<>
{!is3000 && (
// eslint-disable-next-line react/forbid-dom-props
<div className="page-title-row flex justify-between" style={style}>
<div className="min-w-0">
{!is3000 &&
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/Support/supportLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export const supportLogic = kea<supportLogicType>([
actionToUrl(({ values }) => {
return {
closeSupportForm: () => {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test') {
return
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/hooks/use3000Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { useFeatureFlag } from './useFeatureFlag'

export function use3000Body(): void {
const is3000 = !!useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')
const { isDarkModeOn } = useValues(themeLogic)

useEffect(() => {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/hooks/useFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { useValues } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'

export const useFeatureFlag = (flag: keyof typeof FEATURE_FLAGS): boolean => {
export const useFeatureFlag = (flag: keyof typeof FEATURE_FLAGS, match?: string): boolean => {
const { featureFlags } = useValues(featureFlagLogic)

if (match) {
return featureFlags[FEATURE_FLAGS[flag]] === match
}

return !!featureFlags[FEATURE_FLAGS[flag]]
}
2 changes: 1 addition & 1 deletion frontend/src/lib/lemon-ui/LemonMenu/LemonMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function LemonMenuOverlay({ items, tooltipPlacement, itemsRef }: LemonMen
const { featureFlags } = useValues(featureFlagLogic)
const sectionsOrItems = useMemo(() => normalizeItems(items), [items])

const buttonSize = featureFlags[FEATURE_FLAGS.POSTHOG_3000] ? 'small' : 'medium'
const buttonSize = featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test' ? 'small' : 'medium'

return sectionsOrItems.length > 0 && isLemonMenuSection(sectionsOrItems[0]) ? (
<LemonMenuSectionList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function LemonSegmentedButton<T extends React.Key>({
HTMLDivElement,
HTMLLIElement
>(value, 200)
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

let buttonProps = {}

Expand Down
Loading

0 comments on commit 25af306

Please sign in to comment.