Skip to content

Commit db7b408

Browse files
authored
Merge pull request #1498 from devtron-labs/feat/dependencies
feat: add application dependencies
2 parents 1ca6918 + 19f3af8 commit db7b408

File tree

2 files changed

+68
-21
lines changed

2 files changed

+68
-21
lines changed

src/components/app/Overview/Overview.tsx

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
stopPropagation,
1212
useAsync,
1313
getRandomColor,
14+
noop,
1415
} from '@devtron-labs/devtron-fe-common-lib'
1516
import { EditableTextArea, RadioGroup, handleUTCTime, importComponentFromFELibrary } from '../../common'
1617
import { AppOverviewProps, EditAppRequest, JobPipeline } from '../types'
@@ -33,10 +34,10 @@ import { getAppConfig, getGitProviderIcon } from './utils'
3334
import { EnvironmentList } from './EnvironmentList'
3435
import { MAX_LENGTH_350 } from '../../../config/constantMessaging'
3536
import { getModuleInfo } from '../../v2/devtronStackManager/DevtronStackManager.service'
36-
import { OVERVIEW_TABS, TAB_SEARCH_KEY } from './constants'
37+
import { MODAL_STATE, OVERVIEW_TABS, TAB_SEARCH_KEY } from './constants'
3738
const MandatoryTagWarning = importComponentFromFELibrary('MandatoryTagWarning')
3839
const Catalog = importComponentFromFELibrary('Catalog')
39-
// const DependencyList = importComponentFromFELibrary('DependencyList')
40+
const DependencyList = importComponentFromFELibrary('DependencyList')
4041

4142
type AvailableTabs = typeof OVERVIEW_TABS[keyof typeof OVERVIEW_TABS]
4243

