Skip to content

Commit 0a75eaf

Browse files
authored
Merge branch 'develop' into feat/secrets-mgr
2 parents b1e113a + b7a148f commit 0a75eaf

File tree

24 files changed

+407
-264
lines changed

24 files changed

+407
-264
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.18.1-pre-5",
7+
"@devtron-labs/devtron-fe-common-lib": "1.18.1-pre-6",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/Pages/Shared/ConfigMapSecret/ConfigMapSecret.wrapper.tsx

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useRef } from 'react'
1817
import { useParams } from 'react-router-dom'
1918

20-
import {
21-
abortPreviousRequests,
22-
CMSecretComponentType,
23-
ErrorScreenManager,
24-
getIsRequestAborted,
25-
Progressing,
26-
showError,
27-
useAsync,
28-
} from '@devtron-labs/devtron-fe-common-lib'
19+
import { CMSecretComponentType, ErrorScreenManager, Progressing, useQuery } from '@devtron-labs/devtron-fe-common-lib'
2920

30-
import { ComponentStates } from '@Pages/Shared/EnvironmentOverride/EnvironmentOverrides.types'
3121
import { getAppChartRefForAppAndEnv } from '@Services/service'
3222

3323
import { ConfigMapSecretContainer } from './ConfigMapSecretContainer'
@@ -36,53 +26,37 @@ import { CMSecretWrapperProps } from './types'
3626

