Skip to content

Commit b3d7429

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/dashboard into fix/theming-v3
2 parents 0fe167d + 77ba48c commit b3d7429

File tree

7 files changed

+54
-47
lines changed

7 files changed

+54
-47
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "1.7.6",
7+
"@devtron-labs/devtron-fe-common-lib": "1.7.7",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/components/common/DynamicTabs/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ export const FALLBACK_TAB = 1
1818

1919
export const TAB_DATA_LOCAL_STORAGE_KEY = 'persisted-tabs-data'
2020

21-
export const TAB_DATA_VERSION = 'v1'
21+
export const TAB_DATA_VERSION = 'v2'

src/components/common/DynamicTabs/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ export interface TimerType {
7272
format?: (start: Dayjs, now: Dayjs) => string
7373
}
7474

75-
export type ParsedTabsData = {
75+
export type ParsedTabsDataV1 = {
7676
key: string
7777
data: DynamicTabType[]
78+
version: 'v1'
79+
}
80+
81+
export type ParsedTabsData = {
82+
data: Record<string, DynamicTabType[]>
7883
version: typeof TAB_DATA_VERSION
7984
}
8085

src/components/common/DynamicTabs/useTabs.ts

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import dayjs from 'dayjs'
1919
import { noop, InitTabType, DynamicTabType } from '@devtron-labs/devtron-fe-common-lib'
2020
import { AddTabParamsType, ParsedTabsData, PopulateTabDataPropsType, UseTabsReturnType } from './types'
2121
import { FALLBACK_TAB, TAB_DATA_LOCAL_STORAGE_KEY, TAB_DATA_VERSION } from './constants'
22+
import { convertV1TabsDataToV2 } from './utils'
2223

2324
export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB): UseTabsReturnType {
2425
const [tabs, setTabs] = useState<DynamicTabType[]>([])
@@ -104,17 +105,15 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
104105
} else {
105106
const persistedTabsData = getTabDataFromLocalStorage()
106107
try {
107-
_parsedTabsData = JSON.parse(persistedTabsData)
108+
_parsedTabsData = convertV1TabsDataToV2(JSON.parse(persistedTabsData))
108109
} catch {
109110
noop()
110111
}
111112
}
112113

113114
return JSON.stringify({
114-
..._parsedTabsData,
115-
key: persistenceKey,
116115
version: TAB_DATA_VERSION,
117-
data: _tabs,
116+
data: { ..._parsedTabsData?.data, [persistenceKey]: _tabs },
118117
})
119118
}
120119

