Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/devtron-labs/dashboard i…
Browse files Browse the repository at this point in the history
…nto feat/confirmation-modal
  • Loading branch information
arunjaindev committed Nov 28, 2024
2 parents 86202ca + 74f5206 commit 67d776f
Show file tree
Hide file tree
Showing 28 changed files with 311 additions and 361 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"homepage": "/dashboard",
"dependencies": {
"@devtron-labs/devtron-fe-common-lib": "1.1.4-beta-11",
"@devtron-labs/devtron-fe-common-lib": "1.1.6",
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
"@rjsf/core": "^5.13.3",
"@rjsf/utils": "^5.13.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
GVKType,
getK8sResourceList,
EntityTypes,
ApiResourceGroupType,
} from '@devtron-labs/devtron-fe-common-lib'
import CreatableSelect from 'react-select/creatable'
import Tippy from '@tippyjs/react'
Expand Down Expand Up @@ -177,13 +178,16 @@ const K8sListItemCard = ({
const createKindData = (selected, _allKindMapping, _k8SObjectMap = null) => {
const kind = []
let selectedGvk: GVKType
const isAllNamespaceSelected = k8sPermission.namespace.some((option) => option.value === SELECT_ALL_VALUE)
if (_k8SObjectMap ?? processedData) {
if (selected.value === SELECT_ALL_VALUE) {
// eslint-disable-next-line no-restricted-syntax
for (const value of (_k8SObjectMap ?? processedData).values()) {
// eslint-disable-next-line no-loop-func
value?.child.forEach((ele: { gvk: GVKType }) => {
kind.push({ value: ele.gvk.Kind, label: ele.gvk.Kind, gvk: ele.gvk })
value?.child.forEach((ele: ApiResourceGroupType) => {
if (isAllNamespaceSelected || ele.namespaced) {
kind.push({ label: ele.gvk.Kind, value: ele.gvk.Kind, gvk: ele.gvk })
}
if (!selectedGvk && ele.gvk.Kind === k8sPermission.kind?.value) {
selectedGvk = ele.gvk
}
Expand All @@ -192,7 +196,7 @@ const K8sListItemCard = ({
} else {
const data = (_k8SObjectMap ?? processedData).get(selected.value === 'k8sempty' ? '' : selected.value)
data?.child?.forEach((ele) => {
if (ele.namespaced) {
if (isAllNamespaceSelected || ele.namespaced) {
kind.push({ label: ele.gvk.Kind, value: ele.gvk.Kind, gvk: ele.gvk })
}
if (!selectedGvk && ele.gvk.Kind === k8sPermission.kind?.value) {
Expand Down
13 changes: 6 additions & 7 deletions src/Pages/Releases/Detail/Configurations/Configurations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ export const Configurations = () => {

const renderConfig = () => (
<Switch>
<Route key={`${path}/${URLS.APP_DEPLOYMENT_CONFIG}`} path={`${path}/${URLS.APP_DEPLOYMENT_CONFIG}`}>
<div className="dc__overflow-auto">
<Route path={`${path}/${URLS.APP_DEPLOYMENT_CONFIG}`}>
<div key={`${appId}-${envId}-${URLS.APP_DEPLOYMENT_CONFIG}`} className="dc__overflow-auto">
<DeploymentTemplate
key={`${appId}/${envId}`}
fetchEnvConfig={fetchEnvConfig}
isProtected={selectedEnv.isProtected}
reloadEnvironments={reloadEnvironments}
Expand All @@ -100,8 +99,8 @@ export const Configurations = () => {
/>
</div>
</Route>
<Route key={`${path}/${URLS.APP_CM_CONFIG}`} path={`${path}/${URLS.APP_CM_CONFIG}/:name?`}>
<div className="dc__overflow-auto">
<Route path={`${path}/${URLS.APP_CM_CONFIG}/:name?`}>
<div key={`${appId}-${envId}-${URLS.APP_CM_CONFIG}`} className="dc__overflow-auto">
<ConfigMapSecretWrapper
appName={selectedApp.label}
envName={selectedEnv.name}
Expand All @@ -114,8 +113,8 @@ export const Configurations = () => {
/>
</div>
</Route>
<Route key={`${path}/${URLS.APP_CS_CONFIG}`} path={`${path}/${URLS.APP_CS_CONFIG}/:name?`}>
<div className="dc__overflow-auto">
<Route path={`${path}/${URLS.APP_CS_CONFIG}/:name?`}>
<div key={`${appId}-${envId}-${URLS.APP_CS_CONFIG}`} className="dc__overflow-auto">
<ConfigMapSecretWrapper
componentType={CMSecretComponentType.Secret}
appName={selectedApp.label}
Expand Down
6 changes: 4 additions & 2 deletions src/Pages/Shared/EnvironmentOverride/EnvironmentOverride.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ const EnvironmentOverride = ({
fetchEnvConfig={fetchEnvConfig}
/>
</Route>
<Route key={`${path}/${URLS.APP_CM_CONFIG}`} path={`${path}/${URLS.APP_CM_CONFIG}/:name?`}>
<Route path={`${path}/${URLS.APP_CM_CONFIG}/:name?`}>
<ConfigMapSecretWrapper
key={`configmap-${params.appId}-${params.envId}`}
isProtected={isProtected}
parentState={viewState}
parentName={getParentName()}
Expand All @@ -175,8 +176,9 @@ const EnvironmentOverride = ({
envName={getEnvName()}
/>
</Route>
<Route key={`${path}/${URLS.APP_CS_CONFIG}`} path={`${path}/${URLS.APP_CS_CONFIG}/:name?`}>
<Route path={`${path}/${URLS.APP_CS_CONFIG}/:name?`}>
<ConfigMapSecretWrapper
key={`secret-${params.appId}-${params.envId}`}
isProtected={isProtected}
parentState={viewState}
parentName={getParentName()}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ClusterNodes/ClusterOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EditableTextArea,
ResourceKindType,
getUrlWithSearchParams,
showError,
} from '@devtron-labs/devtron-fe-common-lib'
import {
ClusterErrorType,
Expand Down Expand Up @@ -89,7 +90,7 @@ const tippyForMetricsApi = () => {
)
}

function ClusterOverview({ isSuperAdmin, selectedCluster, addTab }: ClusterOverviewProps) {
function ClusterOverview({ selectedCluster, addTab }: ClusterOverviewProps) {
const { clusterId, namespace } = useParams<{
clusterId: string
namespace: string
Expand Down Expand Up @@ -132,7 +133,7 @@ function ClusterOverview({ isSuperAdmin, selectedCluster, addTab }: ClusterOverv
})
}
} catch (error) {
setErrorCode(error['code'])
showError(error)
throw error
}
}
Expand Down Expand Up @@ -512,7 +513,6 @@ function ClusterOverview({ isSuperAdmin, selectedCluster, addTab }: ClusterOverv
<GenericDescription
isClusterTerminal
clusterId={clusterId}
isSuperAdmin={isSuperAdmin}
descriptionId={descriptionData.descriptionId}
initialDescriptionText={descriptionData.descriptionText}
initialDescriptionUpdatedBy={descriptionData.descriptionUpdatedBy}
Expand Down
3 changes: 1 addition & 2 deletions src/components/ClusterNodes/ClusterSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const parseSearchParams = (searchParams: URLSearchParams) => ({

const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
clusterOptions,
isSuperAdmin,
clusterListLoader,
initialLoading,
refreshData,
Expand Down Expand Up @@ -190,7 +189,7 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
{/* NOTE: visible-hover plays with display prop; therefore need to set display: flex on a new div */}
<div className="cursor dc__visible-hover--child ml-8">
<div className="flexbox dc__align-items-center dc__gap-4">
{!!clusterData.nodeCount && !clusterListLoader && isSuperAdmin && (
{!!clusterData.nodeCount && !clusterListLoader && (
<Tooltip alwaysShowTippyOnHover content="View terminal">
<div className="flex">
<TerminalIcon
Expand Down
39 changes: 9 additions & 30 deletions src/components/ClusterNodes/NodeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import { unauthorizedInfoText } from '../ResourceBrowser/ResourceList/ClusterSel
import './clusterNodes.scss'
import ResourceBrowserActionMenu from '../ResourceBrowser/ResourceList/ResourceBrowserActionMenu'

const NodeDetails = ({ isSuperAdmin, addTab, lowercaseKindToResourceGroupMap, updateTabUrl }: ClusterListType) => {
const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }: ClusterListType) => {
const { clusterId, node } = useParams<{ clusterId: string; nodeType: string; node: string }>()
const [loader, setLoader] = useState(true)
const [apiInProgress, setApiInProgress] = useState(false)
Expand Down Expand Up @@ -799,12 +799,10 @@ const NodeDetails = ({ isSuperAdmin, addTab, lowercaseKindToResourceGroupMap, up
return (
<div className="fw-6 flex dc__content-space flex-grow-1 mr-12">
<div className="flex left">
{isSuperAdmin && (
<span className="flex left fw-6 cb-5 fs-12 cursor" onClick={openDebugTerminal}>
<TerminalLineIcon className="icon-dim-16 mr-5" />
{NODE_DETAILS_TABS.debug}
</span>
)}
<span className="flex left fw-6 cb-5 fs-12 cursor" onClick={openDebugTerminal}>
<TerminalLineIcon className="icon-dim-16 mr-5" />
{NODE_DETAILS_TABS.debug}
</span>
<span className="cn-2 mr-16 ml-16">|</span>
{renderTabControls()}
</div>
Expand Down Expand Up @@ -996,21 +994,8 @@ const NodeDetails = ({ isSuperAdmin, addTab, lowercaseKindToResourceGroupMap, up
return renderSummary()
}

const isAuthorized = (): boolean => {
if (!isSuperAdmin) {
ToastManager.showToast({
variant: ToastVariantType.notAuthorized,
description: TOAST_ACCESS_DENIED.SUBTITLE,
})
return false
}
return true
}

const showCordonNodeModal = (): void => {
if (isAuthorized()) {
setCordonNodeDialog(true)
}
setCordonNodeDialog(true)
}

const hideCordonNodeModal = (refreshData?: boolean): void => {
Expand All @@ -1021,9 +1006,7 @@ const NodeDetails = ({ isSuperAdmin, addTab, lowercaseKindToResourceGroupMap, up
}

const showDrainNodeModal = (): void => {
if (isAuthorized()) {
setDrainNodeDialog(true)
}
setDrainNodeDialog(true)
}

const hideDrainNodeModal = (refreshData?: boolean): void => {
Expand All @@ -1034,9 +1017,7 @@ const NodeDetails = ({ isSuperAdmin, addTab, lowercaseKindToResourceGroupMap, up
}

const showDeleteNodeModal = (): void => {
if (isAuthorized()) {
setDeleteNodeDialog(true)
}
setDeleteNodeDialog(true)
}

const hideDeleteNodeModal = (refreshData?: boolean): void => {
Expand All @@ -1047,9 +1028,7 @@ const NodeDetails = ({ isSuperAdmin, addTab, lowercaseKindToResourceGroupMap, up
}

const showEditTaintsModal = (): void => {
if (isAuthorized()) {
setShowEditTaints(true)
}
setShowEditTaints(true)
}

const hideEditTaintsModal = (refreshData?: boolean): void => {
Expand Down
2 changes: 0 additions & 2 deletions src/components/ClusterNodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export interface ColumnMetadataType {
}

export interface ClusterListType extends Pick<K8SResourceListType, 'lowercaseKindToResourceGroupMap'> {
isSuperAdmin: boolean
addTab?: ReturnType<typeof useTabs>['addTab']
updateTabUrl: (params: Omit<UpdateTabUrlParamsType, 'id'>) => void
}
Expand Down Expand Up @@ -344,7 +343,6 @@ export interface ClusterErrorType {
filterText: string[]
}
export interface ClusterOverviewProps {
isSuperAdmin: boolean
selectedCluster: ClusterOptionType
addTab: ReturnType<typeof useTabs>['addTab']
}
3 changes: 2 additions & 1 deletion src/components/ResourceBrowser/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const NAMESPACE_NOT_APPLICABLE_TEXT = 'Namespace is not applicable for th
export const CLUSTER_NOT_REACHABLE = 'Cluster is not reachable'

export const ORDERED_AGGREGATORS: AggregationKeysType[] = [
AggregationKeys.Nodes,
AggregationKeys.Events,
AggregationKeys.Namespaces,
AggregationKeys.Workloads,
Expand Down Expand Up @@ -222,7 +223,7 @@ export const UPGRADE_CLUSTER_CONSTANTS = {

export const JUMP_TO_KIND_SHORT_NAMES: Record<string, string[] | null> = {
events: null,
nodes: ['no'], // NOTE: hardcoding cuz backend doesn't send nodeGVK
nodes: null,
namespaces: null,
}

Expand Down
10 changes: 1 addition & 9 deletions src/components/ResourceBrowser/ResourceBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import React, { useEffect, useMemo, useRef } from 'react'
import {
showError,
getUserRole,
DevtronProgressing,
useAsync,
PageHeader,
Expand All @@ -44,11 +43,7 @@ const ResourceBrowser: React.FC = () => {
return null
}
})
const [initialLoading, data, error] = useAsync(() =>
Promise.all([getClusterListMin(), window._env_?.K8S_CLIENT ? null : getUserRole()]),
)
/* transpose the data */
const [clusterListMinData = null, userRoleData = null] = data || []
const [initialLoading, clusterListMinData, error] = useAsync(() => getClusterListMin())

useEffect(
() => () => {
Expand All @@ -67,8 +62,6 @@ const ResourceBrowser: React.FC = () => {
[detailClusterList, clusterListMinData],
)

const isSuperAdmin = userRoleData?.result.superAdmin || false

const renderContent = () => {
if (error) {
return <ErrorScreenManager code={error.code} />
Expand All @@ -77,7 +70,6 @@ const ResourceBrowser: React.FC = () => {
return (
<ClusterSelectionList
clusterOptions={sortedClusterList}
isSuperAdmin={isSuperAdmin}
clusterListLoader={detailClusterListLoading}
initialLoading={initialLoading}
refreshData={reloadDetailClusterList}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ResourceBrowser/ResourceList/AdminTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

import React, { useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { Progressing, ErrorScreenManager, Reload, useAsync } from '@devtron-labs/devtron-fe-common-lib'
import { Progressing, ErrorScreenManager, useAsync } from '@devtron-labs/devtron-fe-common-lib'
import ClusterTerminal from '../../ClusterNodes/ClusterTerminal'
import { createGroupSelectList, filterImageList } from '../../common'
import { createTaintsList } from '../../cluster/cluster.util'
import { clusterNamespaceList, getClusterCapacity } from '../../ClusterNodes/clusterNodes.service'
import { getHostURLConfiguration } from '../../../services/service'
import { AdminTerminalProps, URLParams } from '../Types'

const AdminTerminal: React.FC<AdminTerminalProps> = ({ isSuperAdmin, updateTerminalTabUrl }: AdminTerminalProps) => {
const AdminTerminal: React.FC<AdminTerminalProps> = ({ updateTerminalTabUrl }: AdminTerminalProps) => {
const { clusterId } = useParams<URLParams>()

const [loading, data, error] = useAsync(
Expand Down Expand Up @@ -65,7 +65,7 @@ const AdminTerminal: React.FC<AdminTerminalProps> = ({ isSuperAdmin, updateTermi
const errCode = error?.code || 403
return (
<div className="bcn-0 node-data-container flex">
{isSuperAdmin ? <Reload /> : <ErrorScreenManager code={errCode} />}
<ErrorScreenManager code={errCode} />
</div>
)
}
Expand Down
13 changes: 6 additions & 7 deletions src/components/ResourceBrowser/ResourceList/BaseResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const BaseResourceListContent = ({

const { searchParams } = useSearchString()

const isNodeListing = selectedResource.gvk.Kind === SIDEBAR_KEYS.nodeGVK.Kind
const isNodeListing = selectedResource?.gvk.Kind === SIDEBAR_KEYS.nodeGVK.Kind

const {
selectedIdentifiers: bulkSelectionState,
Expand Down Expand Up @@ -261,7 +261,7 @@ const BaseResourceListContent = ({

handleFilterChanges(searchText)
setResourceListOffset(0)
}, [resourceList, sortBy, sortOrder, location.search])
}, [resourceList, sortBy, sortOrder, location.search, isOpen])

const getHandleCheckedForId = (resourceData: K8sResourceDetailDataType) => () => {
const { id } = resourceData as Record<'id', string>
Expand Down Expand Up @@ -431,7 +431,7 @@ const BaseResourceListContent = ({
{headers.map((columnName) =>
columnName === 'name' ? (
<div
key={resourceData.id as string}
key={`${resourceData.id}-${columnName}`}
className={`flexbox dc__align-items-center dc__gap-4 dc__content-space dc__visible-hover dc__visible-hover--parent ${shouldShowRedirectionAndActions ? '' : 'pr-8'}`}
data-testid="created-resource-name"
>
Expand Down Expand Up @@ -505,7 +505,7 @@ const BaseResourceListContent = ({
</div>
) : (
<div
key={resourceData.id as string}
key={`${resourceData.id}-${columnName}`}
className={`flexbox dc__align-items-center ${
columnName === 'status'
? ` app-summary__status-name ${getStatusClass(String(resourceData[columnName]))}`
Expand Down Expand Up @@ -579,7 +579,7 @@ const BaseResourceListContent = ({
}

const renderContent = () => {
if (!resourceListError && (isLoading || !resourceList || !filteredResourceList)) {
if (!resourceListError && (isLoading || !resourceList || !filteredResourceList || !selectedResource)) {
return <Progressing size={32} pageLoader />
}

Expand Down Expand Up @@ -639,7 +639,6 @@ const BaseResourceListContent = ({
<BulkSelection showPagination={showPaginatedView} />
)}
<SortableTableHeaderCell
key={columnName}
showTippyOnTruncate
title={columnName}
triggerSorting={triggerSortingHandler(columnName)}
Expand Down Expand Up @@ -690,7 +689,7 @@ const BaseResourceListContent = ({
/>
) : (
<ResourceFilterOptions
key={`${selectedResource.gvk.Kind}-${selectedResource.gvk.Group}`}
key={`${selectedResource?.gvk.Kind}-${selectedResource?.gvk.Group}`}
selectedResource={selectedResource}
selectedNamespace={selectedNamespace}
setSelectedNamespace={setSelectedNamespace}
Expand Down
Loading

0 comments on commit 67d776f

Please sign in to comment.