Skip to content

Commit 927b29b

Browse files
committed
Merge branch 'kubecon-2024' of github.com:devtron-labs/devtron-fe-common-lib into feat/resource-browser-visualizations
2 parents f9643b8 + 8a93bf6 commit 927b29b

File tree

9 files changed

+73
-19
lines changed

9 files changed

+73
-19
lines changed

src/Common/Api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,4 @@ export const abortPreviousRequests = <T>(
264264
*/
265265
export const getIsRequestAborted = (error) =>
266266
// The 0 code is common for aborted and blocked requests
267-
error && error.code === 0 && error.message.search('abort|aborted')
267+
error && error.code === 0 && error.message.search('abort|aborted') > -1

src/Pages/ResourceBrowser/ResourceBrowser.Types.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { NodeType, Nodes } from '@Shared/types'
18+
import { RefObject } from 'react'
1819

1920
export interface GVKType {
2021
Group: string
@@ -38,3 +39,30 @@ export interface K8SObjectBaseType {
3839
name: string
3940
isExpanded: boolean
4041
}
42+
43+
export interface BulkSelectionActionWidgetProps {
44+
count: number
45+
handleOpenBulkDeleteModal: () => void
46+
handleClearBulkSelection: () => void
47+
handleOpenRestartWorkloadModal: () => void
48+
parentRef: RefObject<HTMLDivElement>
49+
showBulkRestartOption: boolean
50+
}
51+
52+
export interface BulkOperation {
53+
name: string
54+
operation: (signal: AbortSignal, data?: unknown) => Promise<void>
55+
}
56+
57+
export type BulkOperationModalProps = {
58+
operationType: 'restart' | 'delete'
59+
clusterName: string
60+
operations: NonNullable<BulkOperation[]>
61+
handleModalClose: () => void
62+
resourceKind: string
63+
handleReloadDataAfterBulkOperation?: () => void
64+
hideResultsDrawer?: boolean
65+
shouldAllowForceOperation?: true
66+
}
67+
68+
export type BulkOperationModalState = BulkOperationModalProps['operationType'] | 'closed'

src/Shared/API/APIQueuing.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ const eachCall = (batchConfig, functionCalls, resolve, reject, shouldRejectOnErr
5454
*/
5555
const ApiQueuingWithBatch = <T>(
5656
functionCalls,
57-
httpProtocol: string,
5857
shouldRejectOnError: boolean = false,
5958
batchSize: number = window._env_.API_BATCH_SIZE,
6059
): Promise<ApiQueuingWithBatchResponseItem<T>[]> => {
60+
const httpProtocol = (window.performance.getEntriesByType('resource') as PerformanceResourceTiming[]).reduce(
61+
(fallbackProtocol, entry) => entry.nextHopProtocol ?? fallbackProtocol,
62+
'http/1.0',
63+
)
64+
6165
if (!batchSize || batchSize <= 0) {
6266
// eslint-disable-next-line no-param-reassign
6367
batchSize = ['http/0.9', 'http/1.0', 'http/1.1'].indexOf(httpProtocol) !== -1 ? 5 : 30

src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
UseBulkSelectionProps,
3131
UseBulkSelectionReturnType,
3232
} from './types'
33-
import { CHECKBOX_VALUE, noop } from '../../../Common'
33+
import { CHECKBOX_VALUE, noop, useEffectAfterMount } from '../../../Common'
3434

3535
// giving type any here since not exporting this context, rather using it through useBulkSelection hook which is typed
3636
const BulkSelectionContext = createContext<UseBulkSelectionReturnType<any>>({
@@ -39,6 +39,7 @@ const BulkSelectionContext = createContext<UseBulkSelectionReturnType<any>>({
3939
isChecked: false,
4040
checkboxValue: CHECKBOX_VALUE.CHECKED,
4141
isBulkSelectionApplied: false,
42+
setIdentifiers: noop,
4243
getSelectedIdentifiersCount: noop,
4344
})
4445

@@ -52,10 +53,17 @@ export const useBulkSelection = <T,>() => {
5253

5354
export const BulkSelectionProvider = <T,>({
5455
children,
55-
identifiers,
56+
identifiers = null,
5657
getSelectAllDialogStatus,
5758
}: UseBulkSelectionProps<T>) => {
5859
const [selectedIdentifiers, setSelectedIdentifiers] = useState<T>({} as T)
60+
const [identifiersOnCurrentPage, setIdentifiersOnCurrentPage] = useState(identifiers ?? ({} as T))
61+
62+
useEffectAfterMount(() => {
63+
if (identifiers) {
64+
setIdentifiersOnCurrentPage(identifiers)
65+
}
66+
}, [identifiers])
5967

6068
const isBulkSelectionApplied = selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]
6169

@@ -96,7 +104,7 @@ export const BulkSelectionProvider = <T,>({
96104
variant: ToastVariantType.info,
97105
description: CLEAR_SELECTIONS_WARNING,
98106
})
99-
setIdentifiersAfterClear(identifiers, selectedIds)
107+
setIdentifiersAfterClear(identifiersOnCurrentPage, selectedIds)
100108
break
101109
}
102110

@@ -137,7 +145,7 @@ export const BulkSelectionProvider = <T,>({
137145
})
138146
}
139147

140-
setIdentifiersAfterPageSelection(identifiers)
148+
setIdentifiersAfterPageSelection(identifiersOnCurrentPage)
141149
break
142150
}
143151

@@ -169,7 +177,7 @@ export const BulkSelectionProvider = <T,>({
169177
}
170178

171179
// if all the identifiers are selected then CHECKED else intermediate
172-
const areAllPresentIdentifiersSelected = Object.keys(identifiers).every(
180+
const areAllPresentIdentifiersSelected = Object.keys(identifiersOnCurrentPage).every(
173181
(identifierId) => selectedIdentifiers[identifierId],
174182
)
175183

@@ -196,8 +204,17 @@ export const BulkSelectionProvider = <T,>({
196204
checkboxValue,
197205
isBulkSelectionApplied,
198206
getSelectedIdentifiersCount,
207+
setIdentifiers: setIdentifiersOnCurrentPage,
199208
}),
200-
[selectedIdentifiers, handleBulkSelection, isChecked, checkboxValue, getSelectedIdentifiersCount],
209+
[
210+
selectedIdentifiers,
211+
handleBulkSelection,
212+
isChecked,
213+
checkboxValue,
214+
getSelectedIdentifiersCount,
215+
identifiersOnCurrentPage,
216+
isBulkSelectionApplied,
217+
],
201218
)
202219

203220
return <BulkSelectionContext.Provider value={value}>{children}</BulkSelectionContext.Provider>

src/Shared/Components/BulkSelection/types.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface UseBulkSelectionReturnType<T> extends GetBulkSelectionCheckboxV
4444
handleBulkSelection: ({ action, data }: HandleBulkSelectionType<T>) => void
4545
isBulkSelectionApplied: boolean
4646
getSelectedIdentifiersCount: () => number
47+
setIdentifiers: React.Dispatch<React.SetStateAction<T>>
4748
}
4849

4950
export interface BulkSelectionProps {
@@ -72,14 +73,16 @@ export enum SelectAllDialogStatus {
7273
export type BulkSelectionIdentifiersType<T> = Record<string | number, T>
7374

7475
export interface UseBulkSelectionProps<T> {
75-
/**
76-
* Response from API, assuming structure to be array of objects with key and values
77-
* This will the given ids on current page
78-
*/
79-
identifiers: T
8076
/**
8177
* Act as buffer between select all across pages and select all on page state
8278
*/
8379
getSelectAllDialogStatus: () => SelectAllDialogStatus
80+
/**
81+
* Response from API, assuming structure to be array of objects with key and values
82+
* This will the given ids on current page.
83+
*
84+
* NOTE!: Please wrap this value with a useMemo since it goes into useEffect dependency
85+
*/
86+
identifiers?: T
8487
children?: React.ReactNode
8588
}

src/Shared/Components/Security/SecurityModal/config/ImageScan.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ const getVulnerabilitiesDetailData = (
115115
return getGroupedVulnerabilitiesDetailData(element, setDetailViewData, hidePolicy)
116116
}
117117

118-
const getImageScanProgressingState = (status: StatusType['status']) => {
118+
export const getProgressingStateForStatus = (status: StatusType['status']) => {
119119
switch (status) {
120120
case 'Completed':
121-
return <ICSuccess className="icon-dim-16" />
121+
return <ICSuccess className="icon-dim-16 dc__no-shrink" />
122122
case 'Failed':
123-
return <ICError className="icon-dim-16 ic-error-cross-red" />
123+
return <ICError className="icon-dim-16 ic-error-cross-red dc__no-shrink" />
124124
case 'Progressing':
125125
return (
126126
<Progressing
@@ -182,7 +182,7 @@ const getVulnerabilitiesData = (
182182
{
183183
component: (
184184
<div className="flexbox dc__align-items-center dc__gap-4">
185-
{getImageScanProgressingState(element.status)}
185+
{getProgressingStateForStatus(element.status)}
186186
<span>{getTimeString(element.StartedOn, element.status)}</span>
187187
</div>
188188
),
@@ -281,7 +281,7 @@ const getLicenseData = (
281281
{
282282
component: (
283283
<div className="flexbox dc__align-items-center dc__gap-4">
284-
{getImageScanProgressingState(element.status)}
284+
{getProgressingStateForStatus(element.status)}
285285
<span>{getTimeString(element.StartedOn, element.status)}</span>
286286
</div>
287287
),

src/Shared/Components/Security/SecurityModal/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
export { getTableData } from './Table'
66
export { getInfoCardData } from './InfoCard'
77
export { SIDEBAR_DATA } from './Sidebar'
8+
export { getProgressingStateForStatus } from './ImageScan'

src/Shared/Components/Security/SecurityModal/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export type {
1919
GetResourceScanDetailsPayloadType,
2020
GetResourceScanDetailsResponseType,
2121
} from './types'
22-
export { SIDEBAR_DATA } from './config'
22+
export { SIDEBAR_DATA, getProgressingStateForStatus } from './config'
2323
export { CATEGORY_LABELS } from './constants'
2424
export { getExecutionDetails } from './service'

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface customEnv {
8585
FEATURE_PROMO_EMBEDDED_BUTTON_TEXT?: string
8686
FEATURE_PROMO_EMBEDDED_MODAL_TITLE?: string
8787
FEATURE_PROMO_EMBEDDED_IFRAME_URL?: string
88+
FEATURE_BULK_RESTART_WORKLOADS_FROM_RB: string
8889
}
8990
declare global {
9091
interface Window {

0 commit comments

Comments
 (0)