Skip to content

Commit d3d92dd

Browse files
committed
Merge branch 'main' into feat/adv-base-template-gui
2 parents 257f25b + fbcc23a commit d3d92dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+731
-39
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ src/Common/DebouncedSearch/__tests__/DebouncedSearch.test.tsx
3030
src/Common/DeleteComponentModal/DeleteComponent.tsx
3131
src/Common/DevtronProgressing/DevtronProgressing.tsx
3232
src/Common/Dialogs/ConfirmationDialog.tsx
33-
src/Common/Dialogs/DeleteDialog.tsx
3433
src/Common/Dialogs/DialogForm.tsx
3534
src/Common/Dialogs/ForceDeleteDialog.tsx
3635
src/Common/DraggableWrapper/DraggableButton.tsx

.eslintrc.cjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = {
9292
'react/react-in-jsx-scope': 'off',
9393
// additional rules:
9494
'@typescript-eslint/no-floating-promises': 'error',
95-
"import/prefer-default-export": "off",
95+
'import/prefer-default-export': 'off',
9696
'import/extensions': [
9797
'warn',
9898
'ignorePackages',
@@ -103,6 +103,7 @@ module.exports = {
103103
tsx: 'never',
104104
},
105105
],
106+
'no-restricted-exports': 'off',
106107
},
107108
overrides: [
108109
{
@@ -124,4 +125,4 @@ module.exports = {
124125
},
125126
},
126127
ignorePatterns: [".eslintrc.cjs", "vite.config.ts"],
127-
}
128+
}

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- synchronize
88
- edited
99
- reopened
10+
- ready_for_review
1011