@@ -46,6 +47,8 @@ export default function AppOverview({ appMetaInfo, getAppMetaInfoRes, filteredEn
4647
const history = useHistory()
4748
const searchParams = new URLSearchParams(location.search)
4849
const activeTab = searchParams.get(TAB_SEARCH_KEY) as AvailableTabs
50+
const isUpdateDependencyModalOpen =
51+
activeTab === OVERVIEW_TABS.DEPENDENCIES && searchParams.get(MODAL_STATE.key) === MODAL_STATE.value
4952
const config = getAppConfig(appType)
5053
const isJobOverview = appType === 'job'
5154
const isHelmChart = appType === 'helm-chart'
@@ -61,11 +64,10 @@ export default function AppOverview({ appMetaInfo, getAppMetaInfoRes, filteredEn
6164
const [newUpdatedOn, setNewUpdatedOn] = useState<string>()
6265
const [newUpdatedBy, setNewUpdatedBy] = useState<string>()
6366
const [jobPipelines, setJobPipelines] = useState<JobPipeline[]>([])
67+
// Added this state to handle the disabled and hidden state basis the loading of the dependency list inside DependencyList component
68+
const [isEditDependencyButtonDisabled, setIsEditDependencyButtonDisabled] = useState(false)
6469
const [reloadMandatoryProjects, setReloadMandatoryProjects] = useState<boolean>(true)
65-
const [, isArgoInstalled] = useAsync(
66-
() => getModuleInfo(ModuleNameMap.ARGO_CD),
67-
[],
68-
)
70+
const [, isArgoInstalled] = useAsync(() => getModuleInfo(ModuleNameMap.ARGO_CD), [])
6971
const resourceName = config.resourceName
7072

7173
let _moment: moment.Moment
@@ -76,6 +78,15 @@ export default function AppOverview({ appMetaInfo, getAppMetaInfoRes, filteredEn
7678
history.replace({ search: searchParams.toString() })
7779
}
7880

81+
const toggleUpdateDependencyModal = () => {
82+
if (isUpdateDependencyModalOpen) {
83+
searchParams.delete(MODAL_STATE.key)
84+
} else {
85+
searchParams.set(MODAL_STATE.key, MODAL_STATE.value)
86+
}
87+
history.replace({ search: searchParams.toString() })
88+
}
89+
7990
useEffect(() => {
8091
// add a default tab if not set
8192
if (!activeTab || !Object.values(OVERVIEW_TABS).includes(activeTab)) {
@@ -460,24 +471,49 @@ export default function AppOverview({ appMetaInfo, getAppMetaInfoRes, filteredEn
460471
const contentToRender = {
461472
[OVERVIEW_TABS.ABOUT]: renderAppDescription,
462473
[OVERVIEW_TABS.ENVIRONMENTS]: () => <EnvironmentList appId={+appId} filteredEnvIds={filteredEnvIds} />,
463-
// [OVERVIEW_TABS.DEPENDENCIES]: () => DependencyList ? <DependencyList appId={+appId} isArgoInstalled={isArgoInstalled} /> : null,
474+
[OVERVIEW_TABS.DEPENDENCIES]: () =>
475+
DependencyList ? (
476+
<DependencyList
477+
resourceId={+appId}
478+
resourceType={appType}
479+
isArgoInstalled={isArgoInstalled}
480+
resourceName={appMetaInfo.appName}
481+
isUpdateModalOpen={isUpdateDependencyModalOpen}
482+
toggleUpdateModalOpen={toggleUpdateDependencyModal}
483+
toggleButtonDisabledState={setIsEditDependencyButtonDisabled}
484+
/>
485+
) : null,
464486
}
465487

466488
return (
467489
<div className="app-overview-wrapper flexbox-col dc__gap-12">
468-
<RadioGroup
469-
className="gui-yaml-switch gui-yaml-switch--lg gui-yaml-switch-window-bg flex-justify-start dc__no-background-imp"
470-
name="overview-tabs"
471-
initialTab={activeTab}
472-
disabled={false}
473-
onChange={(e) => {
474-
setActiveTab(e.target.value)
475-
}}
476-
>
477-
<RadioGroup.Radio value={OVERVIEW_TABS.ABOUT}>About</RadioGroup.Radio>
478-
<RadioGroup.Radio value={OVERVIEW_TABS.ENVIRONMENTS}>Environments</RadioGroup.Radio>
479-
{/* {DependencyList && <RadioGroup.Radio value={OVERVIEW_TABS.DEPENDENCIES}>Dependencies</RadioGroup.Radio>} */}
480-
</RadioGroup>
490+
<div className="flex flex-justify dc__gap-8">
491+
<RadioGroup
492+
className="gui-yaml-switch gui-yaml-switch--lg gui-yaml-switch-window-bg flex-justify-start dc__no-background-imp"
493+
name="overview-tabs"
494+
initialTab={activeTab}
495+
disabled={false}
496+
onChange={(e) => {
497+
setActiveTab(e.target.value)
498+
}}
499+
>
500+
<RadioGroup.Radio value={OVERVIEW_TABS.ABOUT}>About</RadioGroup.Radio>
501+
<RadioGroup.Radio value={OVERVIEW_TABS.ENVIRONMENTS}>Environments</RadioGroup.Radio>
502+
{DependencyList && (
503+
<RadioGroup.Radio value={OVERVIEW_TABS.DEPENDENCIES}>Dependencies</RadioGroup.Radio>
504+
)}
505+
</RadioGroup>
506+
{activeTab === OVERVIEW_TABS.DEPENDENCIES && (
507+
<button
508+
type="button"
509+
className={`cta flex h-28 dc__gap-4 ${isEditDependencyButtonDisabled ? 'disabled-opacity' : ''}`}
510+
onClick={isEditDependencyButtonDisabled ? noop : toggleUpdateDependencyModal}
511+
>
512+
<EditIcon className="mw-14 icon-dim-14 scn-0 dc__no-svg-fill" />
513+
Edit Dependency
514+
</button>
515+
)}
516+
</div>
481517
<div className="flexbox-col dc__gap-12">{contentToRender[activeTab]?.()}</div>
482518
</div>
483519
)

src/components/app/Overview/constants.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ export const OVERVIEW_TABS = {
1818
ABOUT: 'about',
1919
ENVIRONMENTS: 'environments',
2020
JOB_PIPELINES: 'job-pipelines',
21-
// DEPENDENCIES: 'dependencies',
21+
DEPENDENCIES: 'dependencies',
2222
} as const
2323

2424
export const TAB_SEARCH_KEY = 'tab'
25+
26+
export const MODAL_STATE = {
27+
/**
28+
* Search param key for the modal
29+
*/
30+
key: 'modal',
31+
/**
32+
* Value when the modal is open
33+
*/
34+
value: 'open'
35+
} as const

0 commit comments

Comments
 (0)