@@ -170,46 +169,27 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
170169
overrideSelectionStatus = false,
171170
) => {
172171
let _tabs: DynamicTabType[] = []
173-
let tabDataVersion = TAB_DATA_VERSION
174172
let parsedTabsData: ParsedTabsData
175173

176174
setTabs((prevTabs) => {
177175
if (!reInit) {
178176
const persistedTabsData = getTabDataFromLocalStorage()
179177
try {
180-
parsedTabsData = JSON.parse(persistedTabsData)
181-
_tabs = persistedTabsData ? parsedTabsData.data : prevTabs
182-
tabDataVersion = parsedTabsData?.version
178+
parsedTabsData = convertV1TabsDataToV2(JSON.parse(persistedTabsData))
179+
_tabs = parsedTabsData ? parsedTabsData.data[persistenceKey] : prevTabs
183180
} catch {
184181
_tabs = prevTabs
185182
}
186183
}
187184
if (_tabs.length > 0) {
188-
_tabs = _tabs.map((_tab) => {
189-
// Backward compatibility with position
190-
const type =
191-
_tab.type ??
192-
('position' in _tab && _tab.position === Number.MAX_SAFE_INTEGER ? 'dynamic' : 'fixed')
193-
194-
return {
195-
..._tab,
196-
// NOTE: if reInit && overrideSelectionStatus is false, we need to retain the current selection
197-
// if reInit is true, we need to remove old selection and use the provided initTabs' selection
198-
// or fallback if user has sent all initTabs with isSelected false
199-
...(reInit || overrideSelectionStatus ? { isSelected: false } : {}),
200-
/* NOTE: following lines migrate old tab data to new */
201-
lastSyncMoment: dayjs(),
202-
...(_tab.componentKey
203-
? { componentKey: _tab.componentKey }
204-
: { componentKey: getNewTabComponentKey(_tab.id) }),
205-
...(_tab.isAlive ? { isAlive: _tab.isAlive } : { isAlive: false }),
206-
type,
207-
id:
208-
tabDataVersion !== TAB_DATA_VERSION && type === 'fixed' && _tab.id
209-
? _tab.id.split('-')[0]
210-
: _tab.id,
211-
}
212-
})
185+
_tabs = _tabs.map((_tab) => ({
186+
..._tab,
187+
// NOTE: if reInit && overrideSelectionStatus is false, we need to retain the current selection
188+
// if reInit is true, we need to remove old selection and use the provided initTabs' selection
189+
// or fallback if user has sent all initTabs with isSelected false
190+
...(reInit || overrideSelectionStatus ? { isSelected: false } : {}),
191+
lastSyncMoment: dayjs(),
192+
}))
213193
if (tabsToRemove?.length) {
214194
_tabs = _tabs.filter((_tab) => tabsToRemove.indexOf(_tab.id) === -1)
215195
}

src/components/common/DynamicTabs/utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
import { Dayjs } from 'dayjs'
1818
import { MARK_AS_STALE_DATA_CUT_OFF_MINS } from '../../ResourceBrowser/Constants'
19-
import { DynamicTabsVariantType } from './types'
19+
import { DynamicTabsVariantType, ParsedTabsData, ParsedTabsDataV1 } from './types'
20+
import { TAB_DATA_VERSION } from './constants'
2021

2122
export const checkIfDataIsStale = (start: Dayjs, now: Dayjs): boolean =>
2223
now.diff(start, 'minutes') > MARK_AS_STALE_DATA_CUT_OFF_MINS
@@ -33,3 +34,14 @@ export const getClassNameForVariant = (variant: DynamicTabsVariantType) => {
3334
return ''
3435
}
3536
}
37+
38+
export const convertV1TabsDataToV2 = (tabsData: ParsedTabsDataV1 | ParsedTabsData): ParsedTabsData => {
39+
if (tabsData.version === TAB_DATA_VERSION) {
40+
return tabsData
41+
}
42+
43+
return {
44+
data: { [tabsData.key]: tabsData.data },
45+
version: TAB_DATA_VERSION,
46+
}
47+
}

src/components/common/navigation/NavigationRoutes.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import 'monaco-editor'
6767
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
6868
import YamlWorker from '../../../yaml.worker.js?worker'
6969
import { TAB_DATA_LOCAL_STORAGE_KEY } from '../DynamicTabs/constants'
70+
import { ParsedTabsData, ParsedTabsDataV1 } from '../DynamicTabs/types'
7071

7172
// Monaco Editor worker initialization
7273
self.MonacoEnvironment = {
@@ -304,12 +305,21 @@ export default function NavigationRoutes() {
304305
const persistedTabs = localStorage.getItem(TAB_DATA_LOCAL_STORAGE_KEY)
305306
if (persistedTabs) {
306307
try {
307-
const parsedTabsData = JSON.parse(persistedTabs)
308-
if (
309-
location.pathname === parsedTabsData.key ||
310-
!location.pathname.startsWith(`${parsedTabsData.key}/`)
311-
) {
312-
localStorage.removeItem(TAB_DATA_LOCAL_STORAGE_KEY)
308+
const parsedTabsData: ParsedTabsData | ParsedTabsDataV1 = JSON.parse(persistedTabs)
309+
if (parsedTabsData.version === 'v1') {
310+
if (
311+
location.pathname === parsedTabsData.key ||
312+
!location.pathname.startsWith(`${parsedTabsData.key}/`)
313+
) {
314+
localStorage.removeItem(TAB_DATA_LOCAL_STORAGE_KEY)
315+
}
316+
} else {
317+
const keys = Object.keys(parsedTabsData.data)
318+
if (
319+
keys.every((key) => location.pathname !== key && !location.pathname.startsWith(`${key}/`))
320+
) {
321+
localStorage.removeItem(TAB_DATA_LOCAL_STORAGE_KEY)
322+
}
313323
}
314324
} catch {
315325
localStorage.removeItem(TAB_DATA_LOCAL_STORAGE_KEY)

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,10 @@
11051105
dependencies:
11061106
"@jridgewell/trace-mapping" "0.3.9"
11071107

1108-
"@devtron-labs/[email protected].6":
1109-
version "1.7.6"
1110-
resolved "https://registry.yarnpkg.com/@devtron-labs/devtron-fe-common-lib/-/devtron-fe-common-lib-1.7.6.tgz#59c85b4a7408d8606044191f3931b56ff759196f"
1111-
integrity sha512-vEy7EgLQu3gI0SPRSvQ3Y7GAvjRjhFAk12Rq88p+cJmilg+fHEjVRmmcUapqkB9Cmc1dIq3LkWuOkQ9rNyYLfA==
1108+
"@devtron-labs/[email protected].7":
1109+
version "1.7.7"
1110+
resolved "https://registry.yarnpkg.com/@devtron-labs/devtron-fe-common-lib/-/devtron-fe-common-lib-1.7.7.tgz#4ca45cb7e1e5721d0c6ece2040c764bb613a4208"
1111+
integrity sha512-caCJaAllzaV3Qr9ehx3SnHe9XsYBn1NzXZzkXP32wgquAchdoI8I1N35Ywleo5rpbT1NagC7py0qv9oeSa3MCQ==
11121112
dependencies:
11131113
"@codemirror/lang-json" "6.0.1"
11141114
"@codemirror/lang-yaml" "6.1.2"

0 commit comments

Comments
 (0)