@devtron-labs/devtron-fe-common-lib 0.0.51 → 0.0.52-beta-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/Common/Constants.d.ts +5 -0
  2. package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
  3. package/dist/Common/CustomInput/Types.d.ts +1 -0
  4. package/dist/Common/DraggableWrapper/DraggableButton.d.ts +3 -0
  5. package/dist/Common/DraggableWrapper/DraggableWrapper.d.ts +9 -0
  6. package/dist/Common/DraggableWrapper/index.d.ts +3 -0
  7. package/dist/Common/DraggableWrapper/types.d.ts +23 -0
  8. package/dist/Common/EmptyState/GenericEmptyState.d.ts +1 -1
  9. package/dist/Common/Grid/Grid.d.ts +1 -1
  10. package/dist/Common/Grid/types.d.ts +2 -2
  11. package/dist/Common/Hooks/UseWindowSize/UseWindowSize.d.ts +4 -0
  12. package/dist/Common/Hooks/index.d.ts +1 -0
  13. package/dist/Common/Types.d.ts +1 -0
  14. package/dist/Common/index.d.ts +1 -0
  15. package/dist/index.js +286 -140
  16. package/package.json +3 -2
  17. package/src/Assets/Icon/ic-drag.svg +8 -0
  18. package/src/Common/Constants.ts +7 -1
  19. package/src/Common/CustomInput/CustomInput.tsx +3 -2
  20. package/src/Common/CustomInput/Types.ts +1 -0
  21. package/src/Common/DraggableWrapper/DraggableButton.tsx +14 -0
  22. package/src/Common/DraggableWrapper/DraggableWrapper.tsx +116 -0
  23. package/src/Common/DraggableWrapper/index.ts +3 -0
  24. package/src/Common/DraggableWrapper/types.ts +27 -0
  25. package/src/Common/EmptyState/GenericEmptyState.tsx +45 -13
  26. package/src/Common/Grid/Grid.tsx +7 -2
  27. package/src/Common/Grid/types.ts +3 -1
  28. package/src/Common/Hooks/UseWindowSize/UseWindowSize.tsx +31 -0
  29. package/src/Common/Hooks/index.ts +1 -0
  30. package/src/Common/Types.ts +1 -0
  31. package/src/Common/index.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.51",
3
+ "version": "0.0.52-beta-2",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -47,7 +47,8 @@
47
47
  "react": "^17.0.2",
48
48
  "react-dom": "^17.0.2",
49
49
  "react-router": "^5.3.0",
50
- "react-router-dom": "^5.3.0"
50
+ "react-router-dom": "^5.3.0",
51
+ "react-draggable": "^4.4.5"
51
52
  },
