Skip to content

Commit ea88f80

Browse files
committed
fix: DynamicDataTable - error showing if validation is not passed fix, feat: FileUpload - loading state add, code refactor
1 parent 426c5ca commit ea88f80

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

src/Common/Common.service.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import moment from 'moment'
1919
import { RuntimeParamsAPIResponseType, RuntimeParamsListItemType } from '@Shared/types'
2020
import { getIsManualApprovalSpecific, sanitizeUserApprovalConfig, stringComparatorBySortOrder } from '@Shared/Helpers'
2121
import { get, getIsRequestAborted, post } from './Api'
22-
import { GitProviderType, ROUTES } from './Constants'
22+
import { API_STATUS_CODES, GitProviderType, ROUTES } from './Constants'
2323
import { getUrlWithSearchParams, showError, sortCallback } from './Helper'
2424
import {
2525
TeamList,
@@ -547,13 +547,16 @@ export const getGlobalVariables = async ({
547547
abortControllerRef?: MutableRefObject<AbortController>
548548
}): Promise<GlobalVariableOptionType[]> => {
549549
try {
550-
const { result } = await get<GlobalVariableDTO[]>(`${ROUTES.PLUGIN_GLOBAL_VARIABLES}?appId=${appId}`, {
551-
abortControllerRef,
552-
})
550+
const { result } = await get<GlobalVariableDTO[]>(
551+
getUrlWithSearchParams(ROUTES.PLUGIN_GLOBAL_VARIABLES, { appId }),
552+
{
553+
abortControllerRef,
554+
},
555+
)
553556
const variableList = (result ?? [])
554557
.filter((item) => (isCD ? item.stageType !== 'ci' : item.stageType === 'ci'))
555558
.map((variable) => {
556-
const { name, ...updatedVariable } = { ...variable }
559+
const { name, ...updatedVariable } = variable
557560

558561
return {
559562
...updatedVariable,
@@ -567,7 +570,7 @@ export const getGlobalVariables = async ({
567570
return variableList
568571
} catch (err) {
569572
if (!getIsRequestAborted(err)) {
570-
if (err instanceof ServerErrors && err.code === 403) {
573+
if (err instanceof ServerErrors && err.code === API_STATUS_CODES.PERMISSION_DENIED) {
571574
ToastManager.showToast({
572575
variant: ToastVariantType.notAuthorized,
573576
description: 'You are not authorized to access global variables',

src/Common/TippyCustomized.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
4343
}
4444

4545
const closeTippy = (e) => {
46-
stopPropagation(e)
4746
if (!props.disableClose) {
47+
stopPropagation(e)
4848
if (tippyRef.current?.hide) {
4949
tippyRef.current.hide()
5050
tippyRef.current = null

src/Shared/Components/DynamicDataTable/DynamicDataTableRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export const DynamicDataTableRow = <K extends string, CustomStateType = Record<s
254254

255255
const renderCell = (row: DynamicDataTableRowType<K, CustomStateType>, key: K, index: number) => {
256256
const isDisabled = readOnly || row.data[key].disabled || false
257+
const hasError = !(cellError[row.id]?.[key]?.isValid ?? true)
257258

258259
const cellNode = (
259260
<Tooltip
@@ -264,7 +265,7 @@ export const DynamicDataTableRow = <K extends string, CustomStateType = Record<s
264265
plugins={[followCursor]}
265266
>
266267
<div
267-
className={`dynamic-data-table__cell bcn-0 flexbox dc__align-items-center dc__gap-4 dc__position-rel ${isDisabled ? 'cursor-not-allowed no-hover' : ''} ${!isDisabled && !cellError[row.id]?.[key]?.isValid ? 'dynamic-data-table__cell--error no-hover' : ''} ${!rowTypeHasInputField(row.data[key].type) ? 'no-hover no-focus' : ''}`}
268+
className={`dynamic-data-table__cell bcn-0 flexbox dc__align-items-center dc__gap-4 dc__position-rel ${isDisabled ? 'cursor-not-allowed no-hover' : ''} ${!isDisabled && hasError ? 'dynamic-data-table__cell--error no-hover' : ''} ${!rowTypeHasInputField(row.data[key].type) ? 'no-hover no-focus' : ''}`}
268269
>
269270
{renderCellIcon(row, key, true)}
270271
{renderCellContent(row, key)}

src/Shared/Components/FileUpload/FileUpload.tsx

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ import { ReactComponent as ICCloudUpload } from '@Icons/ic-cloud-upload.svg'
44
import { ReactComponent as ICCross } from '@Icons/ic-cross.svg'
55
import { Tooltip } from '@Common/Tooltip'
66

7+
import { Progressing } from '@Common/Progressing'
78
import { FileUploadProps } from './types'
89

9-
export const FileUpload = ({ label, fileName = '', multiple = false, fileTypes = [], onUpload }: FileUploadProps) => {
10+
export const FileUpload = ({
11+
isLoading,
12+
label,
13+
fileName = '',
14+
multiple = false,
15+
fileTypes = [],
16+
onUpload,
17+
}: FileUploadProps) => {
1018
// METHODS
1119
const handleFileChange = (event: ChangeEvent<HTMLInputElement>) => {
1220
if (event.target.files) {
@@ -24,17 +32,32 @@ export const FileUpload = ({ label, fileName = '', multiple = false, fileTypes =
2432

2533
return (
2634
<div className="mw-none">
27-
{fileName ? (
35+
{isLoading || fileName ? (
2836
<div className="dc__border br-4 dc__overflow-hidden flexbox">
2937
<div className="flexbox dc__align-items-center dc__gap-8 px-8 py-4 mw-none">
30-
<ICCloudUpload className="icon-dim-16 dc__no-shrink" />
31-
<Tooltip content={fileName}>
32-
<span className="fs-12 lh-20 dc__ellipsis-right">{fileName}</span>
33-
</Tooltip>
38+
{isLoading ? (
39+
<>
40+
<Progressing size={16} />
41+
<span className="fs-12 lh-20">Uploading...</span>
42+
</>
43+
) : (
44+
<>
45+
<ICCloudUpload className="icon-dim-16 dc__no-shrink" />
46+
<Tooltip content={fileName}>
47+
<span className="fs-12 lh-20 dc__ellipsis-right">{fileName}</span>
48+
</Tooltip>
49+
</>
50+
)}
3451
</div>
35-
<button type="button" className="dc__transparent flex p-6 dc__hover-n50" onClick={onClearUpload}>
36-
<ICCross className="icon-dim-16 fcn-6" />
37-
</button>
52+
{!isLoading && (
53+
<button
54+
type="button"
55+
className="dc__transparent flex p-6 dc__hover-n50"
56+
onClick={onClearUpload}
57+
>
58+
<ICCross className="icon-dim-16 fcn-6" />
59+
</button>
60+
)}
3861
</div>
3962
) : (
4063
<div className="dc__position-rel flex">

src/Shared/Components/FileUpload/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface FileUploadProps {
2+
isLoading?: boolean
23
fileName: string
34
onUpload: (files: File[]) => void
45
multiple?: boolean

0 commit comments

Comments
 (0)