Skip to content

Commit

Permalink
Merge pull request #2379 from devtron-labs/chore/main-to-dev-sync
Browse files Browse the repository at this point in the history
chore: sync develop with main
  • Loading branch information
eshankvaish authored Jan 17, 2025
2 parents 58a70d4 + 9a7ce9f commit 146b4d4
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/components/ClusterNodes/NodeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
}, [location.search])

const selectedResource = useMemo((): { gvk: GVKType; namespaced: boolean } => {
const resourceGroupData = lowercaseKindToResourceGroupMap[Nodes.Pod.toLowerCase()]
// Using - as a prefix since the group is empty for pods
const resourceGroupData = lowercaseKindToResourceGroupMap[`-${Nodes.Pod.toLowerCase()}`]
if (!resourceGroupData) {
return { gvk: { Kind: Nodes.Pod, Group: '', Version: 'v1' }, namespaced: true }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import ResourceBrowserActionMenu from './ResourceBrowserActionMenu'
import { EventList } from './EventList'
import ResourceFilterOptions from './ResourceFilterOptions'
import { BaseResourceListProps, BulkOperationsModalState } from './types'
import { getAppliedColumnsFromLocalStorage } from './utils'
import { getAppliedColumnsFromLocalStorage, getFirstResourceFromKindResourceMap } from './utils'
import NodeListSearchFilter from './NodeListSearchFilter'

const PodRestartIcon = importComponentFromFELibrary('PodRestartIcon')
Expand Down Expand Up @@ -363,7 +363,9 @@ const BaseResourceListContent = ({
const renderResourceRow = (resourceData: K8sResourceDetailDataType): JSX.Element => {
const lowercaseKind = (resourceData.kind as string)?.toLowerCase()
// This should be used only if shouldOverrideSelectedResourceKind is true
const gvkFromRawData = lowercaseKindToResourceGroupMap[lowercaseKind]?.gvk ?? ({} as GVKType)
// Group and version are not available for Events / shouldOverrideSelectedResourceKind is true
const gvkFromRawData =
getFirstResourceFromKindResourceMap(lowercaseKindToResourceGroupMap, lowercaseKind)?.gvk ?? ({} as GVKType)
// Redirection and actions are not possible for Events since the required data for the same is not available
const shouldShowRedirectionAndActions = lowercaseKind !== Nodes.Event.toLowerCase()
const isNodeUnschedulable = isNodeListing && !!resourceData.unschedulable
Expand Down
17 changes: 13 additions & 4 deletions src/components/ResourceBrowser/ResourceList/ResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import AdminTerminal from './AdminTerminal'
import { renderRefreshBar } from './ResourceList.component'
import { renderCreateResourceButton } from '../PageHeader.buttons'
import ClusterUpgradeCompatibilityInfo from './ClusterUpgradeCompatibilityInfo'
import { getUpgradeCompatibilityTippyConfig, parseSearchParams } from './utils'
import { getFirstResourceFromKindResourceMap, getUpgradeCompatibilityTippyConfig, parseSearchParams } from './utils'
import { ResourceListUrlFiltersType } from './types'

const EventsAIResponseWidget = importComponentFromFELibrary('EventsAIResponseWidget', null, 'function')
Expand Down Expand Up @@ -123,11 +123,14 @@ const ResourceList = () => {
[clusterId, clusterOptions],
)

// This needs to rename, not doing due to time constraints
const lowercaseKindToResourceGroupMap = useMemo(
() =>
(k8SObjectMapRaw?.result.apiResources ?? []).reduce<K8SResourceListType['lowercaseKindToResourceGroupMap']>(
(acc, resourceGroup) => {
acc[resourceGroup.gvk.Kind.toLowerCase()] = resourceGroup
// Using Group-Kind as key, but we need to move to using map instead
acc[`${resourceGroup.gvk.Group.toLowerCase()}-${resourceGroup.gvk.Kind.toLowerCase()}`] =
resourceGroup

return acc
},
Expand Down Expand Up @@ -358,7 +361,10 @@ const ResourceList = () => {
const lowercaseKindFromResource = shouldOverrideSelectedResourceKind ? kindFromResource.toLowerCase() : null
let _group: string =
(shouldOverrideSelectedResourceKind
? lowercaseKindToResourceGroupMap[lowercaseKindFromResource]?.gvk?.Group?.toLowerCase()
? getFirstResourceFromKindResourceMap(
lowercaseKindToResourceGroupMap,
lowercaseKindFromResource,
)?.gvk?.Group?.toLowerCase()
: selectedResource.gvk.Group.toLowerCase()) || K8S_EMPTY_GROUP
const _namespace = currentNamespace ?? ALL_NAMESPACE_OPTION.value

Expand All @@ -370,7 +376,10 @@ const ResourceList = () => {
const [_kind, _resourceName] = name.split('/')
const eventKind = shouldOverrideSelectedResourceKind ? lowercaseKindFromResource : _kind
// For event, we should read the group for kind from the resource group map else fallback to empty group
_group = lowercaseKindToResourceGroupMap[eventKind]?.gvk?.Group || K8S_EMPTY_GROUP

_group =
getFirstResourceFromKindResourceMap(lowercaseKindToResourceGroupMap, eventKind)?.gvk?.Group ||
K8S_EMPTY_GROUP

resourceParam = `${eventKind}/${_group}/${_resourceName}`
kind = eventKind
Expand Down
11 changes: 11 additions & 0 deletions src/components/ResourceBrowser/ResourceList/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
OPTIONAL_NODE_LIST_HEADERS,
} from '../Constants'
import { ResourceListUrlFiltersType } from './types'
import { K8SResourceListType } from '../Types'

export const parseSearchParams = (searchParams: URLSearchParams) => ({
targetK8sVersion: searchParams.get(TARGET_K8S_VERSION_SEARCH_KEY),
Expand Down Expand Up @@ -54,3 +55,13 @@ export const getUpgradeCompatibilityTippyConfig = ({
},
],
})

// Note: this is a hack to handle the case where the event kind is not present in the resource group map
// This will break for the kind with multiple groups
export const getFirstResourceFromKindResourceMap = (
lowercaseKindToResourceGroupMap: K8SResourceListType['lowercaseKindToResourceGroupMap'],
kind: string,
) =>
Object.values(lowercaseKindToResourceGroupMap).find(
(resourceGroup) => resourceGroup.gvk.Kind?.toLowerCase() === kind.toLowerCase(),
)
4 changes: 4 additions & 0 deletions src/components/app/details/triggerView/ciMaterial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ class CIMaterial extends Component<CIMaterialProps, CIMaterialState> {
const response = await savePipeline(payload, true)
if (response) {
await this.props.getWorkflows()

if (this.props.fromAppGrouping) {
this.context.onClickCIMaterial(this.props.pipelineId.toString(), this.props.pipelineName)
}
}
} catch (error) {
showError(error)
Expand Down
2 changes: 1 addition & 1 deletion src/components/v2/appDetails/appDetails.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export interface NodeTreeTabListProps extends LogSearchTermType {
isReloadResourceTreeInProgress: boolean
handleReloadResourceTree: () => void
tabRef?: MutableRefObject<HTMLDivElement>
appType?: string
appType?: AppType
isExternalApp?: boolean
}

Expand Down
6 changes: 6 additions & 0 deletions src/components/v2/appDetails/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum ApplicationsGAEvents {
REFRESH_DEVTRON_APP_RESOURCE_TREE = 'REFRESH_DEVTRON_APP_RESOURCE_TREE',
REFRESH_HELM_APP_RESOURCE_TREE = 'REFRESH_HELM_APP_RESOURCE_TREE',
REFRESH_ARGO_APP_RESOURCE_TREE = 'REFRESH_ARGO_APP_RESOURCE_TREE',
REFRESH_FLUX_APP_RESOURCE_TREE = 'REFRESH_FLUX_APP_RESOURCE_TREE',
}
14 changes: 12 additions & 2 deletions src/components/v2/appDetails/k8Resource/NodeTreeTabList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import React from 'react'
import { NavLink, useHistory, useParams } from 'react-router-dom'
import ReactGA from 'react-ga4'
import { useSharedState } from '../../utils/useSharedState'
Expand All @@ -36,13 +35,15 @@ import {
ButtonComponentType
} from '@devtron-labs/devtron-fe-common-lib'
import './NodeTreeTabList.scss'
import { getApplicationsGAEvent } from './utils'

export default function NodeTreeTabList({
logSearchTerms,
setLogSearchTerms,
tabRef,
handleReloadResourceTree,
isReloadResourceTreeInProgress,
appType
}: NodeTreeTabListProps) {
const { nodeType } = useParams<{ nodeType: string }>()
const { push } = useHistory()
Expand Down Expand Up @@ -132,6 +133,15 @@ export default function NodeTreeTabList({
handleCloseTab(e, e.currentTarget.dataset.title)
}


const onClickReloadResourceTree = () => {
handleReloadResourceTree()
ReactGA.event({
category: getApplicationsGAEvent(appType),
action: getApplicationsGAEvent(appType),
})
}

return (
<div
data-testid="resource-tree-wrapper"
Expand Down Expand Up @@ -201,7 +211,7 @@ export default function NodeTreeTabList({
<Button
dataTestId="reload-resource-tree-button"
icon={<ICArrowClockwise className="scn-6" />}
onClick={handleReloadResourceTree}
onClick={onClickReloadResourceTree}
variant={ButtonVariantType.borderLess}
size={ComponentSizeType.small}
style={ButtonStyleType.neutral}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ const EphemeralContainerDrawer = ({
setResourceContainers(_containers)
setShowEphemeralContainerDrawer(false)
switchSelectedContainer(containerName)
handleSuccess()
if (typeof handleSuccess === 'function') {
handleSuccess()
}
})
.catch((err) => {
showError(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
FormProps,
ToastManager,
ToastVariantType,
OptionsBase
OptionsBase,
noop
} from '@devtron-labs/devtron-fe-common-lib'
import { ReactComponent as ICArrowsLeftRight } from '@Icons/ic-arrows-left-right.svg'
import { ReactComponent as ICPencil } from '@Icons/ic-pencil.svg'
Expand Down Expand Up @@ -65,6 +66,7 @@ import { CLUSTER_NODE_ACTIONS_LABELS } from '../../../../ClusterNodes/constants'
import DeleteResourcePopup from '../../../../ResourceBrowser/ResourceList/DeleteResourcePopup'
import { EDITOR_VIEW } from '@Config/constants'
import { importComponentFromFELibrary } from '@Components/common'
import { K8S_EMPTY_GROUP } from '@Components/ResourceBrowser/Constants'

const isFELibAvailable = importComponentFromFELibrary('isFELibAvailable', false, 'function')
const ToggleManifestConfigurationMode = importComponentFromFELibrary(
Expand Down Expand Up @@ -120,8 +122,8 @@ const NodeDetailComponent = ({
}

const _selectedResource = useMemo(
() => lowercaseKindToResourceGroupMap[params.nodeType.toLowerCase()],
[lowercaseKindToResourceGroupMap, params.nodeType],
() => lowercaseKindToResourceGroupMap[`${params.group === K8S_EMPTY_GROUP ? '' : params.group?.toLowerCase()}-${params.nodeType.toLowerCase()}`],
[lowercaseKindToResourceGroupMap, params.nodeType, params.group],
)

const resourceName = isResourceBrowserView ? params.node : params.podName
Expand Down Expand Up @@ -254,7 +256,7 @@ const NodeDetailComponent = ({
}
}

if (result?.manifestResponse.ephemeralContainers) {
if (result?.manifestResponse?.ephemeralContainers) {
_resourceContainers.push(
...result.manifestResponse.ephemeralContainers.map((_container) => ({
name: _container.name,
Expand Down Expand Up @@ -646,7 +648,10 @@ const NodeDetailComponent = ({
setContainers={setContainers}
switchSelectedContainer={switchSelectedContainer}
selectedNamespaceByClickingPod={selectedResource?.namespace}
handleSuccess={getContainersFromManifest}
// getContainersFromManifest can only be used from resource browser
{...isResourceBrowserView ? {
handleSuccess: getContainersFromManifest
} : {}}
/>
)}
{isResourceBrowserView && showDeleteDialog && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface ParamsType {
envId?: string
namespace?: string
clusterId?: string
group?: string
}
export interface EphemeralForm {
basicData: {
Expand Down Expand Up @@ -75,7 +76,7 @@ export interface EphemeralContainerDrawerType {
switchSelectedContainer: (string) => void
onClickShowLaunchEphemeral: () => void
selectedNamespaceByClickingPod?: string
handleSuccess: () => void
handleSuccess?: () => void
}

export interface ResponsePayload {
Expand Down
16 changes: 15 additions & 1 deletion src/components/v2/appDetails/k8Resource/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { Node, NodeFilters } from '@devtron-labs/devtron-fe-common-lib'
import { AppType, Node, NodeFilters } from '@devtron-labs/devtron-fe-common-lib'
import { ApplicationsGAEvents } from '../constants'

export const doesNodeSatisfiesFilter = (node: Node, filter: string) =>
node.health?.status.toLowerCase() === filter || (filter === NodeFilters.drifted && node.hasDrift)

export const getApplicationsGAEvent = (appType: AppType) => {
switch (appType) {
case AppType.DEVTRON_HELM_CHART:
return ApplicationsGAEvents.REFRESH_HELM_APP_RESOURCE_TREE
case AppType.EXTERNAL_ARGO_APP:
return ApplicationsGAEvents.REFRESH_ARGO_APP_RESOURCE_TREE
case AppType.EXTERNAL_FLUX_APP:
return ApplicationsGAEvents.REFRESH_FLUX_APP_RESOURCE_TREE
default:
return ApplicationsGAEvents.REFRESH_DEVTRON_APP_RESOURCE_TREE
}
}

0 comments on commit 146b4d4

Please sign in to comment.