-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
32dc17c
feat(3000): Add experiments to the sidebar
Twixes f84bb5f
Fix leftover usage of the "purple" status
Twixes 92da2fe
Update UI snapshots for `chromium` (1)
github-actions[bot] 77a07c8
Update UI snapshots for `chromium` (2)
github-actions[bot] 5c11cd3
Update UI snapshots for `chromium` (2)
github-actions[bot] ac2bac1
Merge branch 'master' into 3000-experiments
Twixes 6e98b19
Fix typing
Twixes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
BIN
+194 Bytes
(100%)
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.
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
101 changes: 101 additions & 0 deletions
101
frontend/src/layout/navigation-3000/sidebars/experiments.ts
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,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) | ||
}, | ||
}), | ||
]) |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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.