@devtron-labs/devtron-fe-common-lib 0.0.37 → 0.0.39-beta-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 (73) hide show
  1. package/dist/Common/AppStatus/AppStatus.d.ts +3 -0
  2. package/dist/Common/AppStatus/constants.d.ts +51 -0
  3. package/dist/Common/AppStatus/index.d.ts +1 -0
  4. package/dist/Common/AppStatus/types.d.ts +12 -0
  5. package/dist/Common/AppStatus/utils.d.ts +1 -0
  6. package/dist/Common/Helper.d.ts +1 -0
  7. package/dist/Common/Hooks/UseClickOutside/UseClickOutside.d.ts +1 -0
  8. package/dist/Common/Hooks/index.d.ts +1 -0
  9. package/dist/Common/RJSF/Form.d.ts +4 -0
  10. package/dist/Common/RJSF/common/FieldRow.d.ts +3 -0
  11. package/dist/Common/RJSF/common/types.d.ts +8 -0
  12. package/dist/Common/RJSF/config.d.ts +4 -0
  13. package/dist/Common/RJSF/constants.d.ts +5 -0
  14. package/dist/Common/RJSF/index.d.ts +2 -0
  15. package/dist/Common/RJSF/templates/ArrayFieldItemTemplate.d.ts +3 -0
  16. package/dist/Common/RJSF/templates/ArrayFieldTemplate.d.ts +3 -0
  17. package/dist/Common/RJSF/templates/BaseInput.d.ts +3 -0
  18. package/dist/Common/RJSF/templates/ButtonTemplates/AddButton.d.ts +3 -0
  19. package/dist/Common/RJSF/templates/ButtonTemplates/RemoveButton.d.ts +3 -0
  20. package/dist/Common/RJSF/templates/ButtonTemplates/SubmitButton.d.ts +3 -0
  21. package/dist/Common/RJSF/templates/ButtonTemplates/index.d.ts +3 -0
  22. package/dist/Common/RJSF/templates/Description.d.ts +3 -0
  23. package/dist/Common/RJSF/templates/Field.d.ts +3 -0
  24. package/dist/Common/RJSF/templates/FieldErrorTemplate.d.ts +3 -0
  25. package/dist/Common/RJSF/templates/ObjectFieldTemplate.d.ts +3 -0
  26. package/dist/Common/RJSF/templates/TitleField.d.ts +3 -0
  27. package/dist/Common/RJSF/templates/WrapIfAdditionalTemplate.d.ts +3 -0
  28. package/dist/Common/RJSF/templates/index.d.ts +10 -0
  29. package/dist/Common/RJSF/types.d.ts +3 -0
  30. package/dist/Common/RJSF/utils.d.ts +14 -0
  31. package/dist/Common/RJSF/widgets/Checkbox.d.ts +3 -0
  32. package/dist/Common/RJSF/widgets/Select.d.ts +3 -0
  33. package/dist/Common/RJSF/widgets/index.d.ts +2 -0
  34. package/dist/Common/index.d.ts +2 -0
  35. package/dist/index.js +487 -147
  36. package/package.json +4 -1
  37. package/src/Assets/Icon/ic-chevron-down.svg +5 -0
  38. package/src/Common/AppStatus/AppStatus.tsx +64 -0
  39. package/src/Common/AppStatus/constants.ts +53 -0
  40. package/src/Common/AppStatus/index.ts +1 -0
  41. package/src/Common/AppStatus/types.ts +12 -0
  42. package/src/Common/AppStatus/utils.ts +14 -0
  43. package/src/Common/Helper.tsx +8 -0
  44. package/src/Common/Hooks/UseClickOutside/UseClickOutside.tsx +15 -0
  45. package/src/Common/Hooks/index.ts +1 -0
  46. package/src/Common/RJSF/Form.tsx +28 -0
  47. package/src/Common/RJSF/common/FieldRow.tsx +31 -0
  48. package/src/Common/RJSF/common/types.ts +9 -0
  49. package/src/Common/RJSF/config.ts +37 -0
  50. package/src/Common/RJSF/constants.ts +5 -0
  51. package/src/Common/RJSF/index.ts +2 -0
  52. package/src/Common/RJSF/rjsfForm.scss +17 -0
  53. package/src/Common/RJSF/templates/ArrayFieldItemTemplate.tsx +33 -0
  54. package/src/Common/RJSF/templates/ArrayFieldTemplate.tsx +77 -0
  55. package/src/Common/RJSF/templates/BaseInput.tsx +16 -0
  56. package/src/Common/RJSF/templates/ButtonTemplates/AddButton.tsx +18 -0
  57. package/src/Common/RJSF/templates/ButtonTemplates/RemoveButton.tsx +10 -0
  58. package/src/Common/RJSF/templates/ButtonTemplates/SubmitButton.tsx +18 -0
  59. package/src/Common/RJSF/templates/ButtonTemplates/index.ts +3 -0
  60. package/src/Common/RJSF/templates/Description.tsx +12 -0
  61. package/src/Common/RJSF/templates/Field.tsx +30 -0
  62. package/src/Common/RJSF/templates/FieldErrorTemplate.tsx +25 -0
  63. package/src/Common/RJSF/templates/ObjectFieldTemplate.tsx +96 -0
  64. package/src/Common/RJSF/templates/TitleField.tsx +9 -0
  65. package/src/Common/RJSF/templates/WrapIfAdditionalTemplate.tsx +51 -0
  66. package/src/Common/RJSF/templates/index.ts +10 -0
  67. package/src/Common/RJSF/types.ts +4 -0
  68. package/src/Common/RJSF/utils.ts +59 -0
  69. package/src/Common/RJSF/widgets/Checkbox.tsx +44 -0
  70. package/src/Common/RJSF/widgets/Select.tsx +72 -0
  71. package/src/Common/RJSF/widgets/index.ts +2 -0
  72. package/src/Common/Security/scanVulnerabilities.css +2 -0
  73. package/src/Common/index.ts +2 -0
