Skip to content

Commit c93bc02

Browse files
committed
refactor: improve rendering logic for WebhookAddImageModal based on location conditions
1 parent 6cd239d commit c93bc02

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

src/components/ApplicationGroup/Details/TriggerView/EnvTriggerView.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ import CIMaterialModal from '../../../app/details/triggerView/CIMaterialModal'
127127
import { RenderCDMaterialContentProps } from './types'
128128
import { WebhookReceivedPayloadModal } from '@Components/app/details/triggerView/WebhookReceivedPayloadModal'
129129
import { getExternalCIConfig } from '@Components/ciPipeline/Webhook/webhook.service'
130+
import { shouldRenderWebhookAddImageModal } from '@Components/app/details/triggerView/TriggerView.utils'
130131

131132
const ApprovalMaterialModal = importComponentFromFELibrary('ApprovalMaterialModal')
132133
const getCIBlockState: (...props) => Promise<BlockedStateData> = importComponentFromFELibrary(
@@ -2397,19 +2398,18 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
23972398
}
23982399

23992400
const renderWebhookAddImageModal = () => {
2400-
// Not showing modal whenever either CDMaterial, CIMaterial or LinkedCIDetails modals are open.
24012401
if (
2402-
location.search.includes('cd-node') ||
2403-
location.search.includes('rollback-node') ||
2404-
location.pathname.includes(URLS.BUILD) ||
2405-
location.pathname.includes(URLS.LINKED_CI_DETAILS) ||
2406-
!WebhookAddImageModal ||
2407-
!selectedWebhookNode
2402+
WebhookAddImageModal &&
2403+
shouldRenderWebhookAddImageModal(location) &&
2404+
!location.pathname.includes('bulk-deploy/request') &&
2405+
selectedWebhookNode
24082406
) {
2409-
return null
2407+
return (
2408+
<WebhookAddImageModal getWebhookDetails={getWebhookDetails} onClose={handleWebhookAddImageModalClose} />
2409+
)
24102410
}
24112411

2412-
return <WebhookAddImageModal getWebhookDetails={getWebhookDetails} onClose={handleWebhookAddImageModalClose} />
2412+
return null
24132413
}
24142414

24152415
const renderWorkflow = (): JSX.Element => {

src/components/app/details/triggerView/TriggerView.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import { LinkedCIDetail } from '../../../../Pages/Shared/LinkedCIDetailsModal'
9696
import { CIMaterialModal } from './CIMaterialModal'
9797
import { WebhookReceivedPayloadModal } from './WebhookReceivedPayloadModal'
9898
import { getExternalCIConfig } from '@Components/ciPipeline/Webhook/webhook.service'
99+
import { shouldRenderWebhookAddImageModal } from './TriggerView.utils'
99100

100101
const ApprovalMaterialModal = importComponentFromFELibrary('ApprovalMaterialModal')
101102
const getCIBlockState: (...props) => Promise<BlockedStateData> = importComponentFromFELibrary(
@@ -1366,24 +1367,20 @@ class TriggerView extends Component<TriggerViewProps, TriggerViewState> {
13661367
}
13671368

13681369
renderWebhookAddImageModal() {
1369-
// Not showing modal whenever either CDMaterial, CIMaterial or LinkedCIDetails modals are open.
13701370
if (
1371-
this.props.location.search.includes('cd-node') ||
1372-
this.props.location.search.includes('rollback-node') ||
1373-
this.props.location.pathname.includes(URLS.BUILD) ||
1374-
this.props.location.pathname.includes(URLS.LINKED_CI_DETAILS) ||
1375-
!WebhookAddImageModal ||
1376-
!this.state.selectedWebhookNodeId
1371+
WebhookAddImageModal &&
1372+
shouldRenderWebhookAddImageModal(this.props.location) &&
1373+
this.state.selectedWebhookNodeId
13771374
) {
1378-
return null
1375+
return (
1376+
<WebhookAddImageModal
1377+
getWebhookDetails={this.getWebhookDetails}
1378+
onClose={this.handleWebhookAddImageModalClose}
1379+
/>
1380+
)
13791381
}
13801382

1381-
return (
1382-
<WebhookAddImageModal
1383-
getWebhookDetails={this.getWebhookDetails}
1384-
onClose={this.handleWebhookAddImageModalClose}
1385-
/>
1386-
)
1383+
return null
13871384
}
13881385

13891386
handleModalClose = () => {

src/components/app/details/triggerView/TriggerView.utils.tsx

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

17+
import { useLocation } from 'react-router-dom'
18+
1719
import { DeploymentWithConfigType } from '@devtron-labs/devtron-fe-common-lib'
1820

21+
import { URLS } from '@Config/routes'
22+
1923
import { deepEqual } from '../../../common'
2024
import { DeploymentHistoryDetail } from '../cdDetails/cd.type'
25+
import { TRIGGER_VIEW_PARAMS } from './Constants'
2126
import { TriggerViewDeploymentConfigType } from './types'
2227

2328
export const DEPLOYMENT_CONFIGURATION_NAV_MAP = {
@@ -163,3 +168,26 @@ export const checkForDiff = (configA: TriggerViewDeploymentConfigType, configB:
163168

164169
return diffForOptions
165170
}
171+
172+
/**
173+
* Determines whether the "Webhook Add Image" modal should be rendered based on the current location.
174+
*
175+
* This function checks the `location` object to ensure that the modal is not displayed
176+
* when certain other modals or views are active. Specifically, the modal will not be shown
177+
* if any of the following conditions are met:
178+
* - The URL query string contains 'cd-node' or 'rollback-node'.
179+
* - The URL path includes the `BUILD` route.
180+
* - The URL path includes the `LINKED_CI_DETAILS` route.
181+
* - The URL query string contains the `APPROVAL_NODE` parameter.
182+
*
183+
* @param location - The current location object, typically obtained from the `useLocation` hook.
184+
* @returns A boolean indicating whether the "Webhook Add Image" modal should be rendered.
185+
*/
186+
export const shouldRenderWebhookAddImageModal = (location: ReturnType<typeof useLocation>) =>
187+
!(
188+
location.search.includes('cd-node') ||
189+
location.search.includes('rollback-node') ||
190+
location.search.includes(TRIGGER_VIEW_PARAMS.APPROVAL_NODE) ||
191+
location.pathname.includes(URLS.BUILD) ||
192+
location.pathname.includes(URLS.LINKED_CI_DETAILS)
193+
)

0 commit comments

Comments
 (0)