@@ -43,6 +43,7 @@ import {
4343 ToastVariantType ,
4444 versionComparatorBySortOrder ,
4545 WebhookEventNameType ,
46+ AppType ,
4647} from '../Shared'
4748import { ReactComponent as ArrowDown } from '@Icons/ic-chevron-down.svg'
4849import { ReactComponent as ICWebhook } from '@Icons/ic-webhook.svg'
@@ -679,6 +680,7 @@ export const applyCompareDiffOnUneditedDocument = (uneditedDocument: object, edi
679680
680681/**
681682 * Returns a debounced variant of the function
683+ * @deprecated - It should use useRef instead, pls use useDebounce
682684 */
683685export const debounce = ( func , timeout = 500 ) => {
684686 let timer
@@ -693,6 +695,17 @@ export const debounce = (func, timeout = 500) => {
693695 }
694696}
695697
698+ export const useDebounce = < Callback extends ( ...args : any [ ] ) => void > ( cb : Callback , delay : number ) => {
699+ const timeoutId = useRef < ReturnType < typeof setTimeout > > ( null )
700+
701+ return ( ...args : Parameters < Callback > ) => {
702+ if ( timeoutId . current ) {
703+ clearTimeout ( timeoutId . current )
704+ }
705+ timeoutId . current = setTimeout ( ( ) => cb ( ...args ) , delay )
706+ }
707+ }
708+
696709/**
697710 * Returns a capitalized string with first letter in uppercase and rest in lowercase
698711 */
@@ -1083,4 +1096,23 @@ export const getTTLInHumanReadableFormat = (ttl: number): string => {
10831096 const humanizedDuration = moment . duration ( absoluteTTL , 'seconds' ) . humanize ( false )
10841097 // Since moment.js return "a" or "an" for singular values so replacing with 1.
10851098 return humanizedDuration . replace ( / ^ ( a | a n ) / , '1 ' ) ;
1086- }
1099+ }
1100+
1101+ const getAppTypeCategory = ( appType : AppType ) => {
1102+ switch ( appType ) {
1103+ case AppType . DEVTRON_APP :
1104+ return 'DA'
1105+ case AppType . DEVTRON_HELM_CHART :
1106+ case AppType . EXTERNAL_HELM_CHART :
1107+ return 'HA'
1108+ case AppType . EXTERNAL_ARGO_APP :
1109+ return 'ACD'
1110+ case AppType . EXTERNAL_FLUX_APP :
1111+ return 'FCD'
1112+ default :
1113+ return 'DA'
1114+ }
1115+ }
1116+
1117+ export const getAIAnalyticsEvents = ( context : string , appType ?: AppType ) =>
1118+ `AI_${ appType ? `${ getAppTypeCategory ( appType ) } _` : '' } ${ context } `
0 commit comments