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

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 +4 -1
  2. package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
  3. package/dist/Common/CustomInput/Types.d.ts +1 -0
  4. package/dist/Common/EmptyState/GenericEmptyState.d.ts +1 -1
  5. package/dist/Common/Grid/Grid.d.ts +1 -1
  6. package/dist/Common/Grid/types.d.ts +2 -2
  7. package/dist/Common/Hooks/index.d.ts +0 -1
  8. package/dist/Common/Types.d.ts +1 -0
  9. package/dist/Common/index.d.ts +0 -1
  10. package/dist/index.js +152 -268
  11. package/package.json +2 -3
  12. package/src/Common/Constants.ts +4 -1
  13. package/src/Common/CustomInput/CustomInput.tsx +3 -2
  14. package/src/Common/CustomInput/Types.ts +1 -0
  15. package/src/Common/EmptyState/GenericEmptyState.tsx +45 -13
  16. package/src/Common/Grid/Grid.tsx +2 -7
  17. package/src/Common/Grid/types.ts +1 -3
  18. package/src/Common/Hooks/index.ts +0 -1
  19. package/src/Common/Types.ts +1 -0
  20. package/src/Common/index.ts +0 -1
  21. package/dist/Common/DraggableWrapper/DraggableButton.d.ts +0 -3
  22. package/dist/Common/DraggableWrapper/DraggableWrapper.d.ts +0 -9
  23. package/dist/Common/DraggableWrapper/index.d.ts +0 -3
  24. package/dist/Common/DraggableWrapper/types.d.ts +0 -19
  25. package/dist/Common/Hooks/UseWindowSize/UseWindowSize.d.ts +0 -4
  26. package/src/Assets/Icon/ic-drag.svg +0 -8
  27. package/src/Common/DraggableWrapper/DraggableButton.tsx +0 -11
  28. package/src/Common/DraggableWrapper/DraggableWrapper.tsx +0 -109
  29. package/src/Common/DraggableWrapper/index.ts +0 -3
  30. package/src/Common/DraggableWrapper/types.ts +0 -22
  31. package/src/Common/Hooks/UseWindowSize/UseWindowSize.tsx +0 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.51-beta-2",
3
+ "version": "0.0.51-beta-3-1",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -47,8 +47,7 @@
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",
51
- "react-draggable": "^4.4.5"
50
+ "react-router-dom": "^5.3.0"
52
51
  },
53
52
  "dependencies": {
54
53
  "fast-json-patch": "^3.1.1",
@@ -242,4 +242,7 @@ export const RepositoryAction = {
242
242
  CHART_PUSH: "CHART_PUSH"
243
243
  }
244
244
 
245
- export const MAX_Z_INDEX = 2147483647
245
+ export enum APPROVAL_MODAL_TYPE {
246
+ CONFIG = 'CONFIG',
247
+ DEPLOYMENT = 'DEPLOYMENT',
248
+ }
@@ -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
  }
