Skip to content

Commit 89da8d3

Browse files
committed
feat: add support for cluster and prod/non-prod env in notifications
1 parent 26990d4 commit 89da8d3

File tree

3 files changed

+87
-19
lines changed

3 files changed

+87
-19
lines changed

src/components/notifications/AddNotification.tsx

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
CHECKBOX_VALUE,
2828
getIsRequestAborted,
2929
CiPipelineSourceConfig,
30+
SelectAllGroupedResourceIdentifiers,
3031
} from '@devtron-labs/devtron-fe-common-lib'
3132
import { RouteComponentProps, Link } from 'react-router-dom'
3233
import { toast } from 'react-toastify'
@@ -55,13 +56,15 @@ import { getAppListMin, getEnvironmentListMin } from '../../services/service'
5556
import { SMTPConfigModal } from './SMTPConfigModal'
5657
import { EMAIL_AGENT } from './types'
5758
import { WebhookConfigModal } from './WebhookConfigModal'
59+
import { getClusterListMin } from '@Components/ClusterNodes/clusterNodes.service'
5860

5961
interface AddNotificationsProps extends RouteComponentProps<{}> {}
6062

61-
enum FilterOptions {
63+
export enum FilterOptions {
6264
ENVIRONMENT = 'environment',
6365
APPLICATION = 'application',
6466
PROJECT = 'project',
67+
CLUSTER = 'cluster'
6568
}
6669
interface Options {
6770
environment: {
@@ -79,6 +82,11 @@ interface Options {
7982
label: string
8083
type: string
8184
}[]
85+
cluster: {
86+
value: number
87+
label: string
88+
type: string
89+
}[]
8290
}
8391
export interface PipelineType {
8492
checkbox: {
@@ -144,6 +152,7 @@ export class AddNotification extends Component<AddNotificationsProps, AddNotific
144152
{ value: 1, label: 'application', type: 'main' },
145153
{ value: 2, label: 'project', type: 'main' },
146154
{ value: 3, label: 'environment', type: 'main' },
155+
{ value: 4, label: 'cluster', type: 'main' },
147156
]
148157

149158
filterOptionsInner = []
@@ -168,7 +177,7 @@ export class AddNotification extends Component<AddNotificationsProps, AddNotific
168177
selectedChannels: [],
169178
pipelineList: [],
170179
emailAgentConfigId: 0,
171-
options: { environment: [], application: [], project: [] },
180+
options: { environment: [], application: [], project: [], cluster: [] },
172181
selectedEmailAgent: EMAIL_AGENT.SES,
173182
showWebhookConfigModal: false,
174183
}
@@ -191,7 +200,7 @@ export class AddNotification extends Component<AddNotificationsProps, AddNotific
191200
}
192201

193202
getInitialData() {
194-
this.getEnvTeamData()
203+
this.getEnvTeamAndClusterData()
195204
getAddNotificationInitData().then((result) => {
196205
this.setState({
197206
sesConfigOptions: result.sesConfigOptions,
@@ -509,23 +518,41 @@ export class AddNotification extends Component<AddNotificationsProps, AddNotific
509518
}
510519
}
511520

512-
getEnvTeamData(): void {
513-
Promise.all([getEnvironmentListMin(), getTeamListMin()]).then(([environments, teams]) => {
521+
getEnvTeamAndClusterData(): void {
522+
Promise.all([getEnvironmentListMin(), getTeamListMin(), getClusterListMin()]).then(([environments, teams, clusters]) => {
514523
const state = { ...this.state }
515-
state.options.environment = environments.result.map((elem) => {
524+
state.options.environment = [
525+
{
526+
environment_name: 'All non-prod environments',
527+
// parseInt can be removed once BE supports identifiers instead
528+
id: parseInt(SelectAllGroupedResourceIdentifiers.allExistingAndFutureNonProdEnvironments),
529+
},
530+
{
531+
environment_name: 'All prod environments',
532+
id: parseInt(SelectAllGroupedResourceIdentifiers.allExistingAndFutureProdEnvironments),
533+
},
534+
...(environments?.result ?? []),
535+
].map((elem) => {
516536
return {
517537
label: `${elem.environment_name.toLowerCase()}`,
518538
value: elem.id,
519539
type: FilterOptions.ENVIRONMENT,
520540
}
521541
})
522-
state.options.project = teams.result.map((elem) => {
542+
state.options.project = (teams?.result ?? []).map((elem) => {
523543
return {
524544
label: `${elem.name.toLowerCase()}`,
525545
value: elem.id,
526546
type: FilterOptions.PROJECT,
527547
}
528548
})
549+
state.options.cluster = (clusters?.result ?? []).map(({ name, id }) => {
550+
return {
551+
label: `${name.toLowerCase()}`,
552+
value: id,
553+
type: FilterOptions.CLUSTER,
554+
}
555+
})
529556
this.setState(state)
530557
})
531558
}
@@ -582,10 +609,16 @@ export class AddNotification extends Component<AddNotificationsProps, AddNotific
582609
input.length === 0
583610
? this.state.options.project
584611
: this.state.options.project.filter((filter) => filter.label.indexOf(input) >= 0)
612+
} else if (unsavedFilter.type === FilterOptions.CLUSTER) {
613+
options =
614+
input.length === 0
615+
? this.state.options.cluster
616+
: this.state.options.cluster.filter((filter) => filter.label.indexOf(input) >= 0)
585617
} else {
586618
options = input.length <= 2 ? [] : this.state.options.application
587619
}
588620
}
621+
589622
return (
590623
<div className="dc__position-rel">
591624
<div

src/components/notifications/NotificationTab.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export interface NotificationConfiguration {
7272
project: { id: number; name: string }[]
7373
application: { id: number; name: string }[]
7474
environment: { id: number; name: string }[]
75+
cluster: {
76+
id: number
77+
name: string
78+
}[]
7579
}
7680
singleDeletedId: number
7781
isVirtualEnvironment?: boolean
@@ -626,7 +630,8 @@ export class NotificationTab extends Component<any, NotificationTabState> {
626630
{row.pipelineName ? row.pipelineName : ''}
627631
{row.appliedFilters.environment?.length ||
628632
row.appliedFilters.application.length ||
629-
row.appliedFilters.project?.length ? (
633+
row.appliedFilters.project?.length ||
634+
row.appliedFilters.cluster?.length ? (
630635
<>
631636
<i>All current and future pipelines matching.</i>
632637
<div className="dc__devtron-tag__container">
@@ -663,6 +668,17 @@ export class NotificationTab extends Component<any, NotificationTabState> {
663668
</span>
664669
)
665670
})}
671+
{row.appliedFilters.cluster.map((element) => {
672+
return (
673+
<span
674+
data-testid={`${row.pipelineType}-${element.name}`}
675+
key={element.name}
676+
className="dc__devtron-tag mr-5"
677+
>
678+
Cluster:{element.name}
679+
</span>
680+
)
681+
})}
666682
</div>{' '}
667683
</>
668684
) : null}

src/components/notifications/notifications.service.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { get, post, trash, put, ResponseType, sortCallback } from '@devtron-labs/devtron-fe-common-lib'
1818
import { Routes } from '../../config/constants'
1919
import { NotificationConfiguration } from './NotificationTab'
20-
import { PipelineType } from './AddNotification'
20+
import { FilterOptions, PipelineType } from './AddNotification'
2121
import { SMTPConfigResponseType, WebhookAttributesResponseType } from './types'
2222

2323
interface UpdateNotificationEvent {
@@ -97,14 +97,22 @@ function createSaveNotificationPayload(selectedPipelines, providers, sesConfigId
9797
eventTypeIds.push(3)
9898
}
9999

100-
const teamId = config.appliedFilters.filter((filter) => filter.type === 'project').map((p) => p.id)
101-
const appId = config.appliedFilters.filter((filter) => filter.type === 'application').map((app) => app.id)
102-
const envId = config.appliedFilters.filter((filter) => filter.type === 'environment').map((e) => e.id)
100+
const teamId = config.appliedFilters
101+
.filter((filter) => filter.type === FilterOptions.PROJECT)
102+
.map((p) => p.id)
103+
const appId = config.appliedFilters
104+
.filter((filter) => filter.type === FilterOptions.APPLICATION)
105+
.map((app) => app.id)
106+
const envId = config.appliedFilters.filter((filter) => filter.type === FilterOptions.ENVIRONMENT).map((e) => e.id)
107+
const clusterId = config.appliedFilters
108+
.filter((filter) => filter.type === FilterOptions.CLUSTER)
109+
.map((e) => e.id)
103110

104111
return {
105112
teamId,
106113
appId,
107114
envId,
115+
clusterId,
108116
pipelineId: config.pipelineId,
109117
pipelineType: config.type,
110118
eventTypeIds,
@@ -243,6 +251,7 @@ export function getNotificationConfigurations(offset: number, pageSize: number):
243251
project: config.team || [],
244252
application: config.app || [],
245253
environment: config.environment || [],
254+
cluster: config.cluster || [],
246255
},
247256
isVirtualEnvironment: config?.pipeline?.isVirtualEnvironment,
248257
}
@@ -451,39 +460,49 @@ function getChannelsAndEmails(): Promise<GetChannelsResponseType> {
451460
export function getPipelines(filters): Promise<GetPipelinesResponseType> {
452461
const URL = `${Routes.NOTIFIER}/search`
453462
const payload = {
454-
teamId: filters.filter((p) => p.type == 'project').map((p) => p.value),
455-
envId: filters.filter((p) => p.type == 'environment').map((p) => p.value),
456-
appId: filters.filter((p) => p.type == 'application').map((p) => p.value),
463+
teamId: filters.filter((p) => p.type === FilterOptions.PROJECT).map((p) => p.value),
464+
envId: filters.filter((p) => p.type === FilterOptions.ENVIRONMENT).map((p) => p.value),
465+
appId: filters.filter((p) => p.type === FilterOptions.APPLICATION).map((p) => p.value),
466+
clusterId: filters.filter((p) => p.type === FilterOptions.CLUSTER).map(p => p.value),
457467
pipelineName: filters.find((p) => p.type == 'pipeline')?.value,
458468
}
459469
return post(URL, payload).then((response) => {
460470
const parsedResult = response.result?.map((row) => {
461471
const projects = row.team
462472
? row.team.map((team) => {
463473
return {
464-
type: 'project',
474+
type: FilterOptions.PROJECT,
465475
...team,
466476
}
467477
})
468478
: []
469479
const app = row.app
470480
? row.app.map((team) => {
471481
return {
472-
type: 'application',
482+
type: FilterOptions.APPLICATION,
473483
...team,
474484
}
475485
})
476486
: []
477487
const environment = row.environment
478488
? row.environment?.map((team) => {
479489
return {
480-
type: 'environment',
490+
type: FilterOptions.ENVIRONMENT,
481491
...team,
482492
}
483493
})
484494
: []
495+
const cluster = row.cluster
496+
? row.cluster?.map((cluster) => {
497+
return {
498+
type: FilterOptions.CLUSTER,
499+
...cluster,
500+
}
501+
})
502+
: []
503+
485504
return {
486-
appliedFilters: projects.concat(app, environment),
505+
appliedFilters: projects.concat(app, environment, cluster),
487506
checkbox: { isChecked: false, value: 'INTERMEDIATE' },
488507
pipelineId: row.pipeline?.id,
489508
appName: row?.pipeline?.appName,

0 commit comments

Comments
 (0)