Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(3000): Add experiments to the sidebar #16086

Merged
merged 7 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified frontend/__snapshots__/lemon-ui-lemon-tag--lemon-tag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/posthog-3000-sidebar--feature-flags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/layout/navigation-3000/Navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@
&.SidebarListItem--marker-status-danger {
--sidebar-list-item-status-color: var(--danger);
}
&.SidebarListItem--marker-status-completion {
--sidebar-list-item-status-color: var(--purple);
}
}

.SidebarListItem__link,
Expand Down Expand Up @@ -398,6 +401,7 @@
}

.SidebarListItem__link {
row-gap: 1px;
padding: 0 var(--sidebar-horizontal-padding) 0 var(--sidebar-list-item-inset);
&:hover {
color: inherit;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/layout/navigation-3000/navbarItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { cohortsSidebarLogic } from './sidebars/cohorts'
import { personsAndGroupsSidebarLogic } from './sidebars/personsAndGroups'
import { insightsSidebarLogic } from './sidebars/insights'
import { dataManagementSidebarLogic } from './sidebars/dataManagement'
import { experimentsSidebarLogic } from './sidebars/experiments'

/** A list of navbar sections with items. */
export const NAVBAR_ITEMS: NavbarItem[][] = [
Expand Down Expand Up @@ -88,6 +89,7 @@ export const NAVBAR_ITEMS: NavbarItem[][] = [
identifier: Scene.Experiments,
label: 'A/B Testing',
icon: <IconExperiment />,
logic: experimentsSidebarLogic,
},
],
[
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation-3000/sidebars/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const dashboardsSidebarLogic = kea<dashboardsSidebarLogicType>([
{
key: 'dashboards',
title: 'Dashboards',
loading: dashboardsLoading,
items: relevantDashboards.map(
([dashboard, matches]) =>
({
Expand Down Expand Up @@ -121,7 +122,6 @@ export const dashboardsSidebarLogic = kea<dashboardsSidebarLogicType>([
},
} as ExtendedListItem)
),
loading: dashboardsLoading,
} as SidebarCategory,
],
],
Expand Down
101 changes: 101 additions & 0 deletions frontend/src/layout/navigation-3000/sidebars/experiments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { connect, kea, path, selectors } from 'kea'
import { sceneLogic } from 'scenes/sceneLogic'
import { Scene } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
import { SidebarCategory, ExtendedListItem } from '../types'
import Fuse from 'fuse.js'
import { subscriptions } from 'kea-subscriptions'
import { navigation3000Logic } from '../navigationLogic'
import { FuseSearchMatch } from './utils'
import { Experiment, ProgressStatus } from '~/types'
import type { experimentsSidebarLogicType } from './experimentsType'
import { experimentsLogic, getExperimentStatus } from 'scenes/experiments/experimentsLogic'
import { dayjs } from 'lib/dayjs'

const fuse = new Fuse<Experiment>([], {
keys: [{ name: 'name', weight: 2 }, 'description'],
threshold: 0.3,
ignoreLocation: true,
includeMatches: true,
})

const EXPERIMENT_STATUS_TO_RIBBON_STATUS = { draft: 'muted', running: 'success', complete: 'completion' }

export const experimentsSidebarLogic = kea<experimentsSidebarLogicType>([
path(['layout', 'navigation-3000', 'sidebars', 'experimentsSidebarLogic']),
connect({
values: [experimentsLogic, ['experiments', 'experimentsLoading'], sceneLogic, ['activeScene', 'sceneParams']],
actions: [experimentsLogic, ['loadExperiments', 'deleteExperiment']],
}),
selectors(({ actions }) => ({
contents: [
(s) => [s.relevantExperiments, s.experimentsLoading],
(relevantExperiments, experimentsLoading) => [
{
key: 'experiments',
title: 'Experiments',
loading: experimentsLoading,
items: relevantExperiments.map(([experiment, matches]) => {
const experimentStatus = getExperimentStatus(experiment)
return {
key: experiment.id,
name: experiment.name,
summary:
experimentStatus === ProgressStatus.Draft
? 'Draft'
: experimentStatus === ProgressStatus.Complete
? `Completed ${dayjs(experiment.start_date).fromNow()}`
: `Running for ${dayjs(experiment.start_date).fromNow(true)} now`,
extraContextTop: dayjs(experiment.created_at),
extraContextBottom: `by ${experiment.created_by?.first_name || 'unknown'}`,
url: urls.experiment(experiment.id),
searchMatch: matches
? {
matchingFields: matches.map((match) => match.key),
nameHighlightRanges: matches.find((match) => match.key === 'name')?.indices,
}
: null,
marker: {
type: 'ribbon',
status: EXPERIMENT_STATUS_TO_RIBBON_STATUS[experimentStatus],
},
menuItems: [
{
items: [
{
label: 'Delete experiment',
onClick: () => actions.deleteExperiment(experiment.id as number),
status: 'danger',
},
],
},
],
} as ExtendedListItem
}),
} as SidebarCategory,
],
],
activeListItemKey: [
(s) => [s.activeScene, s.sceneParams],
(activeScene, sceneParams) => {
return activeScene === Scene.Experiment && sceneParams.params.id
? parseInt(sceneParams.params.id)
: null
},
],
relevantExperiments: [
(s) => [s.experiments, navigation3000Logic.selectors.searchTerm],
(experiments, searchTerm): [Experiment, FuseSearchMatch[] | null][] => {
if (searchTerm) {
return fuse.search(searchTerm).map((result) => [result.item, result.matches as FuseSearchMatch[]])
}
return experiments.map((experiment) => [experiment, null])
},
],
})),
subscriptions({
experiments: (experiments) => {
fuse.setCollection(experiments)
},
}),
])
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const featureFlagsSidebarLogic = kea<featureFlagsSidebarLogicType>([
{
key: 'feature-flags',
title: 'Feature Flags',
loading: featureFlagsLoading,
items: relevantFeatureFlags.map(([featureFlag, matches]) => {
if (!featureFlag.id) {
throw new Error('Feature flag ID should never be missing in the sidebar')
Expand Down Expand Up @@ -135,7 +136,6 @@ export const featureFlagsSidebarLogic = kea<featureFlagsSidebarLogicType>([
status: 'danger',
},
],
loading: featureFlagsLoading,
},
],
} as ExtendedListItem
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation-3000/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface BasicListItem {
* Optional marker color.
* @default 'muted'
*/
status?: 'muted' | 'success' | 'warning' | 'danger'
status?: 'muted' | 'success' | 'warning' | 'danger' | 'completion'
}
/** If search is on, this should be present to convey why this item is included in results. */
searchMatch?: SearchMatch | null
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/lemon-ui/LemonTag/LemonTag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
color: var(--inverse);
}

&.purple {
&.completion {
background-color: var(--purple-light);
color: var(--purple-dark);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/lemon-ui/LemonTag/LemonTag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ALL_COLORS: LemonTagType[] = [
'danger',
'success',
'default',
'purple',
'completion',
'caution',
'none',
]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/lemon-ui/LemonTag/LemonTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type LemonTagType =
| 'danger'
| 'success'
| 'default'
| 'purple'
| 'completion'
| 'caution'
| 'none'

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/billing/BillingProduct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const BillingProductAddon = ({ addon }: { addon: BillingProductV2AddonTyp
<h4 className="leading-5 mb-1 font-bold">{addon.name}</h4>
{addon.subscribed && (
<div>
<LemonTag type="purple" icon={<IconCheckmark />}>
<LemonTag type="completion" icon={<IconCheckmark />}>
Subscribed
</LemonTag>
</div>
Expand Down Expand Up @@ -110,7 +110,7 @@ export const BillingProductAddon = ({ addon }: { addon: BillingProductV2AddonTyp
/>
</>
) : addon.included_with_main_product ? (
<LemonTag type="purple" icon={<IconCheckmark />}>
<LemonTag type="completion" icon={<IconCheckmark />}>
Included with plan
</LemonTag>
) : (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/billing/PlanComparisonModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const PlanComparisonModal = ({
<th scope="row">
<p className="ml-0">
<span className="font-bold">{addon.name}</span>
<LemonTag type="purple" className="ml-2">
<LemonTag type="completion" className="ml-2">
addon
</LemonTag>
</p>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/experiments/Experiments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export function Experiments(): JSX.Element {
}
}}
options={[
{ label: 'All', value: ProgressStatus.All },
{ label: 'All', value: 'all' },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where/why did this go? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"All" is not not an actual status, it's only a filtering option, which was making handling of actual experiment items weird, because TypeScript said "you need to handle the All status too" – despite it not really existing. It should just be a string here.

{ label: 'Draft', value: ProgressStatus.Draft },
{ label: 'Running', value: ProgressStatus.Running },
{ label: 'Complete', value: ProgressStatus.Complete },
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/persons/RelatedFeatureFlags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function RelatedFeatureFlags({ distinctId, groups }: Props): JSX.Element
<>
<Link to={featureFlag.id ? urls.featureFlag(featureFlag.id) : undefined} className="row-name">
{stringWithWBR(featureFlag.key, 17)}
<LemonTag type={isExperiment ? 'purple' : 'default'} className="ml-2">
<LemonTag type={isExperiment ? 'completion' : 'default'} className="ml-2">
{isExperiment ? 'Experiment' : 'Feature flag'}
</LemonTag>
</Link>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/surveys/Surveys.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LemonButton, LemonTable, LemonDivider, Link, LemonTag } from '@posthog/lemon-ui'
import { LemonButton, LemonTable, LemonDivider, Link, LemonTag, LemonTagType } from '@posthog/lemon-ui'
import { PageHeader } from 'lib/components/PageHeader'
import { More } from 'lib/lemon-ui/LemonButton/More'
import stringWithWBR from 'lib/utils/stringWithWBR'
import { SceneExport } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
import { getSurveyStatus, surveysLogic } from './surveysLogic'
import { createdAtColumn, createdByColumn } from 'lib/lemon-ui/LemonTable/columnUtils'
import { ProductKey, Survey } from '~/types'
import { ProductKey, ProgressStatus, Survey } from '~/types'
import { LemonTableColumn } from 'lib/lemon-ui/LemonTable'
import { useActions, useValues } from 'kea'
import { router } from 'kea-router'
Expand Down Expand Up @@ -113,8 +113,8 @@ export function Surveys(): JSX.Element {
const statusColors = {
running: 'success',
draft: 'default',
complete: 'purple',
}
complete: 'completion',
} as Record<ProgressStatus, LemonTagType>
const status = getSurveyStatus(survey)
return (
<LemonTag type={statusColors[status]} style={{ fontWeight: 600 }}>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ export enum ProgressStatus {
Draft = 'draft',
Running = 'running',
Complete = 'complete',
All = 'all',
}

export enum PropertyFilterType {
Expand Down