Skip to content

Commit af340f7

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-lib into feat/use-register-shortcut
2 parents 88eaa2e + aa3d21f commit af340f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1514
-879
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.4.3-beta-6",
3+
"version": "0.5.3",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading

src/Assets/Icon/ic-file-code.svg

Lines changed: 7 additions & 0 deletions
Loading

src/Common/ChartVersionAndTypeSelector.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,17 @@ const ChartVersionAndTypeSelector = ({ setSelectedChartRefId }: ChartVersionAndT
7272
<div className="chart-type-options flex" data-testid="chart-type-options">
7373
<span className="cn-7 mr-4">Chart Type</span>
7474
<SelectPicker
75-
inputId='chart-type-select'
76-
label='Chart Type'
75+
inputId="chart-type-select"
7776
value={selectedChartType ?? chartTypeOptions[0]}
7877
options={chartTypeOptions}
7978
onChange={handleChartTypeChange}
8079
variant={SelectPickerVariantType.BORDER_LESS}
8180
/>
8281
</div>
8382
<div className="chart-version-options flex" data-testid="chart-version-options">
84-
<span className="cn-7 mr-4">Chart Version</span>
83+
<span className="cn-7 mr-4">Chart Version</span>
8584
<SelectPicker
86-
inputId='chart-version-select'
85+
inputId="chart-version-select"
8786
value={selectedChartVersion ?? chartVersionOptions[0]}
8887
options={chartVersionOptions}
8988
onChange={handleChartVersionChange}

src/Common/Helper.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,3 +937,19 @@ export function asyncWrap(promise): any[] {
937937
}
938938

939939
export const prefixZeroIfSingleDigit = (value: number = 0) => (value > 0 && value < 10 ? `0${value}` : value)
940+
941+
export const throttle = <T extends (...args: unknown[]) => unknown>(
942+
func: T,
943+
delay: number = 300,
944+
): ((...args: Parameters<T>) => void) => {
945+
let lastCall = 0
946+
947+
return (...args: Parameters<T>) => {
948+
const now = Date.now()
949+
950+
if (now - lastCall >= delay) {
951+
lastCall = now
952+
func(...args)
953+
}
954+
}
955+
}

src/Common/RJSF/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const parseSchemaHiddenType = (hiddenSchema: HiddenType): MetaHiddenType
166166
const clone = structuredClone(hiddenSchema)
167167
if (typeof clone === 'string') {
168168
return {
169-
value: false,
169+
value: true,
170170
path: conformPathToPointers(clone),
171171
}
172172
}

src/Common/Toggle/Toggle.tsx

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

17-
import React from 'react'
18-
import { useEffectAfterMount } from '../Helper'
17+
import React, { useCallback } from 'react'
18+
import { throttle, useEffectAfterMount } from '../Helper'
1919
import './Toggle.scss'
2020

2121
const Toggle = ({
@@ -27,6 +27,7 @@ const Toggle = ({
2727
dataTestId = 'handle-toggle-button',
2828
Icon = null,
2929
iconClass = '',
30+
throttleOnChange = false,
3031
...props
3132
}) => {
3233
const [active, setActive] = React.useState(selected)
@@ -49,13 +50,20 @@ const Toggle = ({
4950
}
5051
}
5152

53+
const throttledHandleClick = useCallback(throttle(handleClick, 500), [disabled])
54+
5255
return (
5356
<label
5457
{...props}
5558
className={`${rootClassName} toggle__switch ${disabled ? 'disabled' : ''}`}
5659
style={{ ['--color' as any]: color }}
5760
>
58-
<input type="checkbox" checked={!!active} onChange={handleClick} className="toggle__input" />
61+
<input
62+
type="checkbox"
63+
checked={!!active}
64+
onChange={throttleOnChange ? throttledHandleClick : handleClick}
65+
className="toggle__input"
66+
/>
5967
<span className={`toggle__slider ${Icon ? 'with-icon br-4 dc__border' : 'round'}`} data-testid={dataTestId}>
6068
{Icon && <Icon className={`icon-dim-20 br-4 p-2 ${iconClass}`} />}
6169
</span>
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
import { useMemo, useState } from 'react'
2+
import { generatePath, Route, Switch, useLocation, useRouteMatch } from 'react-router-dom'
3+
4+
import { ReactComponent as ICError } from '@Icons/ic-error.svg'
5+
import { getAppEnvDeploymentConfigList } from '@Shared/Components/DeploymentConfigDiff'
6+
import { useAsync } from '@Common/Helper'
7+
import { EnvResourceType, getAppEnvDeploymentConfig } from '@Shared/Services'
8+
import { groupArrayByObjectKey } from '@Shared/Helpers'
9+
import ErrorScreenManager from '@Common/ErrorScreenManager'
10+
import { Progressing } from '@Common/Progressing'
11+
import { useUrlFilters } from '@Common/Hooks'
12+
import { GenericEmptyState, InfoColourBar } from '@Common/index'
13+
14+
import { DeploymentHistoryConfigDiffCompare } from './DeploymentHistoryConfigDiffCompare'
15+
import { DeploymentHistoryConfigDiffProps, DeploymentHistoryConfigDiffQueryParams } from './types'
16+
import {
17+
getPipelineDeploymentsWfrIds,
18+
getPipelineDeployments,
19+
parseDeploymentHistoryDiffSearchParams,
20+
isDeploymentHistoryConfigDiffNotFoundError,
21+
getDeploymentHistoryConfigDiffError,
22+
} from './utils'
23+
import { renderDeploymentHistoryConfig } from './helpers'
24+
25+
export const DeploymentHistoryConfigDiff = ({
26+
appName,
27+
envName,
28+
pipelineId,
29+
wfrId,
30+
triggerHistory,
31+
setFullScreenView,
32+
runSource,
33+
resourceId,
34+
renderRunSource,
35+
}: DeploymentHistoryConfigDiffProps) => {
36+
// HOOKS
37+
const { path, params } = useRouteMatch()
38+
const { pathname, search } = useLocation()
39+
40+
// CONSTANTS
41+
const pipelineDeployments = useMemo(() => getPipelineDeployments(triggerHistory), [triggerHistory])
42+
const { currentWfrId, previousWfrId } = useMemo(
43+
() => getPipelineDeploymentsWfrIds({ pipelineDeployments, wfrId }),
44+
[pipelineDeployments, wfrId],
45+
)
46+
const isPreviousDeploymentConfigAvailable = !!previousWfrId
47+
48+
// URL FILTERS
49+
const { compareWfrId } = useUrlFilters<string, DeploymentHistoryConfigDiffQueryParams>({
50+
parseSearchParams: parseDeploymentHistoryDiffSearchParams(previousWfrId),
51+
})
52+
53+
// STATES
54+
const [convertVariables, setConvertVariables] = useState(false)
55+
56+
// ASYNC CALLS
57+
// Load comparison deployment data
58+
const [compareDeploymentConfigLoader, compareDeploymentConfig, , reloadCompareDeploymentConfig] = useAsync(
59+
() =>
60+
Promise.allSettled([
61+
getAppEnvDeploymentConfig({
62+
params: {
63+
appName,
64+
envName,
65+
configArea: 'DeploymentHistory',
66+
pipelineId,
67+
wfrId: currentWfrId,
68+
},
69+
}),
70+
isPreviousDeploymentConfigAvailable
71+
? getAppEnvDeploymentConfig({
72+
params: {
73+
appName,
74+
envName,
75+
configArea: 'DeploymentHistory',
76+
pipelineId,
77+
wfrId: compareWfrId,
78+
},
79+
})
80+
: null,
81+
]),
82+
[currentWfrId, compareWfrId],
83+
)
84+
85+
// METHODS
86+
const getNavItemHref = (resourceType: EnvResourceType, resourceName: string) =>
87+
`${generatePath(path, { ...params })}/${resourceType}${resourceName ? `/${resourceName}` : ''}${search}`
88+
89+
// Generate the deployment history config list
90+
const deploymentConfigList = useMemo(() => {
91+
if (!compareDeploymentConfigLoader && compareDeploymentConfig) {
92+
const compareList =
93+
isPreviousDeploymentConfigAvailable && compareDeploymentConfig[1].status === 'fulfilled'
94+
? compareDeploymentConfig[1].value.result
95+
: {
96+
configMapData: null,
97+
deploymentTemplate: null,
98+
secretsData: null,
99+
isAppAdmin: false,
100+
}
101+
102+
const currentList =
103+
compareDeploymentConfig[0].status === 'fulfilled' ? compareDeploymentConfig[0].value.result : null
104+
105+
const configData = getAppEnvDeploymentConfigList({
106+
currentList,
107+
compareList,
108+
getNavItemHref,
109+
convertVariables,
110+
})
111+
return configData
112+
}
113+
114+
return null
115+
}, [isPreviousDeploymentConfigAvailable, compareDeploymentConfigLoader, compareDeploymentConfig, convertVariables])
116+
117+
const compareDeploymentConfigErr = useMemo(
118+
() =>
119+
!compareDeploymentConfigLoader && compareDeploymentConfig
120+
? getDeploymentHistoryConfigDiffError(compareDeploymentConfig[0]) ||
121+
getDeploymentHistoryConfigDiffError(compareDeploymentConfig[1])
122+
: null,
123+
[compareDeploymentConfigLoader, compareDeploymentConfig],
124+
)
125+
126+
const groupedDeploymentConfigList = useMemo(
127+
() => (deploymentConfigList ? groupArrayByObjectKey(deploymentConfigList.configList, 'groupHeader') : []),
128+
[deploymentConfigList],
129+
)
130+
131+
/** Previous deployment config has 404 error. */
132+
const hasPreviousDeploymentConfigNotFoundError =
133+
compareDeploymentConfig && isDeploymentHistoryConfigDiffNotFoundError(compareDeploymentConfig[1])
134+
/** Hide diff state if the previous deployment config is unavailable or returns a 404 error. */
135+
const hideDiffState = !isPreviousDeploymentConfigAvailable || hasPreviousDeploymentConfigNotFoundError
136+
// LOADING
137+
const isLoading = compareDeploymentConfigLoader || (!compareDeploymentConfigErr && !deploymentConfigList)
138+
// ERROR CONFIG
139+
const errorConfig = {
140+
code: compareDeploymentConfigErr?.code,
141+
error: compareDeploymentConfigErr && !compareDeploymentConfigLoader,
142+
reload: reloadCompareDeploymentConfig,
143+
}
144+
145+
if (compareDeploymentConfig && isDeploymentHistoryConfigDiffNotFoundError(compareDeploymentConfig[0])) {
146+
return (
147+
<div className="flex bcn-0 h-100">
148+
<GenericEmptyState
149+
title="Data not available"
150+
subTitle="Configurations used for this deployment execution is not available"
151+
/>
152+
</div>
153+
)
154+
}
155+
156+
return (
157+
<Switch>
158+
<Route path={`${path}/:resourceType(${Object.values(EnvResourceType).join('|')})/:resourceName?`}>
159+
<DeploymentHistoryConfigDiffCompare
160+
{...deploymentConfigList}
161+
isLoading={isLoading}
162+
errorConfig={errorConfig}
163+
envName={envName}
164+
wfrId={wfrId}
165+
previousWfrId={previousWfrId}
166+
pipelineDeployments={pipelineDeployments}
167+
setFullScreenView={setFullScreenView}
168+
convertVariables={convertVariables}
169+
setConvertVariables={setConvertVariables}
170+
runSource={runSource}
171+
resourceId={resourceId}
172+
renderRunSource={renderRunSource}
173+
hideDiffState={hideDiffState}
174+
isCompareDeploymentConfigNotAvailable={hasPreviousDeploymentConfigNotFoundError}
175+
/>
176+
</Route>
177+
<Route>
178+
{compareDeploymentConfigErr && !compareDeploymentConfigLoader ? (
179+
<ErrorScreenManager code={errorConfig.code} reload={errorConfig.reload} />
180+
) : (
181+
<div className="p-16 flexbox-col dc__gap-16 bcn-0 h-100">
182+
{isLoading ? (
183+
<Progressing fullHeight size={48} />
184+
) : (
185+
<>
186+
<h3 className="fs-13 lh-20 fw-6 cn-9 m-0">
187+
{hideDiffState
188+
? 'Configurations used for this deployment trigger'
189+
: 'Showing configuration change with respect to previous deployment'}
190+
</h3>
191+
<div className="flexbox-col dc__gap-16 dc__mxw-800">
192+
<div className="flexbox-col dc__gap-12">
193+
{Object.keys(groupedDeploymentConfigList).map((groupHeader) =>
194+
renderDeploymentHistoryConfig(
195+
groupedDeploymentConfigList[groupHeader],
196+
groupHeader !== 'UNGROUPED' ? groupHeader : null,
197+
pathname,
198+
hideDiffState,
199+
),
200+
)}
201+
</div>
202+
{hasPreviousDeploymentConfigNotFoundError && (
203+
<InfoColourBar
204+
classname="error_bar cn-9 fs-13 lh-20"
205+
Icon={ICError}
206+
message="Diff unavailable: Configurations for previous deployment not found."
207+
/>
208+
)}
209+
</div>
210+
</>
211+
)}
212+
</div>
213+
)}
214+
</Route>
215+
</Switch>
216+
)
217+
}

0 commit comments

Comments
 (0)