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(commands): add commands for sidebar items #19020

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 6 additions & 8 deletions frontend/src/layout/navigation-3000/sidepanel/sidePanelLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const sidePanelLogic = kea<sidePanelLogicType>([

selectors({
enabledTabs: [
(s) => [s.featureFlags, s.isCloudOrDev],
(featureFlags, isCloudOrDev) => {
(s) => [s.featureFlags, s.isCloudOrDev, s.isReady, s.hasCompletedAllTasks],
(featureFlags, isCloudOrDev, isReady, hasCompletedAllTasks) => {
const tabs: SidePanelTab[] = []

if (featureFlags[FEATURE_FLAGS.NOTEBOOKS]) {
Expand All @@ -46,7 +46,9 @@ export const sidePanelLogic = kea<sidePanelLogicType>([

tabs.push(SidePanelTab.Docs)
tabs.push(SidePanelTab.Settings)
tabs.push(SidePanelTab.Activation)
if (!isReady || hasCompletedAllTasks) {
tabs.push(SidePanelTab.Activation)
}
tabs.push(SidePanelTab.Activity)

if (featureFlags[FEATURE_FLAGS.EARLY_ACCESS_FEATURE_SITE_BUTTON]) {
Expand All @@ -59,7 +61,7 @@ export const sidePanelLogic = kea<sidePanelLogicType>([

visibleTabs: [
(s) => [s.enabledTabs, s.selectedTab, s.sidePanelOpen, s.isReady, s.hasCompletedAllTasks],
(enabledTabs, selectedTab, sidePanelOpen, isReady, hasCompletedAllTasks): SidePanelTab[] => {
(enabledTabs, selectedTab, sidePanelOpen): SidePanelTab[] => {
return enabledTabs.filter((tab: any) => {
if (tab === selectedTab && sidePanelOpen) {
return true
Expand All @@ -70,10 +72,6 @@ export const sidePanelLogic = kea<sidePanelLogicType>([
return false
}

if (tab === SidePanelTab.Activation && (!isReady || hasCompletedAllTasks)) {
return false
}

Comment on lines -73 to -76
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit unsure about this change. Essentially I'm moving removing the activation tab from enabledTabs, instead of visibleTabs. Maybe @benjackwhite can say if we'd still need that.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was somewhat purposeful as otherwise it just closes all of a sudden. But I think it is also fine if it is hidden I guess. Makes the snapshot a bit pointless though...

return true
})
},
Expand Down
58 changes: 56 additions & 2 deletions frontend/src/lib/components/CommandPalette/commandPaletteLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { actions, connect, events, kea, listeners, path, reducers, selectors } f
import { router } from 'kea-router'
import api from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
import { IconClose } from 'lib/lemon-ui/icons'
import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { isMobile, isURL, uniqueBy } from 'lib/utils'
Expand All @@ -58,6 +59,9 @@ import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'

import { ThemeIcon } from '~/layout/navigation-3000/components/Navbar'
import { SidePanelTabs } from '~/layout/navigation-3000/sidepanel/SidePanel'
import { sidePanelLogic } from '~/layout/navigation-3000/sidepanel/sidePanelLogic'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { dashboardsModel } from '~/models/dashboardsModel'
import { DashboardType, InsightType } from '~/types'
Expand Down Expand Up @@ -134,8 +138,28 @@ function resolveCommand(source: Command | CommandFlow, argument?: string, prefix
export const commandPaletteLogic = kea<commandPaletteLogicType>([
path(['lib', 'components', 'CommandPalette', 'commandPaletteLogic']),
connect({
actions: [personalAPIKeysLogic, ['createKey'], router, ['push'], themeLogic, ['overrideTheme']],
values: [teamLogic, ['currentTeam'], userLogic, ['user'], featureFlagLogic, ['featureFlags']],
actions: [
personalAPIKeysLogic,
['createKey'],
router,
['push'],
themeLogic,
['overrideTheme'],
sidePanelStateLogic,
['openSidePanel', 'closeSidePanel'],
],
values: [
teamLogic,
['currentTeam'],
userLogic,
['user'],
featureFlagLogic,
['featureFlags'],
sidePanelLogic,
['enabledTabs'],
sidePanelStateLogic,
['sidePanelOpen'],
],
logic: [preflightLogic],
}),
actions({
Expand Down Expand Up @@ -903,6 +927,34 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
},
}

const sidepanel: Command = {
key: 'sidepanel',
scope: GLOBAL_COMMAND_SCOPE,
resolver: [
...values.enabledTabs.map((tab) => {
const { Icon, label } = SidePanelTabs[tab]
return {
icon: Icon,
display: `Open ${label} side panel`,
executor: () => {
actions.openSidePanel(tab)
},
}
}),
...(values.sidePanelOpen
? [
{
icon: IconClose,
display: 'Close side panel',
executor: () => {
actions.closeSidePanel()
},
},
]
: []),
],
}

actions.registerCommand(goTo)
actions.registerCommand(openUrls)
actions.registerCommand(debugClickhouseQueries)
Expand All @@ -913,6 +965,7 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
actions.registerCommand(debugCopySessionRecordingURL)
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
actions.registerCommand(toggleTheme)
actions.registerCommand(sidepanel)
}
},
beforeUnmount: () => {
Expand All @@ -925,6 +978,7 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
actions.deregisterCommand('share-feedback')
actions.deregisterCommand('debug-copy-session-recording-url')
actions.deregisterCommand('toggle-theme')
actions.deregisterCommand('sidepanel')
},
})),
])
Loading