3727
export const ConfigMapSecretWrapper = (props: CMSecretWrapperProps) => {
3828
// PROPS
39-
const {
40-
componentType = CMSecretComponentType.ConfigMap,
41-
parentState,
42-
setParentState,
43-
onErrorRedirectURL,
44-
isTemplateView,
45-
} = props
29+
const { componentType = CMSecretComponentType.ConfigMap, onErrorRedirectURL, isTemplateView } = props
4630

4731
// HOOKS
4832
const { appId, envId, name } = useParams<{ appId: string; envId: string; name: string }>()
4933

50-
// REFS
51-
const abortControllerRef = useRef<AbortController>(new AbortController())
52-
53-
// ASYNC CALLS
54-
const [appChartRefLoading, appChartRefRes, appChartRefErr, reload] = useAsync(
55-
() =>
56-
abortPreviousRequests(() => getAppChartRefForAppAndEnv(+appId, +envId, isTemplateView), abortControllerRef),
57-
[componentType],
58-
)
59-
60-
useEffect(() => {
61-
if (appChartRefRes) {
62-
setParentState?.(ComponentStates.loaded)
63-
}
64-
if (appChartRefErr && !getIsRequestAborted(appChartRefErr)) {
65-
setParentState?.(ComponentStates.failed)
66-
showError(appChartRefErr)
67-
}
68-
69-
return () => {
70-
setParentState?.(ComponentStates.loading)
71-
}
72-
}, [appChartRefRes, appChartRefErr])
73-
74-
if (parentState === ComponentStates.loading || appChartRefLoading || getIsRequestAborted(appChartRefErr)) {
34+
const {
35+
data: appChartRef,
36+
isLoading,
37+
isFetching,
38+
error: appChartRefErr,
39+
refetch,
40+
} = useQuery({
41+
queryFn: ({ signal }) => getAppChartRefForAppAndEnv(+appId, +envId, isTemplateView, signal),
42+
queryKey: [componentType, appId, envId, isTemplateView],
43+
select: ({ result }) => result,
44+
})
45+
46+
const appChartRefLoading = isLoading || isFetching
47+
48+
if (appChartRefLoading) {
7549
return <Progressing fullHeight pageLoader />
7650
}
7751

7852
if (appChartRefErr) {
79-
return <ErrorScreenManager code={appChartRefErr.code} redirectURL={onErrorRedirectURL} reload={reload} />
53+
return <ErrorScreenManager code={appChartRefErr.code} redirectURL={onErrorRedirectURL} reload={refetch} />
8054
}
8155

8256
return (
8357
<ConfigMapSecretContainer
8458
key={`${CM_SECRET_COMPONENT_NAME[componentType]}-${name}`}
85-
appChartRef={appChartRefRes?.result}
59+
appChartRef={appChartRef}
8660
{...props}
8761
/>
8862
)

src/Pages/Shared/ConfigMapSecret/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Dispatch, MutableRefObject, SetStateAction } from 'react'
17+
import { MutableRefObject } from 'react'
1818

1919
import {
2020
AppConfigProps,
@@ -36,7 +36,7 @@ import {
3636

3737
import { ConfigToolbarProps } from '@Pages/Applications'
3838

39-
import { ComponentStates, EnvironmentOverrideComponentProps } from '../EnvironmentOverride/EnvironmentOverrides.types'
39+
import { EnvironmentOverrideComponentProps } from '../EnvironmentOverride/EnvironmentOverrides.types'
4040

4141
// PAYLOAD PROPS
4242
export interface CMSecretDraftPayloadType {
@@ -74,8 +74,6 @@ export interface CMSecretWrapperProps
7474
> {
7575
componentType?: CMSecretComponentType
7676
parentName?: string
77-
parentState?: ComponentStates
78-
setParentState?: Dispatch<SetStateAction<ComponentStates>>
7977
clusterId?: string
8078
isApprovalPolicyConfigured?: boolean
8179
envName: string

src/Pages/Shared/EnvironmentOverride/EnvironmentOverride.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useState } from 'react'
17+
import { useEffect } from 'react'
1818
import { generatePath, Route, Switch, useHistory, useLocation, useParams, useRouteMatch } from 'react-router-dom'
1919

2020
import {
2121
ApprovalConfigDataKindType,
2222
CMSecretComponentType,
2323
getIsApprovalPolicyConfigured,
24-
Reload,
2524
} from '@devtron-labs/devtron-fe-common-lib'
2625

2726
import { ErrorBoundary, mapByKey, useAppContext } from '@Components/common'
2827
import { APP_COMPOSE_STAGE, getAppComposeURL, URLS } from '@Config/index'
2928
import { DeploymentTemplate } from '@Pages/Applications'
3029
import { ConfigMapSecretWrapper } from '@Pages/Shared/ConfigMapSecret/ConfigMapSecret.wrapper'
3130

32-
import { ComponentStates, EnvironmentOverrideComponentProps } from './EnvironmentOverrides.types'
31+
import { EnvironmentOverrideComponentProps } from './EnvironmentOverrides.types'
3332

3433
import './environmentOverride.scss'
3534

@@ -48,7 +47,6 @@ const EnvironmentOverride = ({
4847
}: EnvironmentOverrideComponentProps) => {
4948
const isAppGroupView = !!envName
5049
const params = useParams<{ appId: string; envId: string }>()
51-
const [viewState, setViewState] = useState<ComponentStates>(null)
5250
const { path, url } = useRouteMatch()
5351
const { push } = useHistory()
5452
const location = useLocation()
@@ -79,24 +77,9 @@ const EnvironmentOverride = ({
7977
}
8078
}, [])
8179

82-
useEffect(() => {
83-
if (viewState === ComponentStates.reloading) {
84-
reloadEnvironments()
85-
}
86-
}, [viewState])
87-
8880
if (!params.envId) {
8981
return null
9082
}
91-
if (viewState === ComponentStates.failed) {
92-
return (
93-
<Reload
94-
reload={() => {
95-
setViewState(ComponentStates.reloading)
96-
}}
97-
/>
98-
)
99-
}
10083

10184
if (params.envId && !environmentsMap.has(+params.envId) && environments.length) {
10285
const newUrl = url.replace(
@@ -164,9 +147,7 @@ const EnvironmentOverride = ({
164147
isApprovalPolicyConfigured={getIsApprovalPolicyConfigured(
165148
approvalConfigMap?.[ApprovalConfigDataKindType.configMap],
166149
)}
167-
parentState={viewState}
168150
parentName={getParentName()}
169-
setParentState={setViewState}
170151
clusterId={clusterId}
171152
envConfig={envConfig}
172153
fetchEnvConfig={fetchEnvConfig}
@@ -185,9 +166,7 @@ const EnvironmentOverride = ({
185166
isApprovalPolicyConfigured={getIsApprovalPolicyConfigured(
186167
approvalConfigMap?.[ApprovalConfigDataKindType.configSecret],
187168
)}
188-
parentState={viewState}
189169
parentName={getParentName()}
190-
setParentState={setViewState}
191170
clusterId={environmentsMap.get(+params.envId)?.clusterId?.toString()}
192171
componentType={CMSecretComponentType.Secret}
193172
envConfig={envConfig}

src/Pages/Shared/EnvironmentOverride/EnvironmentOverrides.types.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React from 'react'
18-
1917
import { AppConfigProps } from '@devtron-labs/devtron-fe-common-lib'
2018

2119
import {
@@ -25,14 +23,6 @@ import {
2523

2624
import { ConfigAppList } from '../../../components/ApplicationGroup/AppGroup.types'
2725

28-
export enum ComponentStates {
29-
loading = 'loading',
30-
loaded = 'loaded',
31-
success = 'success',
32-
failed = 'failed',
33-
reloading = 'reloading',
34-
}
35-
3626
export interface EnvironmentOverrideComponentProps extends Required<Pick<AppConfigProps, 'isTemplateView'>> {
3727
appList?: ConfigAppList[]
3828
environments: AppConfigState['environmentList']
@@ -46,12 +36,6 @@ export interface EnvironmentOverrideComponentProps extends Required<Pick<AppConf
4636
appOrEnvIdToResourceApprovalConfigurationMap: AppConfigState['envIdToEnvApprovalConfigurationMap']
4737
}
4838

49-
export interface CommonEnvironmentOverridesProps {
50-
parentState: ComponentStates
51-
setParentState: React.Dispatch<React.SetStateAction<ComponentStates>>
52-
isJobView?: boolean
53-
}
54-
5539
export interface ListComponentType {
5640
name: string
5741
type: string

src/components/CIPipelineN/AdvancedConfigOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import CIConfig from '../ciConfig/CIConfig'
2020
import DockerArgs from './DockerArgs'
2121
import CustomImageTags from './CustomImageTags'
2222
import TargetPlatformSelector from '../ciConfig/TargetPlatformSelector'
23-
import { ComponentStates } from '../../Pages/Shared/EnvironmentOverride/EnvironmentOverrides.types'
2423
import { AdvancedConfigOptionsProps, CIConfigParentState } from '../ciConfig/types'
2524
import { DockerConfigOverrideKeys } from '../ciPipeline/types'
2625
import { getTargetPlatformMap } from '../ciConfig/CIConfig.utils'
2726
import { pipelineContext } from '../workflowEditor/workflowEditor'
2827
import '../ciConfig/CIConfig.scss'
28+
import { ComponentStates } from './types'
2929

3030
export default function AdvancedConfigOptions({ ciPipeline, appId, isTemplateView }: AdvancedConfigOptionsProps) {
3131
const { formData, setFormData, loadingState, setLoadingState, formDataErrorObj, setFormDataErrorObj } =

src/components/CIPipelineN/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ export interface EnvironmentListType {
7373
setSelectedEnv?: React.Dispatch<React.SetStateAction<EnvironmentWithSelectPickerType>>
7474
isBorderLess?: boolean
7575
}
76+
77+
export enum ComponentStates {
78+
loading = 'loading',
79+
loaded = 'loaded',
80+
success = 'success',
81+
failed = 'failed',
82+
reloading = 'reloading',
83+
}

src/components/ClusterNodes/NodeDetails.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ import {
4444
RESOURCE_BROWSER_ROUTES,
4545
getUrlWithSearchParams,
4646
ResourceBrowserActionMenuEnum,
47+
UNSAVED_CHANGES_PROMPT_MESSAGE,
48+
usePrompt,
4749
} from '@devtron-labs/devtron-fe-common-lib'
48-
import { useParams, useLocation, useHistory, generatePath } from 'react-router-dom'
50+
import { useParams, useLocation, useHistory, generatePath, Prompt } from 'react-router-dom'
4951
import YAML from 'yaml'
5052
import * as jsonpatch from 'fast-json-patch'
5153
import { applyPatch } from 'fast-json-patch'
@@ -111,6 +113,10 @@ const NodeDetails = ({ lowercaseKindToResourceGroupMap, updateTabUrl }: ClusterL
111113
const queryParams = new URLSearchParams(location.search)
112114
const { push, replace } = useHistory()
113115

116+
const hasUnsavedChanges = (nodeDetail?.manifest ? YAMLStringify(nodeDetail.manifest) : '') !== modifiedManifest
117+
118+
usePrompt({ shouldPrompt: hasUnsavedChanges })
119+
114120
const getData = (_patchdata: jsonpatch.Operation[]) => {
115121
setLoader(true)
116122
setErrorResponseCode(null)
@@ -1073,6 +1079,7 @@ const NodeDetails = ({ lowercaseKindToResourceGroupMap, updateTabUrl }: ClusterL
10731079
<Progressing pageLoader size={32} />
10741080
) : (
10751081
<>
1082+
<Prompt when={hasUnsavedChanges} message={UNSAVED_CHANGES_PROMPT_MESSAGE} />
10761083
{renderNodeDetailsTabs()}
10771084
{renderTabContent()}
10781085
{showCordonNodeDialog && (

src/components/ResourceBrowser/Constants.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,12 @@ export const NODE_LIST_HEADERS = [
282282
'status',
283283
'roles',
284284
'errors',
285+
'cpu usage',
286+
'mem usage',
285287
'k8s version',
286288
'node group',
287289
'pods',
288290
'taints',
289-
'cpu usage (%)',
290-
'cpu usage (absolute)',
291-
'cpu allocatable',
292-
'mem usage (%)',
293-
'mem usage (absolute)',
294-
'mem allocatable',
295291
'age',
296292
'unschedulable',
297293
] as const
@@ -315,12 +311,8 @@ export const NODE_LIST_HEADERS_TO_KEY_MAP: Record<(typeof NODE_LIST_HEADERS)[num
315311
'node group': 'nodeGroup',
316312
pods: 'podCount',
317313
taints: 'taintCount',
318-
'cpu usage (%)': 'cpu.usagePercentage',
319-
'cpu usage (absolute)': 'cpu.usage',
320-
'cpu allocatable': 'cpu.allocatable',
321-
'mem usage (%)': 'memory.usagePercentage',
322-
'mem usage (absolute)': 'memory.usage',
323-
'mem allocatable': 'memory.allocatable',
314+
'cpu usage': 'cpu.usagePercentage',
315+
'mem usage': 'memory.usagePercentage',
324316
age: 'age',
325317
unschedulable: 'unschedulable',
326318
} as const

src/components/ResourceBrowser/ResourceList/ColumnSelector.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { MultiValue, SelectInstance } from 'react-select'
1919

2020
import {
2121
ButtonVariantType,
22+
deepEqual,
2223
Icon,
2324
SelectPicker,
2425
SelectPickerOptionType,
@@ -64,13 +65,6 @@ const ColumnSelector = ({ setVisibleColumns, visibleColumns, allColumns }: Colum
6465
setSelectedColumns(getSelectedColumns())
6566
}, [allColumns])
6667

67-
const handleMenuClose = () => {
68-
setIsMenuOpen(false)
69-
resetTriggerAutoClickTimestamp()
70-
71-
selectRef.current?.blur()
72-
}
73-
7468
const onChange = (newValue: MultiValue<SelectPickerOptionType<TableColumnType>>) => {
7569
setTriggerAutoClickTimestampToNow()
7670
setSelectedColumns(newValue)
@@ -90,7 +84,14 @@ const ColumnSelector = ({ setVisibleColumns, visibleColumns, allColumns }: Colum
9084

9185
selectRef.current?.blur()
9286

93-
setVisibleColumns(newVisibleColumns)
87+
if (!deepEqual(newVisibleColumns, visibleColumns.slice(1))) {
88+
setVisibleColumns(newVisibleColumns)
89+
}
90+
}
91+
92+
const handleMenuClose = () => {
93+
handleApplySelectedColumns()
94+
resetTriggerAutoClickTimestamp()
9495
}
9596

9697
return (

0 commit comments

Comments
 (0)