Skip to content

Commit

Permalink
refactor: ClusterForm, ClusterSelectionList, ClusterMap - types refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitRaj011 committed Nov 4, 2024
1 parent a67c584 commit c480cd8
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Link } from 'react-router-dom'
import { ResponsiveContainer, Treemap, TreemapProps } from 'recharts'
import { followCursor } from 'tippy.js'

import { ConditionalWrap, Tooltip } from '@devtron-labs/devtron-fe-common-lib'

import { ClusterStatusType } from '@Components/ClusterNodes/types'
import { ClusterStatusType, ConditionalWrap, Tooltip } from '@devtron-labs/devtron-fe-common-lib'

Check failure on line 5 in src/Pages/ResourceBrowser/ClusterList/ClusterMap/ClusterMap.tsx

View workflow job for this annotation

GitHub Actions / ci

'"@devtron-labs/devtron-fe-common-lib"' has no exported member named 'ClusterStatusType'. Did you mean 'StageStatusType'?

import { getVisibleSvgTextWithEllipsis } from './utils'
import { ClusterMapProps } from './types'
Expand Down Expand Up @@ -53,7 +51,7 @@ const ClusterTreeMapContent = ({
className={`cluster-map__rect ${status === 'unhealthy' ? 'cluster-map__rect--unhealthy' : ''}`}
/>
<text x={x + 8} y={y + 22} className="cluster-map__text fcn-9 fs-13 fw-6">
{getVisibleSvgTextWithEllipsis(name, width, 13, 600)}
{getVisibleSvgTextWithEllipsis({ text: name, maxWidth: width, fontSize: 13, fontWeight: 600 })}
</text>
<text x={x + 8} y={y + 38} className="cluster-map__text fcn-9 fs-12 fw-4">
{value}
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/ResourceBrowser/ClusterList/ClusterMap/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClusterStatusType } from '@Components/ClusterNodes/types'
import { ClusterStatusType } from '@devtron-labs/devtron-fe-common-lib'

Check failure on line 1 in src/Pages/ResourceBrowser/ClusterList/ClusterMap/types.ts

View workflow job for this annotation

GitHub Actions / ci

'"@devtron-labs/devtron-fe-common-lib"' has no exported member named 'ClusterStatusType'. Did you mean 'StageStatusType'?

interface MapData {
name: string
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/ResourceBrowser/ClusterList/ClusterMap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getVisibleSvgTextWithEllipsis = (() => {
let svgInstance: SVGSVGElement | null = null
let textElementInstance: SVGTextElement | null = null

return (text: string = '', maxWidth: number = 0, fontSize = 16, fontWeight = 400) => {
return ({ text = '', maxWidth = 0, fontSize = 16, fontWeight = 400 }) => {
if (!svgInstance || !textElementInstance) {
const { svg, textElement } = createMeasurementSvg(fontSize, fontWeight)
svgInstance = svg
Expand Down
19 changes: 13 additions & 6 deletions src/components/ClusterNodes/ClusterSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

import React, { useState, useMemo } from 'react'
import { useHistory, useLocation, Link } from 'react-router-dom'
import { GenericEmptyState, SearchBar, useUrlFilters, Tooltip } from '@devtron-labs/devtron-fe-common-lib'
import {
GenericEmptyState,
SearchBar,
useUrlFilters,
Tooltip,
ClusterFiltersType,

Check failure on line 24 in src/components/ClusterNodes/ClusterSelectionList.tsx

View workflow job for this annotation

GitHub Actions / ci

Module '"@devtron-labs/devtron-fe-common-lib"' has no exported member 'ClusterFiltersType'.
ClusterStatusType,

Check failure on line 25 in src/components/ClusterNodes/ClusterSelectionList.tsx

View workflow job for this annotation

GitHub Actions / ci

'"@devtron-labs/devtron-fe-common-lib"' has no exported member named 'ClusterStatusType'. Did you mean 'StageStatusType'?
} from '@devtron-labs/devtron-fe-common-lib'
import dayjs, { Dayjs } from 'dayjs'
import { importComponentFromFELibrary } from '@Components/common'
import Timer from '@Components/common/DynamicTabs/DynamicTabs.timer'
Expand All @@ -26,7 +33,7 @@ import { ReactComponent as Error } from '@Icons/ic-error-exclamation.svg'
import { ReactComponent as Success } from '@Icons/appstatus/healthy.svg'
import { ReactComponent as TerminalIcon } from '@Icons/ic-terminal-fill.svg'
import { ClusterMap, ClusterTreeMapData } from '@Pages/ResourceBrowser'
import { ClusterDetail, ClusterFiltersType, ClusterStatusType } from './types'
import { ClusterDetail } from './types'
import ClusterNodeEmptyState from './ClusterNodeEmptyStates'
import { ClusterSelectionType } from '../ResourceBrowser/Types'
import { AppDetailsTabs } from '../v2/appDetails/appDetails.store'
Expand All @@ -36,7 +43,7 @@ import { ClusterStatusByFilter } from './constants'
import './clusterNodes.scss'

const KubeConfigButton = importComponentFromFELibrary('KubeConfigButton', null, 'function')
const ClusterStatus = importComponentFromFELibrary('ClusterStatus', null, 'function')
const ClusterStatusCell = importComponentFromFELibrary('ClusterStatus', null, 'function')
const ClusterFilters = importComponentFromFELibrary('ClusterFilters', null, 'function')

const getClusterMapData = (data: ClusterDetail[]): ClusterTreeMapData['data'] =>
Expand Down Expand Up @@ -77,7 +84,7 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({

return (!searchKey || option.name.toLowerCase().includes(loweredSearchKey)) && filterCondition
})
}, [searchKey, clusterOptions, clusterFilter])
}, [searchKey, clusterOptions, `${clusterFilter}`])

const treeMapData = useMemo<ClusterTreeMapData[]>(() => {
const { prodClusters, nonProdClusters } = filteredList.reduce(
Expand Down Expand Up @@ -149,8 +156,8 @@ const ClusterSelectionList: React.FC<ClusterSelectionType> = ({
}

const renderClusterStatus = ({ errorInNodeListing, status }: ClusterDetail) => {
if (ClusterStatus && status) {
return <ClusterStatus status={status} />
if (ClusterStatusCell && status) {
return <ClusterStatusCell status={status} />
}

return (
Expand Down
7 changes: 5 additions & 2 deletions src/components/ClusterNodes/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
* limitations under the License.
*/

import { ClusterFiltersType, ClusterStatusType } from '@devtron-labs/devtron-fe-common-lib'

Check failure on line 17 in src/components/ClusterNodes/constants.ts

View workflow job for this annotation

GitHub Actions / ci

Module '"@devtron-labs/devtron-fe-common-lib"' has no exported member 'ClusterFiltersType'.

Check failure on line 17 in src/components/ClusterNodes/constants.ts

View workflow job for this annotation

GitHub Actions / ci

'"@devtron-labs/devtron-fe-common-lib"' has no exported member named 'ClusterStatusType'. Did you mean 'StageStatusType'?

import { multiSelectStyles } from '../v2/common/ReactSelectCustomization'
import { ClusterFiltersType, ClusterStatusType, ColumnMetadataType, EFFECT_TYPE } from './types'
import { ColumnMetadataType, EFFECT_TYPE } from './types'

export const clusterSelectStyle = {
...multiSelectStyles,
Expand Down Expand Up @@ -485,7 +487,8 @@ export const defaultManifestErrorText =

export const manifestCommentsRegex = /^(.*?apiVersion:)/s

export const ClusterStatusByFilter = {
export const ClusterStatusByFilter: Record<ClusterFiltersType, ClusterStatusType> = {
[ClusterFiltersType.HEALTHY]: ClusterStatusType.HEALTHY,
[ClusterFiltersType.UNHEALTHY]: ClusterStatusType.UNHEALTHY,
[ClusterFiltersType.ALL_CLUSTERS]: null,
}
14 changes: 1 addition & 13 deletions src/components/ClusterNodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import React from 'react'
import { MultiValue } from 'react-select'
import { ResponseType, ApiResourceGroupType } from '@devtron-labs/devtron-fe-common-lib'
import { ResponseType, ApiResourceGroupType, ClusterStatusType } from '@devtron-labs/devtron-fe-common-lib'

Check failure on line 19 in src/components/ClusterNodes/types.ts

View workflow job for this annotation

GitHub Actions / ci

'"@devtron-labs/devtron-fe-common-lib"' has no exported member named 'ClusterStatusType'. Did you mean 'StageStatusType'?
import { LabelTag, OptionType } from '../app/types'
import { CLUSTER_PAGE_TAB, NODE_SEARCH_TEXT } from './constants'
import { EditModeType } from '../v2/appDetails/k8Resource/nodeDetail/NodeDetailTabs/terminal/constants'
Expand Down Expand Up @@ -65,18 +65,6 @@ export interface NodeDetailsType {
taints?: NodeTaintType[]
}

export enum ClusterFiltersType {
ALL_CLUSTERS = 'all',
HEALTHY = 'healthy',
UNHEALTHY = 'unhealthy',
}

export enum ClusterStatusType {
HEALTHY = 'healthy',
UNHEALTHY = 'unhealthy',
CONNECTION_FAILED = 'connection failed',
}

export interface ClusterCapacityType {
name: string
nodeCount: number
Expand Down
11 changes: 6 additions & 5 deletions src/components/cluster/ClusterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
DEFAULT_CLUSTER_ID,
SSHAuthenticationType,
RemoteConnectionTypeCluster,
ClusterFormProps,
} from './cluster.type'

import { CLUSTER_COMMAND, AppCreationType, MODES, ModuleNameMap } from '../../config'
Expand Down Expand Up @@ -132,8 +133,8 @@ export default function ClusterForm({
isClusterDetails,
toggleClusterDetails,
isVirtualCluster,
isProd
}) {
isProd,
}: ClusterFormProps) {
const [prometheusToggleEnabled, setPrometheusToggleEnabled] = useState(!!prometheus_url)
const [prometheusAuthenticationType, setPrometheusAuthenticationType] = useState({
type: prometheusAuth?.userName ? AuthenticationType.BASIC : AuthenticationType.ANONYMOUS,
Expand Down Expand Up @@ -463,7 +464,7 @@ export default function ClusterForm({
cert_data: state.tlsClientCert.value,
cert_auth_data: state.certificateAuthorityData.value,
},
isProd: state.isProd.value === "true",
isProd: state.isProd.value === 'true',
active,
remoteConnectionConfig: getRemoteConnectionConfig(state, remoteConnectionMethod, SSHConnectionType),
prometheus_url: prometheusToggleEnabled ? state.endpoint.value : '',
Expand Down Expand Up @@ -768,8 +769,8 @@ export default function ClusterForm({
value={state.isProd.value}
onChange={handleOnChange}
>
<RadioGroupItem value={'true'}>Production</RadioGroupItem>
<RadioGroupItem value={'false'}>Non - Production</RadioGroupItem>
<RadioGroupItem value="true">Production</RadioGroupItem>
<RadioGroupItem value="false">Non - Production</RadioGroupItem>
</RadioGroup>
{id !== DEFAULT_CLUSTER_ID && RemoteConnectionRadio && (
<>
Expand Down
4 changes: 4 additions & 0 deletions src/components/cluster/cluster.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,7 @@ export interface ClusterFormType {
}

export const RemoteConnectionTypeCluster = 'cluster'

export type ClusterFormProps = Record<string, any> & {
isProd: boolean
}

0 comments on commit c480cd8

Please sign in to comment.