Skip to content

Commit c96156b

Browse files
committed
feat: accomodate renderContentAtResultRowEnd in bulk operations results modal
1 parent 978d01d commit c96156b

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

src/Shared/Components/BulkOperations/BulkOperations.component.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const BulkOperations = ({
6565
}
6666

6767
const calls = operationsRef.current.map((op) => async () => {
68-
const { operation, name, additionalKeys } = op
68+
const { operation, name, additionalKeys, renderContentAtResultRowEnd = null } = op
6969

7070
if (abortControllerRef.current.signal.aborted) {
7171
throw new Error('bulk operations aborted')
@@ -83,9 +83,16 @@ const BulkOperations = ({
8383

8484
triggerUpdate()
8585

86-
await operation(abortControllerRef, data)
86+
const result = await operation(abortControllerRef, data)
8787

88-
resultsStoreRef.current.updateResultStatus(id, { status: 'Completed' })
88+
resultsStoreRef.current.updateResultStatus(id, {
89+
status: 'Completed',
90+
...(renderContentAtResultRowEnd
91+
? {
92+
renderContentAtResultRowEnd: () => renderContentAtResultRowEnd(result),
93+
}
94+
: {}),
95+
})
8996

9097
triggerUpdate()
9198
} catch (err) {

src/Shared/Components/BulkOperations/BulkOperationsResultModal.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ const BulkOperationsResultModal = ({
159159
{sortedList.map((result, index, arr) => (
160160
<div
161161
className={`dc__grid py-10 fs-13 dc__gap-16 dc__align-items-start ${index === arr.length - 1 ? 'mb-20' : ''}`}
162-
style={{ gridTemplateColumns }}
162+
style={{
163+
gridTemplateColumns: result.renderContentAtResultRowEnd
164+
? `${gridTemplateColumns} min-content`
165+
: gridTemplateColumns,
166+
}}
163167
key={result.id}
164168
>
165169
<Tooltip content={result.name}>
@@ -179,6 +183,8 @@ const BulkOperationsResultModal = ({
179183
</div>
180184

181185
<span className="dc__word-break">{result.message}</span>
186+
187+
{result.renderContentAtResultRowEnd?.()}
182188
</div>
183189
))}
184190
</div>

src/Shared/Components/BulkOperations/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ interface BulkOperationAdditionalKeysType {
1717
export interface BulkOperation {
1818
name: string
1919
/**
20-
* Would these keys beside the name
20+
* Would show these keys beside the name
2121
*/
2222
additionalKeys?: BulkOperationAdditionalKeysType[]
23-
operation: (abortControllerRef: MutableRefObject<AbortController>, data?: unknown) => Promise<void>
23+
operation: (abortControllerRef: MutableRefObject<AbortController>, data?: unknown) => Promise<unknown | void>
24+
renderContentAtResultRowEnd?: (data: Awaited<ReturnType<BulkOperation['operation']>>) => ReactNode
2425
}
2526

2627
export type FailedOperationType = {
@@ -34,6 +35,7 @@ export type OtherStatusOperationType = {
3435

3536
export type BulkOperationResultType = {
3637
message?: string
38+
renderContentAtResultRowEnd?: () => void
3739
} & (FailedOperationType | OtherStatusOperationType) &
3840
Pick<BulkOperation, 'name' | 'additionalKeys'>
3941

@@ -49,7 +51,8 @@ export interface OperationResultStoreType {
4951
getSize: () => number
5052
updateResultStatus: (
5153
id: number,
52-
result: Partial<Pick<BulkOperationResultType, 'message'>> & (FailedOperationType | OtherStatusOperationType),
54+
result: Partial<Pick<BulkOperationResultType, 'message' | 'renderContentAtResultRowEnd'>> &
55+
(FailedOperationType | OtherStatusOperationType),
5356
) => void
5457
getRetryOperations: () => FailedOperationType['retryOperation'][]
5558
hasAnyOperationFailed: () => boolean

src/Shared/Hooks/UseDownload/UseDownload.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import { ServerErrors } from '@Common/ServerError'
2121
import { getFileNameFromHeaders } from '@Shared/Helpers'
2222
import { ToastManager, ToastVariantType } from '@Shared/Services'
2323
import { getDownloadResponse } from './service'
24-
import { HandleDownloadProps } from './types'
24+
import { UseDownloadReturnType } from './types'
2525

26-
const useDownload = () => {
26+
const useDownload = (): UseDownloadReturnType => {
2727
const [isDownloading, setIsDownloading] = useState<boolean>(false)
2828

2929
/**
@@ -33,13 +33,13 @@ const useDownload = () => {
3333
* @param showSuccessfulToast - show toast on successful download
3434
* @param downloadSuccessToastContent - Content to show in toast on successful download
3535
*/
36-
const handleDownload = async ({
36+
const handleDownload: UseDownloadReturnType['handleDownload'] = async ({
3737
downloadUrl,
3838
showFilePreparingToast = false,
3939
fileName,
4040
showSuccessfulToast = true,
4141
downloadSuccessToastContent = 'Downloaded Successfully',
42-
}: HandleDownloadProps): Promise<Error | ServerErrors> => {
42+
}) => {
4343
setIsDownloading(true)
4444
try {
4545
const response = await getDownloadResponse(downloadUrl)

src/Shared/Hooks/UseDownload/types.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { ServerErrors } from '@Common/ServerError'
18+
1719
export interface HandleDownloadProps {
1820
downloadUrl: string
1921
showFilePreparingToast?: boolean
2022
fileName?: string
2123
showSuccessfulToast?: boolean
2224
downloadSuccessToastContent?: string
2325
}
26+
27+
export interface UseDownloadReturnType {
28+
handleDownload: (props: HandleDownloadProps) => Promise<Error | ServerErrors>
29+
isDownloading: boolean
30+
}

0 commit comments

Comments
 (0)