Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ddff3ac
refactor: Collapsible List, DeploymentConfigDiffNavigation: add suppo…
RohitRaj011 Aug 9, 2024
b58d82b
feat: SelectPicker - add support to show tippy on option
RohitRaj011 Aug 9, 2024
97aab9d
refactor: DeploymentConfigDiff - css refactor, add prop to hide divid…
RohitRaj011 Aug 9, 2024
cb4a62a
feat: DeploymentConfigDiff - Scope Variables Support & code refactor
RohitRaj011 Sep 19, 2024
90dd9f1
chore: version bump
RohitRaj011 Sep 19, 2024
e5e69fd
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Sep 23, 2024
ee0f3b1
feat: TriggerOutput - DeploymentHistoryConfigDiff - revamp UI - using…
RohitRaj011 Sep 23, 2024
4ee5946
Merge pull request #319 from devtron-labs/feat/deployment-history-dif…
RohitRaj011 Sep 23, 2024
0628827
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Sep 23, 2024
b7a2280
chore: version bump
RohitRaj011 Sep 23, 2024
d0949d1
feat: DeploymentConfigDiff - UAT changes, code refactor; DeploymentHi…
RohitRaj011 Sep 24, 2024
75d62ec
chore: version bump
RohitRaj011 Sep 24, 2024
c6c937b
fix: useForm: null check missing
RohitRaj011 Sep 25, 2024
843c9dd
fix: DeploymentHistory - diff state not properly showing in some case…
RohitRaj011 Sep 27, 2024
480a9f5
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Sep 27, 2024
d7b7271
chore: version bump
RohitRaj011 Sep 27, 2024
95dcbad
fix: DeploymentConfigDiff: review fixes
RohitRaj011 Oct 3, 2024
0600b59
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Oct 3, 2024
901f32e
chore: version bump
RohitRaj011 Oct 3, 2024
0c15444
fix: SelecPicker: tooltipProps null check
RohitRaj011 Oct 3, 2024
56ef7a0
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Oct 15, 2024
38c5093
feat: DeploymentConfigDiff - logic refactor for resolving deployment …
RohitRaj011 Oct 8, 2024
e3a9275
feat: DeploymentHistoryConfigDiff - uat changes, code refactor
RohitRaj011 Oct 13, 2024
b180a0c
feat: Collapse - add Collapse component, DeploymentConfigDiff - handl…
RohitRaj011 Oct 13, 2024
90c527f
chore: version bump
RohitRaj011 Oct 13, 2024
0765c0c
refactor: DeploymentHistoryConfigDiff - Handle case for no configurat…
RohitRaj011 Oct 14, 2024
fd6437b
chore: version bump
RohitRaj011 Oct 14, 2024
ac34854
feat: DeploymentHistoryConfigDiff - add NullState for previous/curren…
RohitRaj011 Oct 15, 2024
1ebf287
chore: version bump
RohitRaj011 Oct 15, 2024
41abc0a
fix: review fix
RohitRaj011 Oct 15, 2024
16211d5
refactor: DeploymentConfigDiff.utils - code refactor
RohitRaj011 Oct 15, 2024
5f78425
refactor: DeploymentConfigDiff.utils - code refactor
RohitRaj011 Oct 15, 2024
8d2118e
Merge pull request #354 from devtron-labs/feat/pipeline-deploy-config…
RohitRaj011 Oct 15, 2024
193d05c
refactor: CollapsibleList, DeploymentConfigDiffNavigation - icon size…
RohitRaj011 Oct 16, 2024
825eb9d
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Oct 17, 2024
02dd3b4
chore: version bump
RohitRaj011 Oct 17, 2024
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
10 changes: 10 additions & 0 deletions src/Assets/Icon/ic-diff-file-added.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/Assets/Icon/ic-diff-file-removed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/Assets/Icon/ic-file-code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/Common/Helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -937,3 +937,19 @@ export function asyncWrap(promise): any[] {
}

export const prefixZeroIfSingleDigit = (value: number = 0) => (value > 0 && value < 10 ? `0${value}` : value)

export const throttle = <T extends (...args: unknown[]) => unknown>(
func: T,
delay: number = 300,
): ((...args: Parameters<T>) => void) => {
let lastCall = 0

return (...args: Parameters<T>) => {
const now = Date.now()

if (now - lastCall >= delay) {
lastCall = now
func(...args)
}
}
}
14 changes: 11 additions & 3 deletions src/Common/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import React from 'react'
import { useEffectAfterMount } from '../Helper'
import React, { useCallback } from 'react'
import { throttle, useEffectAfterMount } from '../Helper'
import './Toggle.scss'