52
53
  "dependencies": {
53
54
  "fast-json-patch": "^3.1.1",
@@ -0,0 +1,8 @@
1
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M10.3335 9.33325C10.8858 9.33325 11.3335 8.88554 11.3335 8.33325C11.3335 7.78097 10.8858 7.33325 10.3335 7.33325C9.78121 7.33325 9.3335 7.78097 9.3335 8.33325C9.3335 8.88554 9.78121 9.33325 10.3335 9.33325Z" fill="#596168"/>
3
+ <path d="M5.66675 9.33325C6.21903 9.33325 6.66675 8.88554 6.66675 8.33325C6.66675 7.78097 6.21903 7.33325 5.66675 7.33325C5.11446 7.33325 4.66675 7.78097 4.66675 8.33325C4.66675 8.88554 5.11446 9.33325 5.66675 9.33325Z" fill="#596168"/>
4
+ <path d="M10.3335 5.33325C10.8858 5.33325 11.3335 4.88554 11.3335 4.33325C11.3335 3.78097 10.8858 3.33325 10.3335 3.33325C9.78121 3.33325 9.3335 3.78097 9.3335 4.33325C9.3335 4.88554 9.78121 5.33325 10.3335 5.33325Z" fill="#596168"/>
5
+ <path d="M5.66675 5.33325C6.21903 5.33325 6.66675 4.88554 6.66675 4.33325C6.66675 3.78097 6.21903 3.33325 5.66675 3.33325C5.11446 3.33325 4.66675 3.78097 4.66675 4.33325C4.66675 4.88554 5.11446 5.33325 5.66675 5.33325Z" fill="#596168"/>
6
+ <path d="M10.3335 13.3333C10.8858 13.3333 11.3335 12.8855 11.3335 12.3333C11.3335 11.781 10.8858 11.3333 10.3335 11.3333C9.78121 11.3333 9.3335 11.781 9.3335 12.3333C9.3335 12.8855 9.78121 13.3333 10.3335 13.3333Z" fill="#596168"/>
7
+ <path d="M5.66675 13.3333C6.21903 13.3333 6.66675 12.8855 6.66675 12.3333C6.66675 11.781 6.21903 11.3333 5.66675 11.3333C5.11446 11.3333 4.66675 11.781 4.66675 12.3333C4.66675 12.8855 5.11446 13.3333 5.66675 13.3333Z" fill="#596168"/>
8
+ </svg>
@@ -240,4 +240,10 @@ export const RepositoryAction = {
240
240
  CONTAINER: "CONTAINER",
241
241
  CHART_PULL: "CHART_PULL",
242
242
  CHART_PUSH: "CHART_PUSH"
243
- }
243
+ }
244
+
245
+ export enum APPROVAL_MODAL_TYPE {
246
+ CONFIG = 'CONFIG',
247
+ DEPLOYMENT = 'DEPLOYMENT',
248
+ }
249
+ export const MAX_Z_INDEX = 2147483647
@@ -28,7 +28,8 @@ export function CustomInput({
28
28
  defaultValue,
29
29
  onKeyDown,
30
30
  required,
31
- additionalErrorInfo
31
+ additionalErrorInfo,
32
+ inputWrapClassName = '',
32
33
  }: CustomInputProps) {
33
34
 
34
35
  function handleError(error: any): any[] {
@@ -92,7 +93,7 @@ export function CustomInput({
92
93
  }
93
94
 
94
95
  return (
95
- <div className="flex column left top">
96
+ <div className={`flex column left top ${inputWrapClassName}`}>
96
97
  {renderInputLabel()}
97
98
  <input
98
99
  data-testid={dataTestid}
@@ -27,4 +27,5 @@ export interface CustomInputProps {
27
27
  onKeyDown?: (e) => void
28
28
  required?: boolean
29
29
  additionalErrorInfo?: React.ReactNode
30
+ inputWrapClassName?: string
30
31
  }
@@ -0,0 +1,14 @@
1
+ import React from 'react'
2
+ import { ReactComponent as ICDrag } from '../../Assets/Icon/ic-drag.svg'
3
+ import { DraggableButtonProps } from './types'
4
+
5
+ export default function DraggableButton({ dragClassName }: DraggableButtonProps) {
6
+ return (
7
+ <button
8
+ type="button"
9
+ className={`${dragClassName} dc__outline-none-imp dc__no-border p-0 dc__transparent h-20`}
10
+ >
11
+ <ICDrag className="dc__grabbable icon-dim-20 fcn-6" />
12
+ </button>
13
+ )
14
+ }
@@ -0,0 +1,116 @@
1
+ import React, { useEffect, useRef, useState } from 'react'
2
+ import Draggable, { ControlPosition, DraggableData } from 'react-draggable'
3
+ import { DraggableWrapperProps, DraggablePositionVariant } from './types'
4
+ import { useWindowSize } from '../Hooks'
5
+ import { MAX_Z_INDEX } from '../Constants'
6
+
7
+ /**
8
+ * TODO: import it as lazy, after it is supported in common
9
+ * 1. If using react select please use menuPlacement='auto'
10
+ * 2. dragSelector will be used to identify the grabbable button that will grab the div to drag
11
+ * 3. parentRef is the reference point from which we will derive the base top:0 ,left: 0 position
12
+ */
13
+ export default function DraggableWrapper({
14
+ children,
15
+ zIndex = MAX_Z_INDEX,
16
+ positionVariant,
17
+ dragSelector,
18
+ parentRef,
19
+ boundaryGap = 16,
20
+ childDivProps = {},
21
+ }: DraggableWrapperProps) {
22
+ const windowSize = useWindowSize()
23
+ const nodeRef = useRef<HTMLDivElement>(null)
24
+
25
+ const [position, setPosition] = useState<ControlPosition>({
26
+ x: 0,
27
+ y: 0,
28
+ })
29
+
30
+ const getDefaultPosition = (positionVariant: DraggablePositionVariant): ControlPosition => {
31
+ // if this return x: 0, y: 0 then it will be top left corner of parentDiv
32
+ const parentRect =
33
+ parentRef?.current?.getBoundingClientRect() ??
34
+ ({
35
+ width: 0,
36
+ height: 0,
37
+ top: 0,
38
+ left: 0,
39
+ bottom: 0,
40
+ } as DOMRect)
41
+ const nodeRefHeight = nodeRef.current?.getBoundingClientRect().height ?? 0
42
+ const nodeRefWidth = nodeRef.current?.getBoundingClientRect().width ?? 0
43
+
44
+ switch (positionVariant) {
45
+ case DraggablePositionVariant.PARENT_BOTTOM_CENTER: {
46
+ // currently at parentRect.x and need to start to the center of its width and half of node should lie on left of center and other half on right
47
+ const x = (parentRect.width - nodeRefWidth) / 2
48
+ // currently at parentRect.y now parent height can be greater than windowSize.height so taking min
49
+ // subtracting parentRect.top since window height already contains that
50
+ const baseY =
51
+ parentRect.height > windowSize.height ? windowSize.height - parentRect.top : parentRect.height
52
+ const y = baseY - nodeRefHeight - boundaryGap
53
+ return { x, y }
54
+ }
55
+ // Add more cases for other variants if needed
56
+ default: {
57
+ // Since need node to be in center of screen so subtracting width/2 by left of parentRect it will start the node from center but want node's midpoint at center so subtracting node's width from it.
58
+ const x = windowSize.width / 2 - parentRect.left - nodeRefWidth / 2
59
+ // subtracting top since windowSize already contains that
60
+ const y = windowSize.height - parentRect.top - nodeRefHeight - boundaryGap
61
+
62
+ return { x, y }
63
+ }
64
+ }
65
+ }
66
+
67
+ // On change of windowSize we will reset the position to default
68
+ useEffect(() => {
69
+ const defaultPosition = getDefaultPosition(positionVariant)
70
+ setPosition(defaultPosition)
71
+ }, [nodeRef, positionVariant, windowSize])
72
+
73
+ // Would be called on drag and will not update the state if the new position is out of window screen
74
+ function handlePositionChange(e, data: DraggableData) {
75
+ const offsetX = parentRef?.current?.getBoundingClientRect().left ?? 0
76
+ const offsetY = parentRef?.current?.getBoundingClientRect().top ?? 0
77
+
78
+ const nodeRefHeight = nodeRef.current?.getBoundingClientRect().height ?? 0
79
+ const nodeRefWidth = nodeRef.current?.getBoundingClientRect().width ?? 0
80
+
81
+ if (
82
+ offsetX + data.x + nodeRefWidth + boundaryGap > windowSize.width ||
83
+ offsetY + data.y + nodeRefHeight + boundaryGap > windowSize.height ||
84
+ offsetX + data.x < 0 ||
85
+ offsetY + data.y < 0
86
+ ) {
87
+ return
88
+ }
89
+
90
+ setPosition({
91
+ x: data.x,
92
+ y: data.y,
93
+ })
94
+ }
95
+
96
+ return (
97
+ <div
98
+ className="dc__position-fixed"
99
+ style={{
100
+ zIndex,
101
+ }}
102
+ >
103
+ <Draggable handle={dragSelector} nodeRef={nodeRef} position={position} onDrag={handlePositionChange}>
104
+ <div
105
+ ref={nodeRef}
106
+ {...childDivProps}
107
+ style={{
108
+ zIndex,
109
+ }}
110
+ >
111
+ {children}
112
+ </div>
113
+ </Draggable>
114
+ </div>
115
+ )
116
+ }
@@ -0,0 +1,3 @@
1
+ export { default as DraggableWrapper } from './DraggableWrapper'
2
+ export { default as DraggableButton } from './DraggableButton'
3
+ export * from './types'
@@ -0,0 +1,27 @@
1
+ import { HTMLAttributes, ReactNode, RefObject } from 'react'
2
+
3
+ export enum DraggablePositionVariant {
4
+ PARENT_BOTTOM_CENTER = 'PARENT_BOTTOM_CENTER',
5
+ SCREEN_BOTTOM_CENTER = 'SCREEN_BOTTOM_CENTER',
6
+ // Can add more based on requirement
7
+ }
8
+
9
+ export interface DraggableWrapperProps {
10
+ children: ReactNode
11
+ zIndex?: number
12
+ positionVariant?: DraggablePositionVariant
13
+ /**
14
+ * dragSelector (class - (append with .), id, etc) will be used to identify the grabbable button that will grab the div to drag
15
+ */
16
+ dragSelector: string
17
+ parentRef?: RefObject<HTMLDivElement>
18
+ boundaryGap?: number
19
+ childDivProps?: HTMLAttributes<HTMLDivElement>
20
+ }
21
+
22
+ /**
23
+ * dragClassName is the class that we feed to Draggable to identify dragging buttons
24
+ */
25
+ export interface DraggableButtonProps {
26
+ dragClassName: string
27
+ }
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from 'react'
2
2
  import AppNotDeployed from '../../Assets/Img/app-not-deployed.png'
3
3
  import { GenericEmptyStateType, ImageType } from '../Types'
4
4
 
@@ -19,24 +19,56 @@ function GenericEmptyState({
19
19
  SvgImage,
20
20
  noImage,
21
21
  layout = 'column',
22
- contentClassName = ''
22
+ contentClassName = '',
23
+ imageStyles = {},
23
24
  }: GenericEmptyStateType): JSX.Element {
24
- const isRowLayout = layout === 'row';
25
-
25
+ const isRowLayout = layout === 'row'
26
+
27
+ const getImageSize = () => {
28
+ switch (imageType) {
29
+ case ImageType.Large:
30
+ return { width: '250px', height: '200px' }
31
+ default:
32
+ return { width: '200px', height: '160px' }
33
+ }
34
+ }
35
+
26
36
  return (
27
37
  <div
28
- className={`flex ${isRowLayout ? 'dc__gap-32' : 'column dc__gap-20'} empty-state ${classname ? classname : ''}`}
38
+ className={`flex ${isRowLayout ? 'dc__gap-32' : 'column dc__gap-20'} empty-state ${
39
+ classname ? classname : ''
40
+ }`}
29
41
  style={styles}
30
42
  data-testid="generic-empty-state"
31
43
  {...(heightToDeduct >= 0 && { style: { ...styles, height: `calc(100vh - ${heightToDeduct}px)` } })}
32
- >
33
- {!SvgImage ? !noImage && <img className={imageClassName ? imageClassName : ''}
34
- src={image || AppNotDeployed}
35
- width={imageType === ImageType.Medium ? '200' : '250'}
36
- height={imageType === ImageType.Medium ? '160' : '200'}
37
- alt="empty-state"
38
- /> : <SvgImage />}
39
- <div className={`flex column dc__gap-10 dc__mxw-300 ${isRowLayout ? 'dc__align-start' : ''} ${contentClassName}`}>
44
+ >
45
+ {!SvgImage ? (
46
+ !noImage && (
47
+ <img
48
+ className={imageClassName ? imageClassName : ''}
49
+ src={image || AppNotDeployed}
50
+ style={{
51
+ ...imageStyles,
52
+ width: `${getImageSize().width}`,
53
+ height: `${getImageSize().height}`,
54
+ }}
55
+ alt="empty-state"
56
+ />
57
+ )
58
+ ) : (
59
+ <SvgImage
60
+ style={{
61
+ ...imageStyles,
62
+ width: `${getImageSize().width}`,
63
+ height: `${getImageSize().height}`,
64
+ }}
65
+ />
66
+ )}
67
+ <div
68
+ className={`flex column dc__gap-10 dc__mxw-300 ${
69
+ isRowLayout ? 'dc__align-start' : ''
70
+ } ${contentClassName}`}
71
+ >
40
72
  <h4 className="title fw-6 cn-9 mt-0 mb-0">{title}</h4>
41
73
  {subTitle && <p className={`subtitle ${isRowLayout ? 'subtitle--text-start' : ''}`}>{subTitle}</p>}
42
74
  {isButtonAvailable && renderButton()}
@@ -10,6 +10,7 @@ export default function Grid({
10
10
  containerClass = '',
11
11
  itemClass = '',
12
12
  children,
13
+ ...containerDivProps
13
14
  }: GridProps) {
14
15
  const containerStyles = container ? { gap: spacing + 'px' } : {}
15
16
 
@@ -25,14 +26,18 @@ export default function Grid({
25
26
  }
26
27
 
27
28
  return (
28
- <div className={`p-0 ${itemClass}`} style={itemStyles}>
29
+ <div className={`p-0 ${itemClass}`} style={itemStyles} {...containerDivProps}>
29
30
  {children}
30
31
  </div>
31
32
  )
32
33
  }
33
34
 
34
35
  return (
35
- <div className={`flex-wrap flexbox ${container ? containerClass : ''}`} style={containerStyles}>
36
+ <div
37
+ className={`flex-wrap flexbox ${container ? containerClass : ''}`}
38
+ style={containerStyles}
39
+ {...containerDivProps}
40
+ >
36
41
  {children}
37
42
  </div>
38
43
  )
@@ -1,4 +1,6 @@
1
- export interface GridProps {
1
+ import { HTMLAttributes } from 'react'
2
+
3
+ export interface GridProps extends HTMLAttributes<HTMLDivElement> {
2
4
  container?: boolean
3
5
  spacing?: number
4
6
  item?: boolean
@@ -0,0 +1,31 @@
1
+ import { useState, useEffect } from 'react'
2
+
3
+ let timeout
4
+
5
+ const getSize = () => {
6
+ return {
7
+ width: window.innerWidth,
8
+ height: window.innerHeight,
9
+ }
10
+ }
11
+
12
+ export const useWindowSize = () => {
13
+ const [windowSize, setWindowSize] = useState(getSize)
14
+
15
+ function handleResize(e) {
16
+ if (timeout) {
17
+ window.cancelAnimationFrame(timeout)
18
+ }
19
+
20
+ timeout = window.requestAnimationFrame(function () {
21
+ setWindowSize(getSize())
22
+ })
23
+ }
24
+
25
+ useEffect(() => {
26
+ window.addEventListener('resize', handleResize, false)
27
+ return () => window.removeEventListener('resize', handleResize, false)
28
+ }, [])
29
+
30
+ return windowSize
31
+ }
@@ -1,2 +1,3 @@
1
1
  export { useSuperAdmin } from './UseSuperAdmin/UseSuperAdmin'
2
2
  export { useClickOutside } from './UseClickOutside/UseClickOutside'
3
+ export { useWindowSize } from './UseWindowSize/UseWindowSize'
@@ -94,6 +94,7 @@ export interface GenericEmptyStateType {
94
94
  imageClassName?: string
95
95
  children?: ReactNode
96
96
  noImage?: boolean
97
+ imageStyles?: CSSProperties
97
98
  /**
98
99
  * @default 'column'
99
100
  */
@@ -45,3 +45,4 @@ export * from './DevtronProgressing'
45
45
  export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSelector'
46
46
  export * from './AddCDButton'
47
47
  export * from './CustomInput'
48
+ export * from './DraggableWrapper'