Skip to content

Commit 84a9b0b

Browse files
committed
chore: code cleanup
1 parent 18825e6 commit 84a9b0b

File tree

7 files changed

+37
-86
lines changed

7 files changed

+37
-86
lines changed

src/components/AppSelector/ChartSelector.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export default function ChartSelector({
6969
},
7070
]
7171

72+
const selectedChartLabel = listMap.has(_primaryKey) ? (listMap.get(_primaryKey)[primaryValue] as string) : ''
73+
7274
return (
7375
<ContextSwitcher
7476
inputId="chart-select"
@@ -79,9 +81,9 @@ export default function ChartSelector({
7981
onChange={selectApp}
8082
value={{
8183
value: _primaryKey,
82-
label: listMap.has(_primaryKey) ? (listMap.get(_primaryKey)[primaryValue] as string) : '',
84+
label: selectedChartLabel,
8385
}}
84-
placeholder={_primaryKey}
86+
placeholder={selectedChartLabel}
8587
{...(formatOptionLabel ? { formatOptionLabel } : {})}
8688
{...(filterOption ? { filterOption } : {})}
8789
/>

src/components/ApplicationGroup/AppGroup.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ export const envListOptions = (
177177
? [
178178
{
179179
label: 'Recently Visited',
180-
options: recentlyVisitedDevtronApps.map((app: BaseRecentlyVisitedEntitiesTypes) => ({
181-
label: app.name,
182-
value: app.id,
180+
options: recentlyVisitedDevtronApps.map((env: BaseRecentlyVisitedEntitiesTypes) => ({
181+
label: env.name,
182+
value: env.id,
183183
isRecentlyVisited: true,
184184
})) as RecentlyVisitedOptions[],
185185
},

src/components/ApplicationGroup/EnvSelector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ import { envListOptions } from './AppGroup.utils'
3333
export const EnvSelector = ({ onChange, envId, envName }: EnvSelectorType) => {
3434
const abortControllerRef = useRef<AbortController>(new AbortController())
3535
const defaultOptions = { value: envId, label: envName }
36-
const isAppDataAvailable = !!envId && !!envName
36+
const isEnvDataAvailable = !!envId && !!envName
3737

3838
const [inputValue, setInputValue] = useState('')
3939
const { recentlyVisitedResources } = useUserPreferences({
4040
recentlyVisitedFetchConfig: {
4141
id: envId,
4242
name: envName,
4343
resourceKind: 'app-group',
44-
isDataAvailable: isAppDataAvailable,
44+
isDataAvailable: isEnvDataAvailable,
4545
},
4646
})
4747

4848
const [loading, selectOptions] = useAsync(
4949
() => envListOptions(inputValue, abortControllerRef.current.signal, recentlyVisitedResources),
5050
[inputValue, recentlyVisitedResources],
51-
isAppDataAvailable && !!recentlyVisitedResources.length,
51+
isEnvDataAvailable && !!recentlyVisitedResources.length,
5252
)
5353

5454
const onInputChange: SelectPickerProps['onInputChange'] = async (val) => {

src/components/ResourceBrowser/ResourceBrowser.service.tsx

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { RefObject } from 'react'
1919
import {
2020
APIOptions,
2121
ApiResourceType,
22-
BaseRecentlyVisitedEntitiesTypes,
2322
ClusterDetail,
2423
get,
2524
getIsRequestAborted,
@@ -28,23 +27,17 @@ import {
2827
getNamespaceListMin,
2928
getUrlWithSearchParams,
3029
Nodes,
31-
RecentlyVisitedGroupedOptionsType,
32-
RecentlyVisitedOptions,
3330
ResponseType,
3431
showError,
3532
stringComparatorBySortOrder,
3633
} from '@devtron-labs/devtron-fe-common-lib'
3734

38-
import {} from '@Components/AppSelector/AppSelector.types'
39-
import { getMinCharSearchPlaceholderGroup } from '@Components/AppSelector/constants'
4035
import {
4136
getClusterListMinWithInstalledClusters,
4237
getClusterListWithInstalledClusters,
4338
} from '@Components/ClusterNodes/clusterNodes.service'
4439

4540
import { Routes } from '../../config'
46-
import { ClusterListOptionsTypes } from './ResourceList/types'
47-
import { getOptionsValue } from './ResourceList/utils'
4841
import { SIDEBAR_KEYS } from './Constants'
4942
import { GetResourceDataType, NodeRowDetail, URLParams } from './Types'
5043
import { parseNodeList } from './Utils'
@@ -154,41 +147,3 @@ export const getClusterListing = async (
154147
throw err
155148
}
156149
}
157-
158-
export const clusterListOptions = ({
159-
clusterList,
160-
isInstallationStatusView = false,
161-
inputValue,
162-
recentlyVisitedResources,
163-
}: ClusterListOptionsTypes): Promise<RecentlyVisitedGroupedOptionsType[]> =>
164-
new Promise((resolve) => {
165-
setTimeout(() => {
166-
if (inputValue.length < 3) {
167-
resolve(
168-
recentlyVisitedResources?.length
169-
? [
170-
{
171-
label: 'Recently Visited',
172-
options: recentlyVisitedResources.map((app: BaseRecentlyVisitedEntitiesTypes) => ({
173-
label: app.name,
174-
value: app.id,
175-
isRecentlyVisited: true,
176-
})) as RecentlyVisitedOptions[],
177-
},
178-
getMinCharSearchPlaceholderGroup('Clusters'),
179-
]
180-
: [],
181-
)
182-
} else {
183-
resolve([
184-
{
185-
label: 'All Clusters',
186-
options: clusterList?.map((option) => ({
187-
...option,
188-
value: +getOptionsValue(option, isInstallationStatusView),
189-
})) as RecentlyVisitedOptions[],
190-
},
191-
] as RecentlyVisitedGroupedOptionsType[])
192-
}
193-
}, 300)
194-
})

src/components/ResourceBrowser/ResourceList/ClusterSelector.tsx

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@ import {
2323
ContextSwitcher,
2424
Icon,
2525
PopupMenu,
26-
ResourceKindType,
2726
SelectPickerProps,
28-
useAsync,
29-
useUserPreferences,
3027
} from '@devtron-labs/devtron-fe-common-lib'
3128

3229
import { ReactComponent as MenuDots } from '@Icons/ic-more-vertical.svg'
3330
import { DEFAULT_CLUSTER_ID } from '@Pages/GlobalConfigurations/ClustersAndEnvironments'
3431
import DeleteClusterConfirmationModal from '@Pages/GlobalConfigurations/ClustersAndEnvironments/DeleteClusterConfirmationModal'
3532

3633
import { URLS } from '../../../config'
37-
import { clusterListOptions } from '../ResourceBrowser.service'
3834
import { ClusterSelectorType } from '../Types'
35+
import { getClusterSelectOptions } from './utils'
3936

4037
const ClusterSelector: React.FC<ClusterSelectorType> = ({
4138
onChange,
@@ -54,19 +51,7 @@ const ClusterSelector: React.FC<ClusterSelectorType> = ({
5451
isInstallationStatusView ? String(item.installationId) === clusterId : String(item.value) === clusterId,
5552
)
5653

57-
const clusterName = defaultOption?.label
58-
5954
const [inputValue, setInputValue] = useState('')
60-
const isAppDataAvailable = !!clusterId && !!clusterName
61-
62-
const { recentlyVisitedResources } = useUserPreferences({
63-
recentlyVisitedFetchConfig: {
64-
id: +clusterId,
65-
name: clusterName,
66-
resourceKind: ResourceKindType.cluster,
67-
isDataAvailable: isAppDataAvailable,
68-
},
69-
})
7055

7156
const [openDeleteClusterModal, setOpenDeleteClusterModal] = useState(false)
7257

@@ -86,26 +71,14 @@ const ClusterSelector: React.FC<ClusterSelectorType> = ({
8671
replace(URLS.RESOURCE_BROWSER)
8772
}
8873

89-
const [loading, selectOption] = useAsync(
90-
() =>
91-
clusterListOptions({
92-
clusterList: filteredClusterList,
93-
inputValue,
94-
recentlyVisitedResources,
95-
isInstallationStatusView,
96-
}),
97-
[filteredClusterList, inputValue, recentlyVisitedResources],
98-
isAppDataAvailable && !!recentlyVisitedResources.length,
99-
)
100-
10174
return (
10275
<div className="flexbox dc__align-items-center dc__gap-12">
10376
<ContextSwitcher
10477
inputId="cluster-select-header"
105-
isLoading={loading || isClusterListLoading}
78+
isLoading={isClusterListLoading}
10679
onChange={onChange}
10780
value={defaultOption}
108-
options={selectOption}
81+
options={getClusterSelectOptions(filteredClusterList, isInstallationStatusView)}
10982
inputValue={inputValue}
11083
onInputChange={onInputChange}
11184
/>

src/components/ResourceBrowser/ResourceList/utils.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ClusterDetail, DocLink, DocLinkProps, logExceptionToSentry, noop } from '@devtron-labs/devtron-fe-common-lib'
17+
import {
18+
ClusterDetail,
19+
DocLink,
20+
DocLinkProps,
21+
logExceptionToSentry,
22+
noop,
23+
RecentlyVisitedGroupedOptionsType,
24+
RecentlyVisitedOptions,
25+
} from '@devtron-labs/devtron-fe-common-lib'
1826

1927
import { sortObjectArrayAlphabetically } from '@Components/common'
2028

@@ -156,3 +164,13 @@ export const getOptionsValue = (option: ClusterOptionType, isInstallationStatusV
156164
// get its value as installationId. Prefixing it with installation- to avoid collision with normal clusters have same value of
157165
// clusterId as this installationId
158166
isInstallationStatusView ? `installation-${String(option.installationId)}` : option.value
167+
168+
export const getClusterSelectOptions = (clusterList, isInstallationStatusView): RecentlyVisitedGroupedOptionsType[] => [
169+
{
170+
label: 'All Clusters',
171+
options: clusterList?.map((option) => ({
172+
...option,
173+
value: +getOptionsValue(option, isInstallationStatusView),
174+
})) as RecentlyVisitedOptions[],
175+
},
176+
]

src/components/app/details/main.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const AIAgentContextSetterWrapper = ({ children, appName }: PropsWithChildren<{
7373
contextData['Workflow_id'] = contextData.buildId
7474
delete contextData.buildId
7575
}
76-
setAIAgentContext({ path, context: { appName, ...contextData }})
76+
setAIAgentContext({ path, context: { appName, ...contextData } })
7777
}, [path, url])
7878

7979
return <>{children}</>
@@ -101,7 +101,10 @@ export default function AppDetailsPage() {
101101
const [apiError, setApiError] = useState(null)
102102
const [initLoading, setInitLoading] = useState<boolean>(false)
103103

104-
const { fetchRecentlyVisitedParsedEntities } = useUserPreferences({recentlyVisitedFetchConfig: { id: appId, name: '', resourceKind: ResourceKindType.devtronApplication }})
104+
// Passing name value as empty string to check if app exists
105+
const { fetchRecentlyVisitedParsedEntities } = useUserPreferences({
106+
recentlyVisitedFetchConfig: { id: appId, name: '', resourceKind: ResourceKindType.devtronApplication },
107+
})
105108

106109
const getAppMetaInfoRes = async (shouldResetAppName: boolean = false): Promise<AppMetaInfo> => {
107110
try {

0 commit comments

Comments
 (0)