@@ -0,0 +1,96 @@
1
+ import React from 'react'
2
+ import {
3
+ ObjectFieldTemplatePropertyType,
4
+ ObjectFieldTemplateProps,
5
+ canExpand,
6
+ getTemplate,
7
+ getUiOptions,
8
+ titleId,
9
+ } from '@rjsf/utils'
10
+ import { FieldRowWithLabel } from '../common/FieldRow'
11
+
12
+ const Field = ({
13
+ disabled,
14
+ formData,
15
+ idSchema,
16
+ onAddClick,
17
+ properties,
18
+ readonly,
19
+ registry,
20
+ required,
21
+ schema,
22
+ title,
23
+ uiSchema,
24
+ }: ObjectFieldTemplateProps) => {
25
+ const {
26
+ ButtonTemplates: { AddButton },
27
+ } = registry.templates
28
+ const hasAdditionalProperties = !!schema.additionalProperties
29
+
30
+ const ActionButton = canExpand(schema, uiSchema, formData) && (
31
+ <AddButton
32
+ className="object-property-expand"
33
+ onClick={onAddClick(schema)}
34
+ disabled={disabled || readonly}
35
+ uiSchema={uiSchema}
36
+ registry={registry}
37
+ />
38
+ )
39
+
40
+ const Properties = properties.map((prop: ObjectFieldTemplatePropertyType) => prop.content)
41
+
42
+ if (hasAdditionalProperties) {
43
+ if (properties.length) {
44
+ return (
45
+ <>
46
+ <FieldRowWithLabel
47
+ label={title}
48
+ required={required}
49
+ showLabel
50
+ id={idSchema.$id}
51
+ shouldAlignCenter={false}
52
+ >
53
+ <div>{Properties}</div>
54
+ </FieldRowWithLabel>
55
+ {ActionButton}
56
+ </>
57
+ )
58
+ } else {
59
+ return (
60
+ <FieldRowWithLabel label={title} required={required} showLabel id={idSchema.$id}>
61
+ {ActionButton}
62
+ </FieldRowWithLabel>
63
+ )
64
+ }
65
+ }
66
+ return (
67
+ <>
68
+ {Properties}
69
+ {ActionButton}
70
+ </>
71
+ )
72
+ }
73
+
74
+ export const ObjectFieldTemplate = (props: ObjectFieldTemplateProps) => {
75
+ const { idSchema, registry, required, schema, title, uiSchema } = props
76
+ const options = getUiOptions(uiSchema)
77
+ const TitleFieldTemplate = getTemplate('TitleFieldTemplate', registry, options)
78
+ const hasAdditionalProperties = !!schema.additionalProperties
79
+ const showTitle = title && !hasAdditionalProperties
80
+
81
+ return (
82
+ <fieldset id={idSchema.$id}>
83
+ {showTitle && (
84
+ <TitleFieldTemplate
85
+ id={titleId(idSchema)}
86
+ title={title}
87
+ required={required}
88
+ schema={schema}
89
+ uiSchema={uiSchema}
90
+ registry={registry}
91
+ />
92
+ )}
93
+ <Field {...props} />
94
+ </fieldset>
95
+ )
96
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react'
2
+ import { TitleFieldProps } from '@rjsf/utils'
3
+
4
+ export const TitleField = ({ id, title, required }: TitleFieldProps) => (
5
+ <legend className="fs-13 fw-6 cn-9 lh-20 pb-8 dc__border-bottom en-1 mb-12" id={id}>
6
+ <span>{title}</span>
7
+ {required && <span className="cr-5">&nbsp;*</span>}
8
+ </legend>
9
+ )
@@ -0,0 +1,51 @@
1
+ import React from 'react'
2
+ import { ADDITIONAL_PROPERTY_FLAG, WrapIfAdditionalTemplateProps } from '@rjsf/utils'
3
+
4
+ import { PLACEHOLDERS } from '../constants'
5
+
6
+ export const WrapIfAdditionalTemplate = ({
7
+ id,
8
+ disabled,
9
+ label,
10
+ onKeyChange,
11
+ onDropPropertyClick,
12
+ readonly,
13
+ schema,
14
+ children,
15
+ uiSchema,
16
+ registry,
17
+ }: WrapIfAdditionalTemplateProps) => {
18
+ const { templates } = registry
19
+ const { RemoveButton } = templates.ButtonTemplates
20
+ const additional = ADDITIONAL_PROPERTY_FLAG in schema
21
+
22
+ return (
23
+ <>
24
+ {additional ? (
25
+ <div className="rjsf-form-template__additional-fields display-grid dc__gap-8 flex-align-center">
26
+ <div>
27
+ <input
28
+ type="text"
29
+ className="form__input cn-9 fs-13 lh-20 fw-4"
30
+ id={`${id}-key`}
31
+ onBlur={(event) => onKeyChange(event.target.value)}
32
+ placeholder={PLACEHOLDERS.OBJECT_KEY}
33
+ defaultValue={label}
34
+ />
35
+ </div>
36
+ <div>{children}</div>
37
+ <div>
38
+ <RemoveButton
39
+ disabled={disabled || readonly}
40
+ onClick={onDropPropertyClick(label)}
41
+ uiSchema={uiSchema}
42
+ registry={registry}
43
+ />
44
+ </div>
45
+ </div>
46
+ ) : (
47
+ children
48
+ )}
49
+ </>
50
+ )
51
+ }
@@ -0,0 +1,10 @@
1
+ export { ArrayFieldTemplate } from './ArrayFieldTemplate'
2
+ export { ArrayFieldItemTemplate } from './ArrayFieldItemTemplate'
3
+ export { BaseInput as BaseInputTemplate } from './BaseInput'
4
+ export * from './ButtonTemplates'
5
+ export { Description as DescriptionFieldTemplate } from './Description'
6
+ export { Field as FieldTemplate } from './Field'
7
+ export { FieldErrorTemplate } from './FieldErrorTemplate'
8
+ export { ObjectFieldTemplate } from './ObjectFieldTemplate'
9
+ export { TitleField as TitleFieldTemplate } from './TitleField'
10
+ export { WrapIfAdditionalTemplate } from './WrapIfAdditionalTemplate'
@@ -0,0 +1,4 @@
1
+ import { ComponentProps } from 'react'
2
+ import RJSFForm from '@rjsf/core'
3
+
4
+ export type FormProps = Omit<ComponentProps<typeof RJSFForm>, 'validator'>
@@ -0,0 +1,59 @@
1
+ import { TranslatableString, englishStringTranslator } from '@rjsf/utils'
2
+
3
+ /**
4
+ * Override for the TranslatableString from RJSF
5
+ */
6
+ export const translateString = (stringToTranslate: TranslatableString, params?: string[]): string => {
7
+ switch (stringToTranslate) {
8
+ case TranslatableString.NewStringDefault:
9
+ // Use an empty string for the new additionalProperties string default value
10
+ return ''
11
+ default:
12
+ return englishStringTranslator(stringToTranslate, params)
13
+ }
14
+ }
15
+
16
+ export const getCommonSelectStyle = (styleOverrides = {}) => {
17
+ return {
18
+ menuList: (base) => ({
19
+ ...base,
20
+ paddingTop: 0,
21
+ paddingBottom: 0,
22
+ }),
23
+ control: (base, state) => ({
24
+ ...base,
25
+ minHeight: '32px',
26
+ boxShadow: 'none',
27
+ backgroundColor: 'var(--N50)',
28
+ border: state.isFocused ? '1px solid var(--B500)' : '1px solid var(--N200)',
29
+ cursor: 'pointer',
30
+ }),
31
+ option: (base, state) => ({
32
+ ...base,
33
+ color: 'var(--N900)',
34
+ backgroundColor: state.isFocused ? 'var(--N100)' : 'white',
35
+ padding: '10px 12px',
36
+ }),
37
+ dropdownIndicator: (base, state) => ({
38
+ ...base,
39
+ color: 'var(--N400)',
40
+ padding: '0 8px',
41
+ transition: 'all .2s ease',
42
+ transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
43
+ }),
44
+ valueContainer: (base) => ({
45
+ ...base,
46
+ padding: '0 8px',
47
+ fontWeight: '400',
48
+ }),
49
+ loadingMessage: (base) => ({
50
+ ...base,
51
+ color: 'var(--N600)',
52
+ }),
53
+ noOptionsMessage: (base) => ({
54
+ ...base,
55
+ color: 'var(--N600)',
56
+ }),
57
+ ...styleOverrides,
58
+ }
59
+ }
@@ -0,0 +1,44 @@
1
+ import React, { ChangeEvent } from 'react'
2
+ import Toggle from '../../Toggle/Toggle'
3
+ import { WidgetProps } from '@rjsf/utils'
4
+
5
+ export const Checkbox = ({
6
+ id,
7
+ onChange,
8
+ value,
9
+ required,
10
+ disabled,
11
+ readonly,
12
+ autofocus,
13
+ onBlur,
14
+ onFocus,
15
+ }: WidgetProps) => {
16
+ const handleEvent = (e: ChangeEvent<HTMLInputElement>, type: 'blur' | 'focus') => {
17
+ const { id, checked } = e.target
18
+ if (type === 'blur') {
19
+ onBlur(id, checked)
20
+ } else if (type === 'focus') {
21
+ onFocus(id, checked)
22
+ }
23
+ }
24
+
25
+ const isSelected: boolean = typeof value === 'undefined' ? false : value
26
+
27
+ return (
28
+ <div>
29
+ <Toggle
30
+ selected={isSelected}
31
+ onSelect={onChange}
32
+ id={id}
33
+ name={id}
34
+ required={required}
35
+ disabled={disabled || readonly}
36
+ autoFocus={autofocus}
37
+ rootClassName="w-32 mb-0 dc__height-inherit"
38
+ onBlur={(e) => handleEvent(e, 'blur')}
39
+ onFocus={(e) => handleEvent(e, 'focus')}
40
+ />
41
+ <span className="dc__capitalize ml-8">{isSelected.toString()}</span>
42
+ </div>
43
+ )
44
+ }
@@ -0,0 +1,72 @@
1
+ import React from 'react'
2
+ import { WidgetProps } from '@rjsf/utils'
3
+ import ReactSelect, { components } from 'react-select'
4
+ import { PLACEHOLDERS } from '../constants'
5
+ import { getCommonSelectStyle } from '../utils'
6
+
7
+ import { ReactComponent as ArrowDown } from '../../../Assets/Icon/ic-chevron-down.svg'
8
+
9
+ const commonStyles = getCommonSelectStyle()
10
+
11
+ const DropdownIndicator = (props) => (
12
+ <components.DropdownIndicator {...props}>
13
+ <ArrowDown className="icon-dim-20 icon-n5" data-testid="overview-project-edit-dropdown" />
14
+ </components.DropdownIndicator>
15
+ )
16
+
17
+ export const Select = (props: WidgetProps) => {
18
+ const {
19
+ id,
20
+ multiple = false,
21
+ options,
22
+ value,
23
+ disabled,
24
+ readonly,
25
+ autofocus = false,
26
+ onChange,
27
+ onBlur,
28
+ onFocus,
29
+ placeholder,
30
+ } = props
31
+ const { enumOptions: selectOptions = [] } = options
32
+ const emptyValue = multiple ? [] : ''
33
+
34
+ const handleChange = (option) => {
35
+ onChange(multiple ? option.map((o) => o.value) : option.value)
36
+ }
37
+
38
+ const getOption = (value) =>
39
+ multiple
40
+ ? selectOptions.filter((option) => value.includes(option.value))
41
+ : selectOptions.find((option) => option.value === value)
42
+
43
+ return (
44
+ <ReactSelect
45
+ id={id}
46
+ name={id}
47
+ isMulti={multiple}
48
+ value={typeof value === 'undefined' ? emptyValue : getOption(value)}
49
+ autoFocus={autofocus}
50
+ onChange={handleChange}
51
+ options={selectOptions}
52
+ onBlur={() => onBlur(id, value)}
53
+ onFocus={() => onFocus(id, value)}
54
+ placeholder={placeholder || PLACEHOLDERS.SELECT}
55
+ isDisabled={disabled || readonly}
56
+ styles={{
57
+ ...commonStyles,
58
+ control: (base) => ({
59
+ ...base,
60
+ ...commonStyles.control,
61
+ backgroundColor: 'var(--N50)',
62
+ }),
63
+ }}
64
+ components={{
65
+ IndicatorSeparator: null,
66
+ DropdownIndicator,
67
+ }}
68
+ menuPlacement="auto"
69
+ menuPortalTarget={document.body}
70
+ />
71
+ )
72
+ }
@@ -0,0 +1,2 @@
1
+ export { Checkbox as CheckboxWidget } from './Checkbox'
2
+ export { Select as SelectWidget } from './Select'
@@ -39,6 +39,8 @@
39
39
  .security-tab__cell-fixed-ver,
40
40
  .security-tab__cell-policy {
41
41
  padding: 10px;
42
+ max-width: 120px;
43
+ word-wrap: break-word;
42
44
  }
43
45
 
44
46
  .security-tab__cell-cve {
@@ -39,3 +39,5 @@ export { default as DebouncedSearch } from './DebouncedSearch/DebouncedSearch'
39
39
  export { default as Grid } from './Grid/Grid'
40
40
  export { default as ClipboardButton } from './ClipboardButton/ClipboardButton'
41
41
  export * from './Hooks'
42
+ export { AppStatus } from './AppStatus'
43
+ export * from './RJSF'