@@ -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,7 +10,6 @@ export default function Grid({
10
10
  containerClass = '',
11
11
  itemClass = '',
12
12
  children,
13
- ...containerDivProps
14
13
  }: GridProps) {
15
14
  const containerStyles = container ? { gap: spacing + 'px' } : {}
16
15
 
@@ -26,18 +25,14 @@ export default function Grid({
26
25
  }
27
26
 
28
27
  return (
29
- <div className={`p-0 ${itemClass}`} style={itemStyles} {...containerDivProps}>
28
+ <div className={`p-0 ${itemClass}`} style={itemStyles}>
30
29
  {children}
31
30
  </div>
32
31
  )
33
32
  }
34
33
 
35
34
  return (
36
- <div
37
- className={`flex-wrap flexbox ${container ? containerClass : ''}`}
38
- style={containerStyles}
39
- {...containerDivProps}
40
- >
35
+ <div className={`flex-wrap flexbox ${container ? containerClass : ''}`} style={containerStyles}>
41
36
  {children}
42
37
  </div>
43
38
  )
@@ -1,6 +1,4 @@
1
- import { HTMLAttributes } from "react"
2
-
3
- export interface GridProps extends HTMLAttributes<HTMLDivElement> {
1
+ export interface GridProps {
4
2
  container?: boolean
5
3
  spacing?: number
6
4
  item?: boolean
@@ -1,3 +1,2 @@
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,4 +45,3 @@ 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'
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- import { DraggableButtonProps } from './types';
3
- export default function DraggableButton({ dragClassName }: DraggableButtonProps): JSX.Element;
@@ -1,9 +0,0 @@
1
- /// <reference types="react" />
2
- import { DraggableWrapperProps } from './types';
3
- /**
4
- * TODO: import it as lazy, after it is supported in common
5
- * 1. If using react select please use menuPlacement='auto'
6
- * 2. dragClassName will be used to identify the grabbable button that will grab the div to drag
7
- * 3. parentRef is the reference point from which we will derive the base top:0 ,left: 0 position
8
- */
9
- export default function DraggableWrapper({ children, zIndex, positionVariant, dragClassName, parentRef, boundaryGap, childDivProps, }: DraggableWrapperProps): JSX.Element;
@@ -1,3 +0,0 @@
1
- export { default as DraggableWrapper } from './DraggableWrapper';
2
- export { default as DraggableButton } from './DraggableButton';
3
- export * from './types';
@@ -1,19 +0,0 @@
1
- import { HTMLAttributes } from 'react';
2
- export declare enum DraggablePositionVariant {
3
- PARENT_BOTTOM_CENTER = "PARENT_BOTTOM_CENTER",
4
- SCREEN_BOTTOM_CENTER = "SCREEN_BOTTOM_CENTER"
5
- }
6
- export interface DraggableWrapperProps {
7
- children: React.ReactNode;
8
- zIndex?: number;
9
- positionVariant?: DraggablePositionVariant;
10
- dragClassName: string;
11
- parentRef?: React.RefObject<HTMLDivElement>;
12
- boundaryGap?: number;
13
- childDivProps?: HTMLAttributes<HTMLDivElement>;
14
- }
15
- /**
16
- * dragClassName is the class that we feed to Draggable to identify dragging buttons
17
- */
18
- export interface DraggableButtonProps extends Pick<DraggableWrapperProps, 'dragClassName'> {
19
- }
@@ -1,4 +0,0 @@
1
- export declare function useWindowSize(): {
2
- width: number;
3
- height: number;
4
- };
@@ -1,8 +0,0 @@
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>
@@ -1,11 +0,0 @@
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 type="button" className="dc__outline-none-imp dc__no-border p-0 dc__transparent h-20">
8
- <ICDrag className={`${dragClassName} dc__grabbable icon-dim-20 fcn-6`} />
9
- </button>
10
- )
11
- }
@@ -1,109 +0,0 @@
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. dragClassName 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
- dragClassName,
18
- parentRef,
19
- boundaryGap = 16,
20
- childDivProps = {},
21
- }: DraggableWrapperProps) {
22
- const windowSize = useWindowSize()
23
- const nodeRef = useRef<HTMLDivElement>(null)
24
-
25
- const getDefaultPosition = (positionVariant: DraggablePositionVariant): ControlPosition => {
26
- // if i return x: 0, y: 0 then it will be top left corner of parentDiv
27
- const parentRect = parentRef?.current?.getBoundingClientRect() ?? {
28
- width: 0,
29
- height: 0,
30
- top: 0,
31
- left: 0,
32
- bottom: 0,
33
- }
34
-
35
- switch (positionVariant) {
36
- case DraggablePositionVariant.PARENT_BOTTOM_CENTER: {
37
- const x = parentRect.width / 2 - nodeRef.current?.getBoundingClientRect().width / 2
38
- const y =
39
- Math.min(parentRect.height, windowSize.height) -
40
- parentRect.top -
41
- nodeRef.current?.getBoundingClientRect().height -
42
- boundaryGap
43
- return { x, y }
44
- }
45
- case DraggablePositionVariant.SCREEN_BOTTOM_CENTER: {
46
- const x = windowSize.width / 2 - parentRect.left - nodeRef.current?.getBoundingClientRect().width / 2
47
- const y =
48
- windowSize.height - parentRect.top - nodeRef.current?.getBoundingClientRect().height - boundaryGap
49
-
50
- return { x, y }
51
- }
52
- // Add more cases for other variants if needed
53
- default:
54
- throw new Error('Please use DraggablePositionVariant enum')
55
- }
56
- }
57
-
58
- const [position, setPosition] = useState<ControlPosition>({
59
- x: 0,
60
- y: 0,
61
- })
62
-
63
- // On change of windowSize we will reset the position to default
64
- useEffect(() => {
65
- const defaultPosition = getDefaultPosition(positionVariant)
66
- setPosition(defaultPosition)
67
- }, [nodeRef, positionVariant, windowSize])
68
-
69
- function handlePositionChange(e, data: DraggableData) {
70
- const offsetX = parentRef?.current?.getBoundingClientRect().left ?? 0
71
- const offsetY = parentRef?.current?.getBoundingClientRect().top ?? 0
72
-
73
- if (
74
- offsetX + data.x + nodeRef.current?.getBoundingClientRect().width + boundaryGap > windowSize.width ||
75
- offsetY + data.y + nodeRef.current?.getBoundingClientRect().height + boundaryGap > windowSize.height ||
76
- offsetX + data.x < 0 ||
77
- offsetY + data.y < 0
78
- ) {
79
- return
80
- }
81
-
82
- setPosition({
83
- x: data.x,
84
- y: data.y,
85
- })
86
- }
87
-
88
- return (
89
- // Check there might be a case if we need it to be absolute?
90
- <div
91
- className="dc__position-fixed"
92
- style={{
93
- zIndex,
94
- }}
95
- >
96
- <Draggable handle={`.${dragClassName}`} nodeRef={nodeRef} position={position} onDrag={handlePositionChange}>
97
- <div
98
- ref={nodeRef}
99
- {...childDivProps}
100
- style={{
101
- zIndex,
102
- }}
103
- >
104
- {children}
105
- </div>
106
- </Draggable>
107
- </div>
108
- )
109
- }
@@ -1,3 +0,0 @@
1
- export { default as DraggableWrapper } from './DraggableWrapper'
2
- export { default as DraggableButton } from './DraggableButton'
3
- export * from './types'
@@ -1,22 +0,0 @@
1
- import { HTMLAttributes } 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: React.ReactNode
11
- zIndex?: number
12
- positionVariant?: DraggablePositionVariant
13
- dragClassName: string
14
- parentRef?: React.RefObject<HTMLDivElement>
15
- boundaryGap?: number
16
- childDivProps?: HTMLAttributes<HTMLDivElement>
17
- }
18
-
19
- /**
20
- * dragClassName is the class that we feed to Draggable to identify dragging buttons
21
- */
22
- export interface DraggableButtonProps extends Pick<DraggableWrapperProps, 'dragClassName'> {}
@@ -1,30 +0,0 @@
1
- import { useState, useEffect } from 'react'
2
-
3
- function getSize() {
4
- return {
5
- width: window.innerWidth,
6
- height: window.innerHeight,
7
- }
8
- }
9
-
10
- export function useWindowSize() {
11
- let timeout
12
- const [windowSize, setWindowSize] = useState(getSize)
13
-
14
- function handleResize(e) {
15
- if (timeout) {
16
- window.cancelAnimationFrame(timeout)
17
- }
18
-
19
- timeout = window.requestAnimationFrame(function () {
20
- setWindowSize(getSize())
21
- })
22
- }
23
-
24
- useEffect(() => {
25
- window.addEventListener('resize', handleResize, false)
26
- return () => window.removeEventListener('resize', handleResize, false)
27
- }, [])
28
-
29
- return windowSize
30
- }