@devtron-labs/devtron-fe-common-lib 0.0.39 → 0.0.40-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.
- package/dist/Common/Common.service.d.ts +2 -2
- package/dist/Common/Constants.d.ts +1 -0
- package/dist/Common/RJSF/Form.d.ts +4 -0
- package/dist/Common/RJSF/common/FieldRow.d.ts +3 -0
- package/dist/Common/RJSF/common/types.d.ts +8 -0
- package/dist/Common/RJSF/config.d.ts +4 -0
- package/dist/Common/RJSF/constants.d.ts +5 -0
- package/dist/Common/RJSF/index.d.ts +2 -0
- package/dist/Common/RJSF/templates/ArrayFieldItemTemplate.d.ts +3 -0
- package/dist/Common/RJSF/templates/ArrayFieldTemplate.d.ts +3 -0
- package/dist/Common/RJSF/templates/BaseInput.d.ts +3 -0
- package/dist/Common/RJSF/templates/ButtonTemplates/AddButton.d.ts +3 -0
- package/dist/Common/RJSF/templates/ButtonTemplates/RemoveButton.d.ts +3 -0
- package/dist/Common/RJSF/templates/ButtonTemplates/SubmitButton.d.ts +3 -0
- package/dist/Common/RJSF/templates/ButtonTemplates/index.d.ts +3 -0
- package/dist/Common/RJSF/templates/Description.d.ts +3 -0
- package/dist/Common/RJSF/templates/Field.d.ts +3 -0
- package/dist/Common/RJSF/templates/FieldErrorTemplate.d.ts +3 -0
- package/dist/Common/RJSF/templates/ObjectFieldTemplate.d.ts +3 -0
- package/dist/Common/RJSF/templates/TitleField.d.ts +3 -0
- package/dist/Common/RJSF/templates/WrapIfAdditionalTemplate.d.ts +3 -0
- package/dist/Common/RJSF/templates/index.d.ts +10 -0
- package/dist/Common/RJSF/types.d.ts +3 -0
- package/dist/Common/RJSF/utils.d.ts +14 -0
- package/dist/Common/RJSF/widgets/Checkbox.d.ts +3 -0
- package/dist/Common/RJSF/widgets/Select.d.ts +3 -0
- package/dist/Common/RJSF/widgets/index.d.ts +2 -0
- package/dist/Common/Types.d.ts +36 -2
- package/dist/Common/index.d.ts +1 -0
- package/dist/index.js +567 -222
- package/package.json +4 -1
- package/src/Assets/Icon/ic-chevron-down.svg +5 -0
- package/src/Common/Common.service.ts +223 -76
- package/src/Common/Constants.ts +1 -0
- package/src/Common/ImageTags.tsx +11 -2
- package/src/Common/RJSF/Form.tsx +29 -0
- package/src/Common/RJSF/common/FieldRow.tsx +31 -0
- package/src/Common/RJSF/common/types.ts +9 -0
- package/src/Common/RJSF/config.ts +37 -0
- package/src/Common/RJSF/constants.ts +5 -0
- package/src/Common/RJSF/index.ts +2 -0
- package/src/Common/RJSF/rjsfForm.scss +17 -0
- package/src/Common/RJSF/templates/ArrayFieldItemTemplate.tsx +33 -0
- package/src/Common/RJSF/templates/ArrayFieldTemplate.tsx +77 -0
- package/src/Common/RJSF/templates/BaseInput.tsx +16 -0
- package/src/Common/RJSF/templates/ButtonTemplates/AddButton.tsx +18 -0
- package/src/Common/RJSF/templates/ButtonTemplates/RemoveButton.tsx +10 -0
- package/src/Common/RJSF/templates/ButtonTemplates/SubmitButton.tsx +18 -0
- package/src/Common/RJSF/templates/ButtonTemplates/index.ts +3 -0
- package/src/Common/RJSF/templates/Description.tsx +12 -0
- package/src/Common/RJSF/templates/Field.tsx +30 -0
- package/src/Common/RJSF/templates/FieldErrorTemplate.tsx +25 -0
- package/src/Common/RJSF/templates/ObjectFieldTemplate.tsx +96 -0
- package/src/Common/RJSF/templates/TitleField.tsx +9 -0
- package/src/Common/RJSF/templates/WrapIfAdditionalTemplate.tsx +51 -0
- package/src/Common/RJSF/templates/index.ts +10 -0
- package/src/Common/RJSF/types.ts +4 -0
- package/src/Common/RJSF/utils.ts +59 -0
- package/src/Common/RJSF/widgets/Checkbox.tsx +44 -0
- package/src/Common/RJSF/widgets/Select.tsx +76 -0
- package/src/Common/RJSF/widgets/index.ts +2 -0
- package/src/Common/Types.ts +44 -2
- package/src/Common/index.ts +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { getDefaultRegistry } from '@rjsf/core'
|
|
3
|
+
import { BaseInputTemplateProps } from '@rjsf/utils'
|
|
4
|
+
import { PLACEHOLDERS } from '../constants'
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
templates: { BaseInputTemplate },
|
|
8
|
+
} = getDefaultRegistry()
|
|
9
|
+
|
|
10
|
+
export const BaseInput = ({ placeholder, ...props }: BaseInputTemplateProps) => (
|
|
11
|
+
<BaseInputTemplate
|
|
12
|
+
placeholder={placeholder || PLACEHOLDERS.INPUT}
|
|
13
|
+
{...props}
|
|
14
|
+
className="form__input cn-9 fs-13 lh-20 fw-4"
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { IconButtonProps } from '@rjsf/utils'
|
|
3
|
+
|
|
4
|
+
import { ReactComponent as PlusIcon } from '../../../../Assets/Icon/ic-add.svg'
|
|
5
|
+
|
|
6
|
+
export const AddButton = ({ icon, iconType, registry, uiSchema, ...props }: IconButtonProps) => (
|
|
7
|
+
<div className="flexbox flex-justify-end">
|
|
8
|
+
<button
|
|
9
|
+
{...props}
|
|
10
|
+
type="button"
|
|
11
|
+
className="dc__outline-none-imp p-0 dc__transparent flex dc__gap-4 cursor"
|
|
12
|
+
title="Add"
|
|
13
|
+
>
|
|
14
|
+
<PlusIcon className="icon-dim-16 fcb-5" />
|
|
15
|
+
<span className="cb-5 fs-13 lh-20">Add</span>
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { IconButtonProps } from '@rjsf/utils'
|
|
3
|
+
|
|
4
|
+
import { ReactComponent as CrossIcon } from '../../../../Assets/Icon/ic-cross.svg'
|
|
5
|
+
|
|
6
|
+
export const RemoveButton = ({ icon, iconType, registry, uiSchema, ...props }: IconButtonProps) => (
|
|
7
|
+
<button {...props} type="button" className="dc__outline-none-imp p-0 dc__transparent flex cursor" title="Remove">
|
|
8
|
+
<CrossIcon className="icon-dim-16 fcr-5" />
|
|
9
|
+
</button>
|
|
10
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { getSubmitButtonOptions, SubmitButtonProps } from '@rjsf/utils'
|
|
3
|
+
|
|
4
|
+
export const SubmitButton = ({ uiSchema }: SubmitButtonProps) => {
|
|
5
|
+
const { submitText, norender, props: submitButtonProps = {} } = getSubmitButtonOptions(uiSchema)
|
|
6
|
+
|
|
7
|
+
return norender ? null : (
|
|
8
|
+
<div className="flexbox flex-justify-end">
|
|
9
|
+
<button
|
|
10
|
+
type="submit"
|
|
11
|
+
{...submitButtonProps}
|
|
12
|
+
className={`cta ${submitButtonProps.className || ''}`}
|
|
13
|
+
>
|
|
14
|
+
{submitText}
|
|
15
|
+
</button>
|
|
16
|
+
</div>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { DescriptionFieldProps } from '@rjsf/utils'
|
|
3
|
+
|
|
4
|
+
import { ReactComponent as Info } from '../../../Assets/Icon/ic-info-filled.svg'
|
|
5
|
+
|
|
6
|
+
export const Description = ({ id, description }: DescriptionFieldProps) =>
|
|
7
|
+
description && (
|
|
8
|
+
<div id={id} className="flex left flex-align-center mt-4 dc__gap-4">
|
|
9
|
+
<Info className="icon-dim-16 mw-16 info-icon-n5" />
|
|
10
|
+
<span className="cn-7 fs-11 fw-4 dc__ellipsis-right">{description}</span>
|
|
11
|
+
</div>
|
|
12
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { FieldTemplateProps, getUiOptions, getTemplate, ADDITIONAL_PROPERTY_FLAG } from '@rjsf/utils'
|
|
3
|
+
import { FieldRowWithLabel } from '../common/FieldRow'
|
|
4
|
+
|
|
5
|
+
export const Field = (props: FieldTemplateProps) => {
|
|
6
|
+
const { id, label, children, errors, hidden, required, displayLabel, registry, uiSchema, classNames, schema, description } =
|
|
7
|
+
props
|
|
8
|
+
const uiOptions = getUiOptions(uiSchema)
|
|
9
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate'>(
|
|
10
|
+
'WrapIfAdditionalTemplate',
|
|
11
|
+
registry,
|
|
12
|
+
uiOptions,
|
|
13
|
+
)
|
|
14
|
+
// Object type fields have additional properties for key/value pairs
|
|
15
|
+
const hasAdditionalProperties = ADDITIONAL_PROPERTY_FLAG in schema
|
|
16
|
+
// Label is not displayed for boolean fields by default and hide for object type fields
|
|
17
|
+
const showLabel = (displayLabel || schema.type === 'boolean') && !hasAdditionalProperties
|
|
18
|
+
|
|
19
|
+
return hidden ? (
|
|
20
|
+
<div className="hidden">{children}</div>
|
|
21
|
+
) : (
|
|
22
|
+
<div className={`${classNames} mb-12`}>
|
|
23
|
+
<FieldRowWithLabel label={label} showLabel={showLabel} id={id} required={required}>
|
|
24
|
+
<WrapIfAdditionalTemplate {...props}>{children}</WrapIfAdditionalTemplate>
|
|
25
|
+
</FieldRowWithLabel>
|
|
26
|
+
{description}
|
|
27
|
+
{errors}
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { errorId, FieldErrorProps } from '@rjsf/utils'
|
|
3
|
+
|
|
4
|
+
import { ReactComponent as Error } from '../../../Assets/Icon/ic-warning.svg'
|
|
5
|
+
|
|
6
|
+
export const FieldErrorTemplate = ({ errors = [], idSchema }: FieldErrorProps) => {
|
|
7
|
+
const id = errorId(idSchema)
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
errors.length > 0 && (
|
|
11
|
+
<span id={id}>
|
|
12
|
+
{errors
|
|
13
|
+
.filter((elem) => !!elem)
|
|
14
|
+
.map((error, index: number) => {
|
|
15
|
+
return (
|
|
16
|
+
<span className="form__error" key={index}>
|
|
17
|
+
<Error className="form__icon form__icon--error" />
|
|
18
|
+
{error}
|
|
19
|
+
</span>
|
|
20
|
+
)
|
|
21
|
+
})}
|
|
22
|
+
</span>
|
|
23
|
+
)
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -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"> *</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,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,76 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { WidgetProps } from '@rjsf/utils'
|
|
3
|
+
import ReactSelect, { MenuListProps, 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 MenuList = ({ children, ...props }: MenuListProps) => (
|
|
12
|
+
<components.MenuList {...props}>{Array.isArray(children) ? children.slice(0, 20) : children}</components.MenuList>
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const DropdownIndicator = (props) => (
|
|
16
|
+
<components.DropdownIndicator {...props}>
|
|
17
|
+
<ArrowDown className="icon-dim-20 icon-n5" data-testid="overview-project-edit-dropdown" />
|
|
18
|
+
</components.DropdownIndicator>
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
export const Select = (props: WidgetProps) => {
|
|
22
|
+
const {
|
|
23
|
+
id,
|
|
24
|
+
multiple = false,
|
|
25
|
+
options,
|
|
26
|
+
value,
|
|
27
|
+
disabled,
|
|
28
|
+
readonly,
|
|
29
|
+
autofocus = false,
|
|
30
|
+
onChange,
|
|
31
|
+
onBlur,
|
|
32
|
+
onFocus,
|
|
33
|
+
placeholder,
|
|
34
|
+
} = props
|
|
35
|
+
const { enumOptions: selectOptions = [] } = options
|
|
36
|
+
const emptyValue = multiple ? [] : ''
|
|
37
|
+
|
|
38
|
+
const handleChange = (option) => {
|
|
39
|
+
onChange(multiple ? option.map((o) => o.value) : option.value)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getOption = (value) =>
|
|
43
|
+
multiple
|
|
44
|
+
? selectOptions.filter((option) => value.includes(option.value))
|
|
45
|
+
: selectOptions.find((option) => option.value === value)
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<ReactSelect
|
|
49
|
+
id={id}
|
|
50
|
+
name={id}
|
|
51
|
+
isMulti={multiple}
|
|
52
|
+
value={typeof value === 'undefined' ? emptyValue : getOption(value)}
|
|
53
|
+
autoFocus={autofocus}
|
|
54
|
+
onChange={handleChange}
|
|
55
|
+
options={selectOptions}
|
|
56
|
+
onBlur={() => onBlur(id, value)}
|
|
57
|
+
onFocus={() => onFocus(id, value)}
|
|
58
|
+
placeholder={placeholder || PLACEHOLDERS.SELECT}
|
|
59
|
+
isDisabled={disabled || readonly}
|
|
60
|
+
styles={{
|
|
61
|
+
...commonStyles,
|
|
62
|
+
control: (base) => ({
|
|
63
|
+
...base,
|
|
64
|
+
...commonStyles.control,
|
|
65
|
+
backgroundColor: 'var(--N50)',
|
|
66
|
+
}),
|
|
67
|
+
}}
|
|
68
|
+
components={{
|
|
69
|
+
IndicatorSeparator: null,
|
|
70
|
+
DropdownIndicator,
|
|
71
|
+
MenuList,
|
|
72
|
+
}}
|
|
73
|
+
menuPlacement="auto"
|
|
74
|
+
/>
|
|
75
|
+
)
|
|
76
|
+
}
|
package/src/Common/Types.ts
CHANGED
|
@@ -226,6 +226,10 @@ export enum FilterStates {
|
|
|
226
226
|
ERROR = 2,
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
export enum MaterialDataSource {
|
|
230
|
+
EXTERNAL = "ext"
|
|
231
|
+
}
|
|
232
|
+
|
|
229
233
|
export interface CDMaterialType {
|
|
230
234
|
index: number
|
|
231
235
|
id: string
|
|
@@ -252,6 +256,36 @@ export interface CDMaterialType {
|
|
|
252
256
|
imageReleaseTags?: ReleaseTag[]
|
|
253
257
|
artifactStatus?: string
|
|
254
258
|
filterState: FilterStates
|
|
259
|
+
// Not even coming from API but required in CDMaterials for Security which makes its own api call but stores data in CDMaterials
|
|
260
|
+
scanToolId?: number
|
|
261
|
+
appliedFiltersTimestamp?: string
|
|
262
|
+
appliedFilters?: FilterConditionsListType[]
|
|
263
|
+
appliedFiltersState?: FilterStates
|
|
264
|
+
createdTime?: string
|
|
265
|
+
deployed?: boolean
|
|
266
|
+
dataSource?: MaterialDataSource
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export enum CDMaterialServiceEnum {
|
|
270
|
+
ROLLBACK = 'rollback',
|
|
271
|
+
CD_MATERIALS = 'cd-materials',
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export enum CDMaterialResourceQuery {
|
|
275
|
+
PENDING_APPROVAL = 'PENDING_APPROVAL'
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export enum CDMaterialFilterQuery {
|
|
279
|
+
RESOURCE = 'ELIGIBLE_RESOURCES',
|
|
280
|
+
ALL = 'ALL_RESOURCES'
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface CDMaterialServiceQueryParams {
|
|
284
|
+
search?: string
|
|
285
|
+
offset?: number
|
|
286
|
+
size?: number
|
|
287
|
+
resource?: CDMaterialResourceQuery
|
|
288
|
+
filter?: CDMaterialFilterQuery
|
|
255
289
|
}
|
|
256
290
|
|
|
257
291
|
export interface CommonNodeAttr {
|
|
@@ -367,15 +401,23 @@ export interface FilterConditionsListType {
|
|
|
367
401
|
conditions: FilterConditionsInfo[]
|
|
368
402
|
}
|
|
369
403
|
|
|
370
|
-
export interface
|
|
404
|
+
export interface CDMaterialsApprovalInfo {
|
|
371
405
|
approvalUsers: string[]
|
|
372
|
-
materials: any[]
|
|
373
406
|
userApprovalConfig: UserApprovalConfigType
|
|
374
407
|
requestedUserId: number
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export interface CDMaterialsMetaInfo {
|
|
375
411
|
tagsEditable: boolean
|
|
376
412
|
appReleaseTagNames: string[]
|
|
377
413
|
hideImageTaggingHardDelete: boolean
|
|
378
414
|
resourceFilters?: FilterConditionsListType[]
|
|
415
|
+
totalCount: number
|
|
416
|
+
canApproverDeploy: boolean
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export interface CDMaterialResponseType extends CDMaterialsMetaInfo, CDMaterialsApprovalInfo {
|
|
420
|
+
materials: CDMaterialType[]
|
|
379
421
|
}
|
|
380
422
|
|
|
381
423
|
export interface InputDetailType {
|
package/src/Common/index.ts
CHANGED