Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config id is 0 in save notification payload #2409

Merged
merged 10 commits into from
Feb 11, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
WorkflowNodeType,
CommonNodeAttr,
WorkflowType,
getDefaultConfig,
abortPreviousRequests,
getIsRequestAborted,
handleUTCTime,
Expand Down Expand Up @@ -189,8 +188,6 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
const [responseList, setResponseList] = useState<ResponseRowType[]>([])
const [isSelectAll, setSelectAll] = useState(false)
const [selectAllValue, setSelectAllValue] = useState<CHECKBOX_VALUE>(CHECKBOX_VALUE.CHECKED)
const [isConfigPresent, setConfigPresent] = useState<boolean>(false)
const [isDefaultConfigPresent, setDefaultConfig] = useState<boolean>(false)
// Mapping pipelineId (in case of CI) and appId (in case of CD) to runtime params
const [runtimeParams, setRuntimeParams] = useState<Record<string, RuntimePluginVariables[]>>({})
const [runtimeParamsErrorState, setRuntimeParamsErrorState] = useState<Record<string, RuntimeParamsErrorState>>({})
Expand All @@ -202,10 +199,6 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
usePrompt({ shouldPrompt: enableRoutePrompt })

useEffect(() => {
if (ApprovalMaterialModal) {
getConfigs()
}

return () => {
handledLocation.current = false
}
Expand Down Expand Up @@ -309,16 +302,6 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
}
}, [filteredWorkflows])

// TODO: This call should not be here rather inside ApprovalMaterialModal
const getConfigs = () => {
getDefaultConfig().then((response) => {
const isConfigPresent = response.result.isConfigured
const _isDefaultConfig = response.result.is_default_configured
setDefaultConfig(_isDefaultConfig)
setConfigPresent(isConfigPresent)
})
}

const preserveSelection = (_workflows: WorkflowType[]) => {
if (!workflows || !_workflows) {
return
Expand Down Expand Up @@ -2268,8 +2251,6 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
pipelineId={selectedCDNode?.id}
getModuleInfo={getModuleInfo}
ciPipelineId={node?.connectingCiPipelineId}
configs={isConfigPresent}
isDefaultConfigPresent={isDefaultConfigPresent}
history={history}
/>
)
Expand Down
5 changes: 3 additions & 2 deletions src/components/notifications/AddNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ export class AddNotification extends Component<AddNotificationsProps, AddNotific
...element,
data: {
...element.data,
configId: this.state.emailAgentConfigId,
dest: this.state.selectedEmailAgent.toLowerCase(),
},
})
Expand All @@ -441,8 +442,8 @@ export class AddNotification extends Component<AddNotificationsProps, AddNotific
}
}

saveNotification(selectedPipelines, selectedChannels, this.state.emailAgentConfigId)
.then((response) => {
saveNotification(selectedPipelines, selectedChannels)
.then(() => {
this.props.history.push(`${URLS.GLOBAL_CONFIG_NOTIFIER}/channels`)
ToastManager.showToast({
variant: ToastVariantType.success,
Expand Down
22 changes: 6 additions & 16 deletions src/components/notifications/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ interface SaveNotificationPayload {
eventTypeIds: number[]
}[]
providers: { configId: number; dest: 'ses' | 'slack' | ''; recipient: string }[]
sesConfigId: number
}

interface SaveNotificationResponseType extends ResponseType {
Expand Down Expand Up @@ -83,7 +82,7 @@ interface SESConfigResponseType extends ResponseType {
}
}

function createSaveNotificationPayload(selectedPipelines, providers, sesConfigId: number): SaveNotificationPayload {
function createSaveNotificationPayload(selectedPipelines, providers): SaveNotificationPayload {
const allPipelines = selectedPipelines.map((config) => {
const eventTypeIds = []
if (config.trigger) {
Expand Down Expand Up @@ -118,30 +117,21 @@ function createSaveNotificationPayload(selectedPipelines, providers, sesConfigId
}
})
providers = providers.map((p) => {
if (p.data.configId) {
return {
configId: p.data.configId,
dest: p.data.dest,
recipient: '',
}
}
return {
configId: 0,
configId: p.data.configId || 0,
dest: p.data.dest || '',
recipient: p.data.recipient,
recipient: p.data.recipient || '',
}
})
return {
notificationConfigRequest: allPipelines,
providers,
sesConfigId,
}
}

export function saveNotification(selectedPipelines, providers, sesConfigId): Promise<SaveNotificationResponseType> {
const URL = `${Routes.NOTIFIER}`
const payload = createSaveNotificationPayload(selectedPipelines, providers, sesConfigId)
return post(URL, payload)
export function saveNotification(selectedPipelines, providers): Promise<SaveNotificationResponseType> {
const payload = createSaveNotificationPayload(selectedPipelines, providers)
return post<SaveNotificationResponseType['result'] , SaveNotificationPayload>(Routes.NOTIFIER, payload)
}

export function getChannelConfigs(): Promise<ResponseType> {
Expand Down