Skip to content

Commit 9751436

Browse files
committed
feat: derive open tab from sidePanelConfig
1 parent 0596384 commit 9751436

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

src/components/common/SidePanel/SidePanel.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
import { SIDE_PANEL_ASIDE_DRAG_HANDLE, SIDE_PANEL_MAX_ASIDE_WIDTH, SIDE_PANEL_MIN_ASIDE_WIDTH } from './constants'
1515
import { SidePanelContent } from './SidePanelContent'
16-
import { SidePanelProps, SidePanelTab } from './types'
16+
import { SidePanelProps } from './types'
1717

1818
import './SidePanel.scss'
1919

@@ -25,7 +25,8 @@ export const SidePanel = ({ asideWidth }: SidePanelProps) => {
2525
const { appTheme } = useTheme()
2626
const { sidePanelConfig, setSidePanelConfig } = useMainContext()
2727

28-
const { open } = sidePanelConfig
28+
const { state } = sidePanelConfig
29+
const open = state !== 'closed'
2930

3031
useEffect(() => {
3132
if (open) {
@@ -46,7 +47,7 @@ export const SidePanel = ({ asideWidth }: SidePanelProps) => {
4647
// HANDLERS
4748
const handleClose = () => {
4849
asideWidth.set(SIDE_PANEL_MIN_ASIDE_WIDTH)
49-
setSidePanelConfig({ open: false })
50+
setSidePanelConfig({ state: 'closed' })
5051
}
5152

5253
const handleDrag: DraggableEventHandler = (_, data) => {
@@ -67,7 +68,7 @@ export const SidePanel = ({ asideWidth }: SidePanelProps) => {
6768
animate={{ x: 0, opacity: 1 }}
6869
exit={{ x: SIDE_PANEL_MIN_ASIDE_WIDTH, opacity: 0 }}
6970
transition={{ duration: 0.2, ease: 'easeInOut' }}
70-
className="flexbox"
71+
className="flexbox h-100vh dc__overflow-hidden"
7172
>
7273
<Draggable
7374
handle={`.${SIDE_PANEL_ASIDE_DRAG_HANDLE}`}
@@ -93,7 +94,11 @@ export const SidePanel = ({ asideWidth }: SidePanelProps) => {
9394
className={`flex-grow-1 dc__position-rel mt-8 mr-8 mb-8 br-6 bg__primary flexbox-col dc__overflow-hidden ${appTheme === AppThemeType.dark ? 'border__primary-translucent' : ''}`}
9495
>
9596
{contentOverlay && <div className="dc__position-abs w-100 h-100 dc__zi-1" />}
96-
<SidePanelContent onClose={handleClose} initialTab={SidePanelTab.DOCUMENTATION} />
97+
<SidePanelContent
98+
onClose={handleClose}
99+
sidePanelConfig={sidePanelConfig}
100+
setSidePanelConfig={setSidePanelConfig}
101+
/>
97102
</div>
98103
</motion.aside>
99104
)}

src/components/common/SidePanel/SidePanelContent.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react'
1+
import { MouseEvent } from 'react'
22

33
import {
44
Button,
@@ -9,6 +9,7 @@ import {
99
Icon,
1010
ImageType,
1111
logExceptionToSentry,
12+
SidePanelTab,
1213
} from '@devtron-labs/devtron-fe-common-lib'
1314

1415
import { ReactComponent as ICMaintenance } from '@Images/ic-maintenance.svg'
@@ -18,7 +19,7 @@ import { importComponentFromFELibrary } from '../helpers/Helpers'
1819
import { TABS_CONFIG } from './constants'
1920
import { SidePanelDocumentation } from './SidePanelDocumentation'
2021
import { SidePanelHeaderActions } from './SidePanelHeaderActions'
21-
import { SidePanelContentProps, SidePanelTab } from './types'
22+
import { SidePanelContentProps } from './types'
2223
import { renderOpenTicketButton } from './utils'
2324

2425
const AIChat = importComponentFromFELibrary(
@@ -33,8 +34,8 @@ const AIChat = importComponentFromFELibrary(
3334
'function',
3435
)
3536

36-
export const SidePanelContent = ({ onClose, initialTab = SidePanelTab.DOCUMENTATION }: SidePanelContentProps) => {
37-
const [tab, setTab] = useState<SidePanelTab>(initialTab)
37+
export const SidePanelContent = ({ onClose, setSidePanelConfig, sidePanelConfig }: SidePanelContentProps) => {
38+
const tab = sidePanelConfig.state
3839

3940
const renderContent = () => {
4041
switch (tab) {
@@ -57,20 +58,43 @@ export const SidePanelContent = ({ onClose, initialTab = SidePanelTab.DOCUMENTAT
5758
/>
5859
)
5960
default:
60-
logExceptionToSentry('Unknown tab in SidePanelContent', tab)
61+
logExceptionToSentry(`Unknown ${tab} in SidePanelContent`)
6162
return null
6263
}
6364
}
6465

66+
const getConfigForTab = (tabId: SidePanelTab) => {
67+
if (sidePanelConfig.state === tabId) {
68+
return sidePanelConfig
69+
}
70+
71+
switch (tabId) {
72+
case SidePanelTab.ASK_DEVTRON:
73+
return {
74+
state: SidePanelTab.ASK_DEVTRON,
75+
}
76+
case SidePanelTab.DOCUMENTATION:
77+
default:
78+
return {
79+
state: SidePanelTab.DOCUMENTATION,
80+
docLink: null,
81+
}
82+
}
83+
}
84+
6585
return (
6686
<>
6787
<div className="border__primary--bottom flexbox dc__gap-12 dc__no-shrink bg__tertiary">
6888
<div className="flexbox flex-grow-1 dc__content-start">
6989
{TABS_CONFIG.map(({ label, iconName, id }) => {
7090
const isSelected = tab === id
7191

72-
const handleTabClick = () => {
73-
setTab(id)
92+
const handleTabClick = ({
93+
currentTarget: {
94+
dataset: { config },
95+
},
96+
}: MouseEvent<HTMLDivElement>) => {
97+
setSidePanelConfig(() => JSON.parse(config))
7498
}
7599

76100
return (
@@ -81,6 +105,7 @@ export const SidePanelContent = ({ onClose, initialTab = SidePanelTab.DOCUMENTAT
81105
onClick={handleTabClick}
82106
style={{ ...(isSelected ? { boxShadow: '0 1px 0 0 var(--bg-primary)' } : {}) }}
83107
tabIndex={0}
108+
data-config={JSON.stringify(getConfigForTab(id))}
84109
>
85110
<Icon name={iconName} color={isSelected ? 'N900' : 'N700'} />
86111

src/components/common/SidePanel/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { SidePanelTab, TabConfig } from './types'
1+
import { SidePanelTab } from '@devtron-labs/devtron-fe-common-lib'
2+
3+
import { TabConfig } from './types'
24

35
export const SIDE_PANEL_MIN_ASIDE_WIDTH = 362
46

src/components/common/SidePanel/types.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FunctionComponent } from 'react'
22

3-
import { IconName, useMotionValue } from '@devtron-labs/devtron-fe-common-lib'
3+
import { IconName, MainContext, SidePanelTab, useMotionValue } from '@devtron-labs/devtron-fe-common-lib'
44

55
export interface SidePanelProps {
66
asideWidth: ReturnType<typeof useMotionValue<number>>
@@ -11,13 +11,10 @@ export interface SidePanelContentBaseProps {
1111
}
1212

1313
export interface SidePanelContentProps {
14-
initialTab?: SidePanelTab
14+
tab?: SidePanelTab
1515
onClose: () => void
16-
}
17-
18-
export enum SidePanelTab {
19-
DOCUMENTATION = 'documentation',
20-
ASK_DEVTRON = 'ask-devtron',
16+
setSidePanelConfig: MainContext['setSidePanelConfig']
17+
sidePanelConfig: MainContext['sidePanelConfig']
2118
}
2219

2320
export interface TabConfig {

src/components/common/navigation/NavigationRoutes.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default function NavigationRoutes({ reloadVersionConfig }: Readonly<Navig
158158
const [licenseInfoDialogType, setLicenseInfoDialogType] = useState<LicenseInfoDialogType>(null)
159159
const [intelligenceConfig, setIntelligenceConfig] = useState<IntelligenceConfig>(null)
160160

161-
const [sidePanelConfig, setSidePanelConfig] = useState<SidePanelConfig>({ open: false })
161+
const [sidePanelConfig, setSidePanelConfig] = useState<SidePanelConfig>({ state: 'closed' })
162162
const asideWidth = useMotionValue(0)
163163

164164
const {
@@ -522,7 +522,6 @@ export default function NavigationRoutes({ reloadVersionConfig }: Readonly<Navig
522522
handleUpdateUserThemePreference={handleUpdateUserThemePreference}
523523
/>
524524
)}
525-
{AIChat && window._env_?.FEATURE_AI_APP_DETAILS_ENABLE && <AIChat parentRef={parentRef} {...aiAgentContext} />}
526525
{renderAboutDevtronDialog()}
527526
{!isOnboardingPage && (
528527
<Navigation

0 commit comments

Comments
 (0)