From 1c3c990f3c942c01562f3710456da364b701049e Mon Sep 17 00:00:00 2001 From: Amrit Kashyap Borah Date: Wed, 23 Oct 2024 16:13:26 +0530 Subject: [PATCH 1/6] feat: allow setting identifiers internally in bulk selection provider change ApiQueuingWithBatch call signature; find http protocol internally --- src/Shared/API/APIQueuing.ts | 6 +++- .../BulkSelection/BulkSelectionProvider.tsx | 29 +++++++++++++++---- src/Shared/Components/BulkSelection/types.tsx | 13 +++++---- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/Shared/API/APIQueuing.ts b/src/Shared/API/APIQueuing.ts index da6e73e42..7ad8b458c 100644 --- a/src/Shared/API/APIQueuing.ts +++ b/src/Shared/API/APIQueuing.ts @@ -54,10 +54,14 @@ const eachCall = (batchConfig, functionCalls, resolve, reject, shouldRejectOnErr */ const ApiQueuingWithBatch = ( functionCalls, - httpProtocol: string, shouldRejectOnError: boolean = false, batchSize: number = window._env_.API_BATCH_SIZE, ): Promise[]> => { + const httpProtocol = (window.performance.getEntriesByType('resource') as PerformanceResourceTiming[]).reduce( + (fallbackProtocol, entry) => entry.nextHopProtocol ?? fallbackProtocol, + 'http/1.0', + ) + if (!batchSize || batchSize <= 0) { // eslint-disable-next-line no-param-reassign batchSize = ['http/0.9', 'http/1.0', 'http/1.1'].indexOf(httpProtocol) !== -1 ? 5 : 30 diff --git a/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx b/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx index 38b563b05..7eb676797 100644 --- a/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx +++ b/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx @@ -30,7 +30,7 @@ import { UseBulkSelectionProps, UseBulkSelectionReturnType, } from './types' -import { CHECKBOX_VALUE, noop } from '../../../Common' +import { CHECKBOX_VALUE, noop, useEffectAfterMount } from '../../../Common' // giving type any here since not exporting this context, rather using it through useBulkSelection hook which is typed const BulkSelectionContext = createContext>({ @@ -39,6 +39,7 @@ const BulkSelectionContext = createContext>({ isChecked: false, checkboxValue: CHECKBOX_VALUE.CHECKED, isBulkSelectionApplied: false, + setIdentifiers: noop, getSelectedIdentifiersCount: noop, }) @@ -52,10 +53,17 @@ export const useBulkSelection = () => { export const BulkSelectionProvider = ({ children, - identifiers, + identifiers = null, getSelectAllDialogStatus, }: UseBulkSelectionProps) => { const [selectedIdentifiers, setSelectedIdentifiers] = useState({} as T) + const [identifiersOnCurrentPage, setIdentifiersOnCurrentPage] = useState(identifiers ?? ({} as T)) + + useEffectAfterMount(() => { + if (identifiers) { + setIdentifiersOnCurrentPage(identifiers) + } + }, [identifiers]) const isBulkSelectionApplied = selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR] @@ -96,7 +104,7 @@ export const BulkSelectionProvider = ({ variant: ToastVariantType.info, description: CLEAR_SELECTIONS_WARNING, }) - setIdentifiersAfterClear(identifiers, selectedIds) + setIdentifiersAfterClear(identifiersOnCurrentPage, selectedIds) break } @@ -137,7 +145,7 @@ export const BulkSelectionProvider = ({ }) } - setIdentifiersAfterPageSelection(identifiers) + setIdentifiersAfterPageSelection(identifiersOnCurrentPage) break } @@ -169,7 +177,7 @@ export const BulkSelectionProvider = ({ } // if all the identifiers are selected then CHECKED else intermediate - const areAllPresentIdentifiersSelected = Object.keys(identifiers).every( + const areAllPresentIdentifiersSelected = Object.keys(identifiersOnCurrentPage).every( (identifierId) => selectedIdentifiers[identifierId], ) @@ -196,8 +204,17 @@ export const BulkSelectionProvider = ({ checkboxValue, isBulkSelectionApplied, getSelectedIdentifiersCount, + setIdentifiers: setIdentifiersOnCurrentPage, }), - [selectedIdentifiers, handleBulkSelection, isChecked, checkboxValue, getSelectedIdentifiersCount], + [ + selectedIdentifiers, + handleBulkSelection, + isChecked, + checkboxValue, + getSelectedIdentifiersCount, + identifiersOnCurrentPage, + isBulkSelectionApplied, + ], ) return {children} diff --git a/src/Shared/Components/BulkSelection/types.tsx b/src/Shared/Components/BulkSelection/types.tsx index ad4145a54..38907f7c4 100644 --- a/src/Shared/Components/BulkSelection/types.tsx +++ b/src/Shared/Components/BulkSelection/types.tsx @@ -44,6 +44,7 @@ export interface UseBulkSelectionReturnType extends GetBulkSelectionCheckboxV handleBulkSelection: ({ action, data }: HandleBulkSelectionType) => void isBulkSelectionApplied: boolean getSelectedIdentifiersCount: () => number + setIdentifiers: React.Dispatch> } export interface BulkSelectionProps { @@ -72,14 +73,16 @@ export enum SelectAllDialogStatus { export type BulkSelectionIdentifiersType = Record export interface UseBulkSelectionProps { - /** - * Response from API, assuming structure to be array of objects with key and values - * This will the given ids on current page - */ - identifiers: T /** * Act as buffer between select all across pages and select all on page state */ getSelectAllDialogStatus: () => SelectAllDialogStatus + /** + * Response from API, assuming structure to be array of objects with key and values + * This will the given ids on current page. + * + * NOTE!: Please wrap this value with a useMemo since it goes into useEffect dependency + */ + identifiers?: T children?: React.ReactNode } From 4db542d5e01f3a953071a49cb953c4e47bd6ec40 Mon Sep 17 00:00:00 2001 From: Amrit Kashyap Borah Date: Thu, 24 Oct 2024 01:35:39 +0530 Subject: [PATCH 2/6] feat: add FEATURE_BULK_RESTART_WORKLOADS_FROM_RB env variable --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index a5464716a..4c133f060 100644 --- a/src/index.ts +++ b/src/index.ts @@ -86,6 +86,7 @@ export interface customEnv { FEATURE_PROMO_EMBEDDED_BUTTON_TEXT?: string FEATURE_PROMO_EMBEDDED_MODAL_TITLE?: string FEATURE_PROMO_EMBEDDED_IFRAME_URL?: string + FEATURE_BULK_RESTART_WORKLOADS_FROM_RB: string } declare global { interface Window { From 8bc41011c79def3e598ecefc41da437d3673df8d Mon Sep 17 00:00:00 2001 From: Amrit Kashyap Borah Date: Tue, 29 Oct 2024 14:01:56 +0530 Subject: [PATCH 3/6] chore: export utilities from security modal --- src/Common/Api.ts | 2 +- .../Security/SecurityModal/config/ImageScan.tsx | 10 +++++----- .../Components/Security/SecurityModal/config/index.ts | 1 + src/Shared/Components/Security/SecurityModal/index.ts | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Common/Api.ts b/src/Common/Api.ts index a657d208d..485d07f9c 100644 --- a/src/Common/Api.ts +++ b/src/Common/Api.ts @@ -264,4 +264,4 @@ export const abortPreviousRequests = ( */ export const getIsRequestAborted = (error) => // The 0 code is common for aborted and blocked requests - error && error.code === 0 && error.message.search('abort|aborted') + error && error.code === 0 && error.message.search('abort|aborted') > -1 diff --git a/src/Shared/Components/Security/SecurityModal/config/ImageScan.tsx b/src/Shared/Components/Security/SecurityModal/config/ImageScan.tsx index f02c6707c..e3c72c137 100644 --- a/src/Shared/Components/Security/SecurityModal/config/ImageScan.tsx +++ b/src/Shared/Components/Security/SecurityModal/config/ImageScan.tsx @@ -115,12 +115,12 @@ const getVulnerabilitiesDetailData = ( return getGroupedVulnerabilitiesDetailData(element, setDetailViewData, hidePolicy) } -const getImageScanProgressingState = (status: StatusType['status']) => { +export const getProgressingStateForStatus = (status: StatusType['status']) => { switch (status) { case 'Completed': - return + return case 'Failed': - return + return case 'Progressing': return ( - {getImageScanProgressingState(element.status)} + {getProgressingStateForStatus(element.status)} {getTimeString(element.StartedOn, element.status)} ), @@ -281,7 +281,7 @@ const getLicenseData = ( { component: (
- {getImageScanProgressingState(element.status)} + {getProgressingStateForStatus(element.status)} {getTimeString(element.StartedOn, element.status)}
), diff --git a/src/Shared/Components/Security/SecurityModal/config/index.ts b/src/Shared/Components/Security/SecurityModal/config/index.ts index d56e6560e..9c17605f8 100644 --- a/src/Shared/Components/Security/SecurityModal/config/index.ts +++ b/src/Shared/Components/Security/SecurityModal/config/index.ts @@ -5,3 +5,4 @@ export { getTableData } from './Table' export { getInfoCardData } from './InfoCard' export { SIDEBAR_DATA } from './Sidebar' +export { getProgressingStateForStatus } from './ImageScan' diff --git a/src/Shared/Components/Security/SecurityModal/index.ts b/src/Shared/Components/Security/SecurityModal/index.ts index 75f34a8e1..60cb58020 100644 --- a/src/Shared/Components/Security/SecurityModal/index.ts +++ b/src/Shared/Components/Security/SecurityModal/index.ts @@ -19,6 +19,6 @@ export type { GetResourceScanDetailsPayloadType, GetResourceScanDetailsResponseType, } from './types' -export { SIDEBAR_DATA } from './config' +export { SIDEBAR_DATA, getProgressingStateForStatus } from './config' export { CATEGORY_LABELS } from './constants' export { getExecutionDetails } from './service' From 59e3a15ef668db35ec6fd494fa77435f27f03d48 Mon Sep 17 00:00:00 2001 From: Amrit Kashyap Borah Date: Tue, 29 Oct 2024 14:03:34 +0530 Subject: [PATCH 4/6] chore: version bump --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4995bef46..e742241fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.6.5", + "version": "0.6.2-beta-4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.6.5", + "version": "0.6.2-beta-4", "license": "ISC", "dependencies": { "@types/react-dates": "^21.8.6", diff --git a/package.json b/package.json index 8b3b3cf5e..1438c1061 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.6.5", + "version": "0.6.2-beta-4", "description": "Supporting common component library", "type": "module", "main": "dist/index.js", From 305e1545a31fbc21d764f973cee1b6b1304cd6e7 Mon Sep 17 00:00:00 2001 From: Amrit Kashyap Borah Date: Tue, 5 Nov 2024 11:30:45 +0530 Subject: [PATCH 5/6] feat: add bulk operation related types --- .../ResourceBrowser/ResourceBrowser.Types.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts b/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts index 5e8a9218f..45f47b392 100644 --- a/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts +++ b/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts @@ -15,6 +15,7 @@ */ import { NodeType, Nodes } from '@Shared/types' +import { RefObject } from 'react' export interface GVKType { Group: string @@ -38,3 +39,31 @@ export interface K8SObjectBaseType { name: string isExpanded: boolean } + +export interface BulkSelectionActionWidgetProps { + count: number + handleOpenBulkDeleteModal: () => void + handleClearBulkSelection: () => void + handleOpenRestartWorkloadModal: () => void + parentRef: RefObject + showBulkRestartOption: boolean +} + +export interface BulkOperation { + name: string + namespace: string + operation: (signal: AbortSignal, data?: unknown) => Promise +} + +export interface BulkOperationModalProps { + operationType: 'restart' | 'delete' + clusterName: string + operations: NonNullable + handleModalClose: () => void + resourceKind: string + handleReloadDataAfterBulkOperation?: () => void + hideResultsDrawer?: boolean + removeTabByIdentifier?: (id: string) => Promise +} + +export type BulkOperationModalState = BulkOperationModalProps['operationType'] | 'closed' From 7a69120ab7d07332b257a33d9f4a2f85b5b7c158 Mon Sep 17 00:00:00 2001 From: Amrit Kashyap Borah Date: Tue, 5 Nov 2024 16:14:03 +0530 Subject: [PATCH 6/6] chore: remove unneeded props --- src/Pages/ResourceBrowser/ResourceBrowser.Types.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts b/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts index 45f47b392..8bd33acf4 100644 --- a/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts +++ b/src/Pages/ResourceBrowser/ResourceBrowser.Types.ts @@ -51,11 +51,10 @@ export interface BulkSelectionActionWidgetProps { export interface BulkOperation { name: string - namespace: string operation: (signal: AbortSignal, data?: unknown) => Promise } -export interface BulkOperationModalProps { +export type BulkOperationModalProps = { operationType: 'restart' | 'delete' clusterName: string operations: NonNullable @@ -63,7 +62,7 @@ export interface BulkOperationModalProps { resourceKind: string handleReloadDataAfterBulkOperation?: () => void hideResultsDrawer?: boolean - removeTabByIdentifier?: (id: string) => Promise + shouldAllowForceOperation?: true } export type BulkOperationModalState = BulkOperationModalProps['operationType'] | 'closed'