const Toggle = ({
Expand All @@ -27,6 +27,7 @@ const Toggle = ({
dataTestId = 'handle-toggle-button',
Icon = null,
iconClass = '',
throttleOnChange = false,
...props
}) => {
const [active, setActive] = React.useState(selected)
Expand All @@ -49,13 +50,20 @@ const Toggle = ({
}
}

const throttledHandleClick = useCallback(throttle(handleClick, 500), [disabled])

return (
<label
{...props}
className={`${rootClassName} toggle__switch ${disabled ? 'disabled' : ''}`}
style={{ ['--color' as any]: color }}
>
<input type="checkbox" checked={!!active} onChange={handleClick} className="toggle__input" />
<input
type="checkbox"
checked={!!active}
onChange={throttleOnChange ? throttledHandleClick : handleClick}
className="toggle__input"
/>
<span className={`toggle__slider ${Icon ? 'with-icon br-4 dc__border' : 'round'}`} data-testid={dataTestId}>
{Icon && <Icon className={`icon-dim-20 br-4 p-2 ${iconClass}`} />}
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
import { useMemo, useRef, useState } from 'react'
import { generatePath, Route, Switch, useLocation, useRouteMatch } from 'react-router-dom'

import { getAppEnvDeploymentConfigList, getDeploymentTemplateValues } from '@Shared/Components/DeploymentConfigDiff'
import { useAsync } from '@Common/Helper'
import { EnvResourceType, getAppEnvDeploymentConfig } from '@Shared/Services'
import { groupArrayByObjectKey } from '@Shared/Helpers'
import ErrorScreenManager from '@Common/ErrorScreenManager'
import { Progressing } from '@Common/Progressing'
import { useUrlFilters } from '@Common/Hooks'

import { abortPreviousRequests, getIsRequestAborted } from '@Common/Api'
import { DeploymentHistoryConfigDiffCompare } from './DeploymentHistoryConfigDiffCompare'
import { DeploymentHistoryConfigDiffProps, DeploymentHistoryConfigDiffQueryParams } from './types'
import { getPipelineDeploymentsWfrIds, getPipelineDeployments, parseDeploymentHistoryDiffSearchParams } from './utils'
import { renderDeploymentHistoryConfig } from './helpers'

export const DeploymentHistoryConfigDiff = ({
appName,
envName,
pipelineId,
wfrId,
triggerHistory,
setFullScreenView,
runSource,
resourceId,
renderRunSource,
}: DeploymentHistoryConfigDiffProps) => {
// HOOKS
const { path, params } = useRouteMatch()
const { pathname, search } = useLocation()

// CONSTANTS
const pipelineDeployments = useMemo(() => getPipelineDeployments(triggerHistory), [triggerHistory])
const { currentWfrId, previousWfrId } = useMemo(
() => getPipelineDeploymentsWfrIds({ pipelineDeployments, wfrId }),
[pipelineDeployments, wfrId],
)
const isPreviousDeploymentConfigAvailable = !!previousWfrId

// REFS
const deploymentTemplateResolvedDataAbortControllerRef = useRef(new AbortController())

// URL FILTERS
const { compareWfrId } = useUrlFilters<string, DeploymentHistoryConfigDiffQueryParams>({
parseSearchParams: parseDeploymentHistoryDiffSearchParams(previousWfrId),
})

// STATES
const [convertVariables, setConvertVariables] = useState(false)

// ASYNC CALLS
// Load comparison deployment data
const [
compareDeploymentConfigLoader,
compareDeploymentConfig,
compareDeploymentConfigErr,
reloadCompareDeploymentConfig,
] = useAsync(
() =>
Promise.all([
getAppEnvDeploymentConfig({
params: {
appName,
envName,
configArea: 'DeploymentHistory',
pipelineId,
wfrId: currentWfrId,
},
}),
isPreviousDeploymentConfigAvailable
? getAppEnvDeploymentConfig({
params: {
appName,
envName,
configArea: 'DeploymentHistory',
pipelineId,
wfrId: compareWfrId,
},
})
: null,
]),
[currentWfrId, compareWfrId],
)

const [
deploymentTemplateResolvedDataLoader,
deploymentTemplateResolvedData,
deploymentTemplateResolvedDataErr,
reloadDeploymentTemplateResolvedData,
] = useAsync(
() =>
abortPreviousRequests(
() =>
Promise.all([
getAppEnvDeploymentConfig({
params: {
configArea: 'ResolveData',
appName,
envName,
},
payload: {
values: getDeploymentTemplateValues(
compareDeploymentConfig[0].result?.deploymentTemplate,
),
},
signal: deploymentTemplateResolvedDataAbortControllerRef.current?.signal,
}),
getAppEnvDeploymentConfig({
params: {
configArea: 'ResolveData',
appName,
envName,
},
payload: {
values: getDeploymentTemplateValues(
compareDeploymentConfig[1].result?.deploymentTemplate,
),
},
signal: deploymentTemplateResolvedDataAbortControllerRef.current?.signal,
}),
]),
deploymentTemplateResolvedDataAbortControllerRef,
),
[convertVariables, compareDeploymentConfig],
convertVariables && !!compareDeploymentConfig,
)

// METHODS
const reload = () => {
reloadCompareDeploymentConfig()
reloadDeploymentTemplateResolvedData()
}

const getNavItemHref = (resourceType: EnvResourceType, resourceName: string) =>
`${generatePath(path, { ...params })}/${resourceType}${resourceName ? `/${resourceName}` : ''}${search}`

// Generate the deployment history config list
const deploymentConfigList = useMemo(() => {
const isDeploymentTemplateLoaded = !deploymentTemplateResolvedDataLoader && deploymentTemplateResolvedData
const isComparisonDataLoaded = !compareDeploymentConfigLoader && compareDeploymentConfig

const shouldLoadData = convertVariables
? isComparisonDataLoaded && isDeploymentTemplateLoaded
: isComparisonDataLoaded

if (shouldLoadData) {
const compareList = isPreviousDeploymentConfigAvailable
? compareDeploymentConfig[1].result
: {
configMapData: null,
deploymentTemplate: null,
secretsData: null,
isAppAdmin: false,
}
const currentList = compareDeploymentConfig[0].result

const configData = getAppEnvDeploymentConfigList({
currentList,
compareList,
getNavItemHref,
convertVariables,
...(convertVariables
? {
currentDeploymentTemplateResolvedData: deploymentTemplateResolvedData[0].result,
compareDeploymentTemplateResolvedData: deploymentTemplateResolvedData[1].result,
}
: {}),
})
return configData
}

return null
}, [
isPreviousDeploymentConfigAvailable,
compareDeploymentConfigErr,
compareDeploymentConfig,
convertVariables,
deploymentTemplateResolvedDataLoader,
deploymentTemplateResolvedData,
])

const groupedDeploymentConfigList = useMemo(
() => (deploymentConfigList ? groupArrayByObjectKey(deploymentConfigList.configList, 'groupHeader') : []),
[deploymentConfigList],
)

const isLoading = compareDeploymentConfigLoader || deploymentTemplateResolvedDataLoader
const isError =
compareDeploymentConfigErr ||
(deploymentTemplateResolvedDataErr && !getIsRequestAborted(deploymentTemplateResolvedDataErr))

return (
<Switch>
<Route path={`${path}/:resourceType(${Object.values(EnvResourceType).join('|')})/:resourceName?`}>
<DeploymentHistoryConfigDiffCompare
{...deploymentConfigList}
isLoading={isLoading || (!isError && !deploymentConfigList)}
errorConfig={{
code: compareDeploymentConfigErr?.code || deploymentTemplateResolvedDataErr?.code,
error: isError && !isLoading,
reload,
}}
envName={envName}
wfrId={wfrId}
previousWfrId={previousWfrId}
pipelineDeployments={pipelineDeployments}
setFullScreenView={setFullScreenView}
convertVariables={convertVariables}
setConvertVariables={setConvertVariables}
runSource={runSource}
resourceId={resourceId}
renderRunSource={renderRunSource}
/>
</Route>
<Route>
{isError && !isLoading ? (
<ErrorScreenManager code={compareDeploymentConfigErr?.code} reload={reload} />
) : (
<div className="p-16 flexbox-col dc__gap-16 bcn-0 h-100">
{isLoading || (!isError && !deploymentConfigList) ? (
<Progressing fullHeight size={48} />
) : (
<>
<h3 className="fs-13 lh-20 fw-6 cn-9 m-0">
Showing configuration change with respect to previous deployment
</h3>
<div className="flexbox-col dc__gap-12 dc__mxw-800">
{Object.keys(groupedDeploymentConfigList).map((groupHeader) =>
renderDeploymentHistoryConfig(
groupedDeploymentConfigList[groupHeader],
groupHeader !== 'UNGROUPED' ? groupHeader : null,
pathname,
),
)}
</div>
</>
)}
</div>
)}
</Route>
</Switch>
)
}
Loading