1112
jobs:
1213
ci:

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.0.91-beta-1",
3+
"version": "0.0.91-beta-2",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -23,12 +23,12 @@
2323
],
2424
"scripts": {
2525
"prepare": "node -e \"try { require('husky').install() } catch (e) {}\"",
26-
"lint": "tsc --noEmit && eslint 'src/**/*.{js,jsx,ts,tsx}' --max-warnings 0",
26+
"lint": "tsc --noEmit && NODE_OPTIONS=--max_old_space_size=8192 eslint 'src/**/*.{js,jsx,ts,tsx}' --max-warnings 0",
2727
"lint-fix": "eslint 'src/**/*.{js,jsx,ts,tsx}' --fix",
2828
"test": "exit 0",
29-
"dev": "vite",
30-
"build": "vite build --sourcemap",
31-
"build-watch": "vite build --sourcemap --watch",
29+
"dev": "NODE_OPTIONS=--max_old_space_size=8192 vite",
30+
"build": "NODE_OPTIONS=--max_old_space_size=8192 vite build --sourcemap",
31+
"build-watch": "NODE_OPTIONS=--max_old_space_size=8192 vite build --sourcemap --watch",
3232
"build-lib": "vite build",
3333
"preview": "vite preview",
3434
"lint-staged": "lint-staged"
Lines changed: 3 additions & 0 deletions
Loading

src/Common/Dialogs/DeleteDialog.tsx

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,30 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React from 'react'
17+
import React, { ChangeEvent, useState } from 'react'
1818
import warn from '../../Assets/Img/delete-medium.svg'
1919
import { Progressing } from '../Progressing'
2020
import ConfirmationDialog from './ConfirmationDialog'
2121
import { DeleteDialogProps } from './Types'
22+
import { CustomInput } from '../CustomInput'
23+
24+
export const DeleteDialog: React.FC<DeleteDialogProps> & { Description?: React.FC<any> } = ({
25+
showDeleteConfirmation: _showDeleteConfirmation,
26+
deleteConfirmationText = null,
27+
...props
28+
}: DeleteDialogProps) => {
29+
const [confirmationText, setConfirmationText] = useState('')
30+
31+
const showDeleteConfirmation = _showDeleteConfirmation && !!deleteConfirmationText
32+
const isDeleteDisabled =
33+
props.apiCallInProgress ||
34+
props.disabled ||
35+
(showDeleteConfirmation && deleteConfirmationText !== confirmationText)
36+
37+
const handleConfirmationTextChange = (e: ChangeEvent<HTMLInputElement>) => {
38+
setConfirmationText(e.target.value)
39+
}
2240

23-
export const DeleteDialog: React.FC<DeleteDialogProps> & { Description?: React.FC<any> } = (props) => {
2441
const handleDelete = (e: React.MouseEvent) => {
2542
if (props.shouldStopPropagation) {
2643
e.stopPropagation()
@@ -29,6 +46,18 @@ export const DeleteDialog: React.FC<DeleteDialogProps> & { Description?: React.F
2946
props.delete()
3047
}
3148

49+
const handleKeyDown = (event: KeyboardEvent) => {
50+
if (event.key === 'Enter' && !isDeleteDisabled) {
51+
event.preventDefault()
52+
53+
if (props.shouldStopPropagation) {
54+
event.stopPropagation()
55+
}
56+
57+
props.delete()
58+
}
59+
}
60+
3261
const handleModalClose = (e: React.MouseEvent) => {
3362
if (props.shouldStopPropagation) {
3463
e.stopPropagation()
@@ -37,13 +66,34 @@ export const DeleteDialog: React.FC<DeleteDialogProps> & { Description?: React.F
3766
props.closeDelete()
3867
}
3968

69+
const getLabel = () => (
70+
<span>
71+
Type
72+
<span className="fw-6 dc__word-break">&nbsp;&apos;{deleteConfirmationText}&apos;&nbsp;</span>
73+
to confirm
74+
</span>
75+
)
76+
4077
return (
4178
<ConfirmationDialog className="confirmation-dialog__body--w-400">
4279
<ConfirmationDialog.Icon src={warn} />
4380
<ConfirmationDialog.Body title={props.title}>
4481
<div className="fs-13 cn-7 lh-1-54 w-100">
4582
{props.description ? props.description : null}
4683
{props.children}
84+
{showDeleteConfirmation && (
85+
<CustomInput
86+
name="delete-confirmation"
87+
value={confirmationText}
88+
onChange={handleConfirmationTextChange}
89+
label={getLabel()}
90+
inputWrapClassName="mt-12 w-100"
91+
placeholder={`Type ${deleteConfirmationText} to confirm`}
92+
isRequiredField
93+
onKeyDown={handleKeyDown}
94+
autoFocus
95+
/>
96+
)}
4797
</div>
4898
</ConfirmationDialog.Body>
4999
<ConfirmationDialog.ButtonGroup>
@@ -61,7 +111,7 @@ export const DeleteDialog: React.FC<DeleteDialogProps> & { Description?: React.F
61111
type="button"
62112
className="cta delete cta-cd-delete-modal ml-16"
63113
onClick={handleDelete}
64-
disabled={props.apiCallInProgress || props.disabled}
114+
disabled={isDeleteDisabled}
65115
data-testid="dialog-delete"
66116
>
67117
{props.apiCallInProgress ? (
@@ -78,6 +128,7 @@ export const DeleteDialog: React.FC<DeleteDialogProps> & { Description?: React.F
78128
)
79129
}
80130

81-
const DeleteDialogDescription = (props) => <>{props.children}</>
131+
// eslint-disable-next-line react/jsx-no-useless-fragment
132+
const DeleteDialogDescription = ({ children }: Pick<DeleteDialogProps, 'children'>) => <>{children}</>
82133

83134
DeleteDialog.Description = DeleteDialogDescription

src/Common/Dialogs/Types.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@
1616

1717
import { ReactNode } from 'react'
1818

19-
export interface DeleteDialogProps {
19+
type WithOrWithoutDeleteConfirmationType =
20+
| {
21+
showDeleteConfirmation: true
22+
/**
23+
* If added, confirmation input is shown
24+
*/
25+
deleteConfirmationText: string
26+
}
27+
| {
28+
showDeleteConfirmation?: never
29+
/**
30+
* If added, confirmation input is shown
31+
*/
32+
deleteConfirmationText?: never
33+
}
34+
35+
export type DeleteDialogProps = {
2036
title: string
2137
description?: string
2238
closeDelete: () => void
@@ -28,7 +44,8 @@ export interface DeleteDialogProps {
2844
buttonPrimaryText?: string
2945
shouldStopPropagation?: boolean
3046
disabled?: boolean
31-
}
47+
children?: ReactNode
48+
} & WithOrWithoutDeleteConfirmationType
3249

3350
export interface ForceDeleteDialogType {
3451
onClickDelete: () => void

src/Common/EmptyState/GenericFilterEmptyState.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,37 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { GenericEmptyStateType } from '../Types'
1817
import noResult from '../../Assets/Img/empty-noresult@2x.png'
1918
import GenericEmptyState from './GenericEmptyState'
19+
import { GenericFilterEmptyStateProps } from './types'
2020

21-
const GenericFilterEmptyState = (
22-
props: Omit<GenericEmptyStateType, 'image' | 'title' | 'subTitle'> &
23-
Partial<Pick<GenericEmptyStateType, 'title' | 'subTitle'>>,
24-
) => (
25-
<GenericEmptyState
26-
image={noResult}
27-
title="No results"
28-
subTitle="We couldn’t find any matching results"
29-
{...props}
30-
/>
31-
)
21+
/**
22+
* Empty state when no filters are applied
23+
*/
24+
const GenericFilterEmptyState = ({
25+
handleClearFilters,
26+
isButtonAvailable,
27+
renderButton,
28+
...props
29+
}: GenericFilterEmptyStateProps) => {
30+
const isClearFilterButtonAvailable = !!handleClearFilters
31+
32+
const renderClearFilterButton = () => (
33+
<button type="button" onClick={handleClearFilters} className="cta secondary flex h-32 lh-20-imp">
34+
Clear Filters
35+
</button>
36+
)
37+
38+
return (
39+
<GenericEmptyState
40+
image={noResult}
41+
title="No results"
42+
subTitle="We couldn’t find any matching results"
43+
{...props}
44+
isButtonAvailable={isClearFilterButtonAvailable || isButtonAvailable}
45+
renderButton={isClearFilterButtonAvailable ? renderClearFilterButton : renderButton}
46+
/>
47+
)
48+
}
3249

3350
export default GenericFilterEmptyState

src/Common/EmptyState/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { GenericEmptyStateType } from '../Types'
2+
3+
export type GenericFilterEmptyStateProps = Omit<
4+
GenericEmptyStateType,
5+
'image' | 'title' | 'subTitle' | 'isButtonAvailable' | 'renderButton'
6+
> &
7+
Partial<Pick<GenericEmptyStateType, 'title' | 'subTitle'>> &
8+
(
9+
| {
10+
/**
11+
* If provided, it will have priority over the isButtonAvailable prop
12+
* and render clear filter button
13+
*/
14+
handleClearFilters?: () => void
15+
isButtonAvailable?: never
16+
renderButton?: never
17+
}
18+
| (Pick<GenericEmptyStateType, 'isButtonAvailable' | 'renderButton'> & {
19+
handleClearFilters?: never
20+
})
21+
)

0 commit comments

Comments
 (0)