box-ui-elements 23.4.0-beta.1 → 23.4.0-beta.3
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/explorer.js +1 -1
- package/dist/preview.js +1 -1
- package/dist/sidebar.js +1 -1
- package/es/common/types/metadata.js.flow +1 -0
- package/es/common/types/metadata.js.map +1 -1
- package/es/features/metadata-instance-editor/CascadePolicy.js +6 -2
- package/es/features/metadata-instance-editor/CascadePolicy.js.flow +19 -12
- package/es/features/metadata-instance-editor/CascadePolicy.js.map +1 -1
- package/es/features/metadata-instance-editor/Instance.js +31 -9
- package/es/features/metadata-instance-editor/Instance.js.flow +41 -9
- package/es/features/metadata-instance-editor/Instance.js.map +1 -1
- package/es/features/metadata-instance-editor/Instances.js +2 -0
- package/es/features/metadata-instance-editor/Instances.js.flow +3 -0
- package/es/features/metadata-instance-editor/Instances.js.map +1 -1
- package/es/features/metadata-instance-editor/MetadataInstanceEditor.js +2 -0
- package/es/features/metadata-instance-editor/MetadataInstanceEditor.js.flow +3 -0
- package/es/features/metadata-instance-editor/MetadataInstanceEditor.js.map +1 -1
- package/es/features/metadata-instance-editor/TemplateDropdown.js +1 -1
- package/es/features/metadata-instance-editor/TemplateDropdown.js.flow +1 -1
- package/es/features/metadata-instance-editor/TemplateDropdown.js.map +1 -1
- package/es/features/metadata-instance-editor/TemplatedInstance.js +2 -0
- package/es/features/metadata-instance-editor/TemplatedInstance.js.flow +11 -1
- package/es/features/metadata-instance-editor/TemplatedInstance.js.map +1 -1
- package/es/features/metadata-instance-editor/constants.js +2 -1
- package/es/features/metadata-instance-editor/constants.js.flow +3 -1
- package/es/features/metadata-instance-editor/constants.js.map +1 -1
- package/es/features/metadata-instance-fields/DateMetadataField.js +30 -25
- package/es/features/metadata-instance-fields/DateMetadataField.js.flow +31 -27
- package/es/features/metadata-instance-fields/DateMetadataField.js.map +1 -1
- package/es/features/metadata-instance-fields/EnumMetadataField.js +8 -5
- package/es/features/metadata-instance-fields/EnumMetadataField.js.flow +8 -6
- package/es/features/metadata-instance-fields/EnumMetadataField.js.map +1 -1
- package/es/features/metadata-instance-fields/FloatMetadataField.js +2 -0
- package/es/features/metadata-instance-fields/FloatMetadataField.js.flow +3 -0
- package/es/features/metadata-instance-fields/FloatMetadataField.js.map +1 -1
- package/es/features/metadata-instance-fields/IntegerMetadataField.js +2 -0
- package/es/features/metadata-instance-fields/IntegerMetadataField.js.flow +3 -0
- package/es/features/metadata-instance-fields/IntegerMetadataField.js.map +1 -1
- package/es/features/metadata-instance-fields/MetadataField.js +7 -0
- package/es/features/metadata-instance-fields/MetadataField.js.flow +8 -0
- package/es/features/metadata-instance-fields/MetadataField.js.map +1 -1
- package/es/features/metadata-instance-fields/MultiSelectMetadataField.js +2 -0
- package/es/features/metadata-instance-fields/MultiSelectMetadataField.js.flow +3 -0
- package/es/features/metadata-instance-fields/MultiSelectMetadataField.js.map +1 -1
- package/es/features/metadata-instance-fields/TextMetadataField.js +8 -5
- package/es/features/metadata-instance-fields/TextMetadataField.js.flow +8 -6
- package/es/features/metadata-instance-fields/TextMetadataField.js.map +1 -1
- package/i18n/bn-IN.js +4 -4
- package/i18n/bn-IN.properties +4 -4
- package/i18n/da-DK.js +4 -4
- package/i18n/da-DK.properties +4 -4
- package/i18n/de-DE.js +4 -4
- package/i18n/de-DE.properties +4 -4
- package/i18n/es-419.js +3 -3
- package/i18n/es-419.properties +3 -3
- package/i18n/es-ES.js +3 -3
- package/i18n/es-ES.properties +3 -3
- package/i18n/fi-FI.js +3 -3
- package/i18n/fi-FI.properties +3 -3
- package/i18n/fr-CA.js +4 -4
- package/i18n/fr-CA.properties +4 -4
- package/i18n/fr-FR.js +4 -4
- package/i18n/fr-FR.properties +4 -4
- package/i18n/hi-IN.js +4 -4
- package/i18n/hi-IN.properties +4 -4
- package/i18n/it-IT.js +4 -4
- package/i18n/it-IT.properties +4 -4
- package/i18n/ko-KR.js +4 -4
- package/i18n/ko-KR.properties +4 -4
- package/i18n/nb-NO.js +4 -4
- package/i18n/nb-NO.properties +4 -4
- package/i18n/nl-NL.js +4 -4
- package/i18n/nl-NL.properties +4 -4
- package/i18n/pl-PL.js +4 -4
- package/i18n/pl-PL.properties +4 -4
- package/i18n/pt-BR.js +4 -4
- package/i18n/pt-BR.properties +4 -4
- package/i18n/ru-RU.js +4 -4
- package/i18n/ru-RU.properties +4 -4
- package/i18n/sv-SE.js +4 -4
- package/i18n/sv-SE.properties +4 -4
- package/i18n/tr-TR.js +4 -4
- package/i18n/tr-TR.properties +4 -4
- package/i18n/zh-CN.js +4 -4
- package/i18n/zh-CN.properties +4 -4
- package/i18n/zh-TW.js +4 -4
- package/i18n/zh-TW.properties +4 -4
- package/package.json +1 -1
- package/src/common/types/metadata.js +1 -0
- package/src/features/metadata-instance-editor/CascadePolicy.js +19 -12
- package/src/features/metadata-instance-editor/Instance.js +41 -9
- package/src/features/metadata-instance-editor/Instances.js +3 -0
- package/src/features/metadata-instance-editor/MetadataInstanceEditor.js +3 -0
- package/src/features/metadata-instance-editor/TemplateDropdown.js +1 -1
- package/src/features/metadata-instance-editor/TemplatedInstance.js +11 -1
- package/src/features/metadata-instance-editor/__tests__/CascadePolicy.test.js +92 -1
- package/src/features/metadata-instance-editor/__tests__/Instance.test.js +207 -2
- package/src/features/metadata-instance-editor/__tests__/Instances.test.js +92 -3
- package/src/features/metadata-instance-editor/__tests__/MetadataInstanceEditor.test.js +105 -0
- package/src/features/metadata-instance-editor/__tests__/TemplatedInstance.test.js +83 -1
- package/src/features/metadata-instance-editor/__tests__/__snapshots__/CascadePolicy.test.js.snap +1 -0
- package/src/features/metadata-instance-editor/__tests__/__snapshots__/Instance.test.js.snap +16 -5
- package/src/features/metadata-instance-editor/__tests__/__snapshots__/Instances.test.js.snap +4 -2
- package/src/features/metadata-instance-editor/__tests__/__snapshots__/MetadataInstanceEditor.test.js.snap +1 -0
- package/src/features/metadata-instance-editor/__tests__/__snapshots__/TemplatedInstance.test.js.snap +2 -2
- package/src/features/metadata-instance-editor/constants.js +3 -1
- package/src/features/metadata-instance-fields/DateMetadataField.js +31 -27
- package/src/features/metadata-instance-fields/EnumMetadataField.js +8 -6
- package/src/features/metadata-instance-fields/FloatMetadataField.js +3 -0
- package/src/features/metadata-instance-fields/IntegerMetadataField.js +3 -0
- package/src/features/metadata-instance-fields/MetadataField.js +8 -0
- package/src/features/metadata-instance-fields/MultiSelectMetadataField.js +3 -0
- package/src/features/metadata-instance-fields/TextMetadataField.js +8 -6
- package/src/features/metadata-instance-fields/__tests__/DateMetadataField.test.js +59 -8
- package/src/features/metadata-instance-fields/__tests__/EnumMetadataField.test.js +63 -18
- package/src/features/metadata-instance-fields/__tests__/FloatMetadataField.test.js +68 -4
- package/src/features/metadata-instance-fields/__tests__/IntegerMetadataField.test.js +90 -4
- package/src/features/metadata-instance-fields/__tests__/MultiSelectMetadataField.test.js +95 -7
- package/src/features/metadata-instance-fields/__tests__/TextMetadataField.test.js +107 -14
- package/src/features/metadata-instance-fields/__tests__/__snapshots__/DateMetadataField.test.js.snap +0 -18
- package/src/features/metadata-instance-fields/__tests__/__snapshots__/EnumMetadataField.test.js.snap +0 -84
- package/src/features/metadata-instance-fields/__tests__/__snapshots__/FloatMetadataField.test.js.snap +0 -8
- package/src/features/metadata-instance-fields/__tests__/__snapshots__/IntegerMetadataField.test.js.snap +0 -8
- package/src/features/metadata-instance-fields/__tests__/__snapshots__/MultiSelectMetadataField.test.js.snap +0 -58
- package/src/features/metadata-instance-fields/__tests__/__snapshots__/TextMetadataField.test.js.snap +0 -31
|
@@ -34,10 +34,12 @@ const agents = [
|
|
|
34
34
|
type Props = {
|
|
35
35
|
canEdit: boolean,
|
|
36
36
|
canUseAIFolderExtraction: boolean,
|
|
37
|
+
canUseAIFolderExtractionAgentSelector: boolean,
|
|
37
38
|
isAIFolderExtractionEnabled: boolean,
|
|
38
39
|
isCascadingEnabled: boolean,
|
|
39
40
|
isCascadingOverwritten: boolean,
|
|
40
41
|
isCustomMetadata: boolean,
|
|
42
|
+
isExistingAIExtractionCascadePolicy: boolean,
|
|
41
43
|
onAIFolderExtractionToggle: (value: boolean) => void,
|
|
42
44
|
onCascadeModeChange: (value: boolean) => void,
|
|
43
45
|
onCascadeToggle: (value: boolean) => void,
|
|
@@ -47,10 +49,12 @@ type Props = {
|
|
|
47
49
|
const CascadePolicy = ({
|
|
48
50
|
canEdit,
|
|
49
51
|
canUseAIFolderExtraction,
|
|
52
|
+
canUseAIFolderExtractionAgentSelector,
|
|
50
53
|
isCascadingEnabled,
|
|
51
54
|
isCascadingOverwritten,
|
|
52
55
|
isCustomMetadata,
|
|
53
56
|
isAIFolderExtractionEnabled,
|
|
57
|
+
isExistingAIExtractionCascadePolicy,
|
|
54
58
|
onAIFolderExtractionToggle,
|
|
55
59
|
onCascadeToggle,
|
|
56
60
|
onCascadeModeChange,
|
|
@@ -65,7 +69,7 @@ const CascadePolicy = ({
|
|
|
65
69
|
return canEdit ? (
|
|
66
70
|
<>
|
|
67
71
|
<div className="metadata-cascade-editor">
|
|
68
|
-
<div className="metadata-cascade-enable">
|
|
72
|
+
<div className="metadata-cascade-enable" data-testid="metadata-cascade-enable">
|
|
69
73
|
<div>
|
|
70
74
|
<FormattedMessage tagName="strong" {...messages.enableCascadePolicy} />
|
|
71
75
|
{!isCustomMetadata && (
|
|
@@ -131,6 +135,7 @@ const CascadePolicy = ({
|
|
|
131
135
|
<Toggle
|
|
132
136
|
className="metadata-cascade-toggle"
|
|
133
137
|
isOn={isAIFolderExtractionEnabled}
|
|
138
|
+
isDisabled={isExistingAIExtractionCascadePolicy}
|
|
134
139
|
label=""
|
|
135
140
|
onChange={e => onAIFolderExtractionToggle(e.target.checked)}
|
|
136
141
|
/>
|
|
@@ -142,17 +147,19 @@ const CascadePolicy = ({
|
|
|
142
147
|
<FormattedMessage {...messages.aiAutofillLearnMore} />
|
|
143
148
|
</Link>
|
|
144
149
|
</div>
|
|
145
|
-
|
|
146
|
-
<
|
|
147
|
-
<
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
{canUseAIFolderExtractionAgentSelector && (
|
|
151
|
+
<div className="metadata-cascade-ai-agent-selector">
|
|
152
|
+
<TooltipProvider>
|
|
153
|
+
<BoxAiAgentSelector
|
|
154
|
+
agents={agents}
|
|
155
|
+
onErrorAction={() => {}}
|
|
156
|
+
requestState="success"
|
|
157
|
+
selectedAgent={agents[0]}
|
|
158
|
+
variant="sidebar"
|
|
159
|
+
/>
|
|
160
|
+
</TooltipProvider>
|
|
161
|
+
</div>
|
|
162
|
+
)}
|
|
156
163
|
<InlineNotice className="metadata-cascade-ai-notice" variant="info">
|
|
157
164
|
<FormattedMessage
|
|
158
165
|
{...messages.aiAutofillNotice}
|
|
@@ -24,7 +24,7 @@ import MetadataInstanceConfirmDialog from './MetadataInstanceConfirmDialog';
|
|
|
24
24
|
import Footer from './Footer';
|
|
25
25
|
import messages from './messages';
|
|
26
26
|
import { FIELD_TYPE_FLOAT, FIELD_TYPE_INTEGER } from '../metadata-instance-fields/constants';
|
|
27
|
-
import TEMPLATE_CUSTOM_PROPERTIES from './constants';
|
|
27
|
+
import { CASCADE_POLICY_TYPE_AI_EXTRACT, TEMPLATE_CUSTOM_PROPERTIES } from './constants';
|
|
28
28
|
import {
|
|
29
29
|
JSON_PATCH_OP_REMOVE,
|
|
30
30
|
JSON_PATCH_OP_ADD,
|
|
@@ -48,6 +48,7 @@ import './Instance.scss';
|
|
|
48
48
|
type Props = {
|
|
49
49
|
canEdit: boolean,
|
|
50
50
|
canUseAIFolderExtraction?: boolean,
|
|
51
|
+
canUseAIFolderExtractionAgentSelector?: boolean,
|
|
51
52
|
cascadePolicy?: MetadataCascadePolicy, // eslint-disable-line
|
|
52
53
|
data: MetadataFields,
|
|
53
54
|
hasError: boolean,
|
|
@@ -210,7 +211,13 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
210
211
|
isCascadingPolicyApplicable,
|
|
211
212
|
onSave,
|
|
212
213
|
}: Props = this.props;
|
|
213
|
-
const {
|
|
214
|
+
const {
|
|
215
|
+
data: currentData,
|
|
216
|
+
errors,
|
|
217
|
+
isAIFolderExtractionEnabled,
|
|
218
|
+
isCascadingEnabled,
|
|
219
|
+
isCascadingOverwritten,
|
|
220
|
+
}: State = this.state;
|
|
214
221
|
|
|
215
222
|
if (!this.isEditing() || !isDirty || !onSave || Object.keys(errors).length) {
|
|
216
223
|
return;
|
|
@@ -219,7 +226,8 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
219
226
|
this.setState({
|
|
220
227
|
isBusy: true,
|
|
221
228
|
isEditing: false,
|
|
222
|
-
|
|
229
|
+
// reset state if cascading policy is removed
|
|
230
|
+
isAIFolderExtractionEnabled: isCascadingEnabled ? isAIFolderExtractionEnabled : false,
|
|
223
231
|
});
|
|
224
232
|
onSave(
|
|
225
233
|
id,
|
|
@@ -230,6 +238,7 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
230
238
|
id: cascadePolicy ? cascadePolicy.id : undefined,
|
|
231
239
|
isEnabled: isCascadingEnabled,
|
|
232
240
|
overwrite: isCascadingOverwritten,
|
|
241
|
+
isAIFolderExtractionEnabled,
|
|
233
242
|
}
|
|
234
243
|
: undefined,
|
|
235
244
|
cloneDeep(currentData),
|
|
@@ -339,12 +348,12 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
339
348
|
* @return {Object} - react state
|
|
340
349
|
*/
|
|
341
350
|
getState(props: Props): State {
|
|
342
|
-
const isCascadingEnabled = this.
|
|
351
|
+
const isCascadingEnabled = this.isCascadingEnabledThroughProps(props);
|
|
343
352
|
|
|
344
353
|
return {
|
|
345
354
|
data: cloneDeep(props.data),
|
|
346
355
|
errors: {},
|
|
347
|
-
isAIFolderExtractionEnabled:
|
|
356
|
+
isAIFolderExtractionEnabled: this.isAIFolderExtractionEnabledThroughProps(props),
|
|
348
357
|
isBusy: false,
|
|
349
358
|
isCascadingEnabled,
|
|
350
359
|
isCascadingOverwritten: false,
|
|
@@ -420,13 +429,16 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
420
429
|
*/
|
|
421
430
|
setDirty = (type?: string): void => {
|
|
422
431
|
const { id, isCascadingPolicyApplicable, onModification }: Props = this.props;
|
|
423
|
-
const { data, isCascadingEnabled, isCascadingOverwritten } = this.state;
|
|
432
|
+
const { data, isCascadingEnabled, isCascadingOverwritten, isAIFolderExtractionEnabled } = this.state;
|
|
424
433
|
const hasDataChanged = !isEqual(data, this.props.data);
|
|
425
434
|
let hasCascadingChanged = false;
|
|
426
435
|
|
|
427
436
|
if (isCascadingPolicyApplicable) {
|
|
428
437
|
// isCascadingOverwritten always starts out as false, so true signifies a change
|
|
429
|
-
hasCascadingChanged =
|
|
438
|
+
hasCascadingChanged =
|
|
439
|
+
isCascadingOverwritten ||
|
|
440
|
+
isCascadingEnabled !== this.isCascadingEnabledThroughProps(this.props) ||
|
|
441
|
+
isAIFolderExtractionEnabled !== this.isAIFolderExtractionEnabledThroughProps(this.props);
|
|
430
442
|
}
|
|
431
443
|
|
|
432
444
|
// Callback to parent to tell that something is dirty
|
|
@@ -442,19 +454,30 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
442
454
|
fieldKeyToTypeMap: Object;
|
|
443
455
|
|
|
444
456
|
/**
|
|
445
|
-
* Determines if cascading policy is enabled based on
|
|
457
|
+
* Determines if cascading policy is enabled through props based on
|
|
446
458
|
* whether it has an id or not.
|
|
447
459
|
*
|
|
448
460
|
* @param {Object} props - component props
|
|
449
461
|
* @return {boolean} true if cascading policy is enabled
|
|
450
462
|
*/
|
|
451
|
-
|
|
463
|
+
isCascadingEnabledThroughProps(props: Props) {
|
|
452
464
|
if (props.cascadePolicy) {
|
|
453
465
|
return !!props.cascadePolicy.id;
|
|
454
466
|
}
|
|
455
467
|
return false;
|
|
456
468
|
}
|
|
457
469
|
|
|
470
|
+
/**
|
|
471
|
+
* Determines if ai extraction is enabled based on
|
|
472
|
+
* if cascade policy type is ai_extract
|
|
473
|
+
*
|
|
474
|
+
* @param {Object} props - component props
|
|
475
|
+
* @return {boolean} true if ai extraction is enabled
|
|
476
|
+
*/
|
|
477
|
+
isAIFolderExtractionEnabledThroughProps({ cascadePolicy }: Props) {
|
|
478
|
+
return cascadePolicy?.cascadePolicyType === CASCADE_POLICY_TYPE_AI_EXTRACT;
|
|
479
|
+
}
|
|
480
|
+
|
|
458
481
|
/**
|
|
459
482
|
* Toggles the edit mode
|
|
460
483
|
*
|
|
@@ -590,6 +613,7 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
590
613
|
render() {
|
|
591
614
|
const {
|
|
592
615
|
canUseAIFolderExtraction = false,
|
|
616
|
+
canUseAIFolderExtractionAgentSelector = false,
|
|
593
617
|
cascadePolicy = {},
|
|
594
618
|
isDirty,
|
|
595
619
|
isCascadingPolicyApplicable,
|
|
@@ -617,6 +641,9 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
617
641
|
// Animate short and tall cards at consistent speeds.
|
|
618
642
|
const animationDuration = (fields.length + 1) * 50;
|
|
619
643
|
|
|
644
|
+
const isExistingAIExtractionCascadePolicy =
|
|
645
|
+
this.isCascadingEnabledThroughProps(this.props) && this.isAIFolderExtractionEnabledThroughProps(this.props);
|
|
646
|
+
|
|
620
647
|
return (
|
|
621
648
|
<div ref={this.collapsibleRef}>
|
|
622
649
|
<Collapsible
|
|
@@ -647,10 +674,14 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
647
674
|
<CascadePolicy
|
|
648
675
|
canEdit={isEditing && !!cascadePolicy.canEdit}
|
|
649
676
|
canUseAIFolderExtraction={canUseAIFolderExtraction}
|
|
677
|
+
canUseAIFolderExtractionAgentSelector={
|
|
678
|
+
canUseAIFolderExtractionAgentSelector
|
|
679
|
+
}
|
|
650
680
|
isAIFolderExtractionEnabled={isAIFolderExtractionEnabled}
|
|
651
681
|
isCascadingEnabled={isCascadingEnabled}
|
|
652
682
|
isCascadingOverwritten={isCascadingOverwritten}
|
|
653
683
|
isCustomMetadata={isProperties}
|
|
684
|
+
isExistingAIExtractionCascadePolicy={isExistingAIExtractionCascadePolicy}
|
|
654
685
|
onAIFolderExtractionToggle={this.onAIFolderExtractionToggle}
|
|
655
686
|
onCascadeModeChange={this.onCascadeModeChange}
|
|
656
687
|
onCascadeToggle={this.onCascadeToggle}
|
|
@@ -669,6 +700,7 @@ class Instance extends React.PureComponent<Props, State> {
|
|
|
669
700
|
canEdit={isEditing}
|
|
670
701
|
data={data}
|
|
671
702
|
errors={errors}
|
|
703
|
+
isDisabled={isAIFolderExtractionEnabled}
|
|
672
704
|
onFieldChange={this.onFieldChange}
|
|
673
705
|
onFieldRemove={this.onFieldRemove}
|
|
674
706
|
template={template}
|
|
@@ -7,6 +7,7 @@ import type { JSONPatchOperations } from '../../common/types/api';
|
|
|
7
7
|
|
|
8
8
|
type Props = {
|
|
9
9
|
canUseAIFolderExtraction?: boolean,
|
|
10
|
+
canUseAIFolderExtractionAgentSelector?: boolean,
|
|
10
11
|
editors?: Array<MetadataEditor>,
|
|
11
12
|
isCascadingPolicyApplicable?: boolean,
|
|
12
13
|
onModification?: (id: string, isDirty: boolean) => void,
|
|
@@ -22,6 +23,7 @@ type Props = {
|
|
|
22
23
|
|
|
23
24
|
const Instances = ({
|
|
24
25
|
canUseAIFolderExtraction = false,
|
|
26
|
+
canUseAIFolderExtractionAgentSelector = false,
|
|
25
27
|
isCascadingPolicyApplicable = false,
|
|
26
28
|
editors = [],
|
|
27
29
|
onModification,
|
|
@@ -37,6 +39,7 @@ const Instances = ({
|
|
|
37
39
|
<Instance
|
|
38
40
|
canEdit={instance.canEdit}
|
|
39
41
|
canUseAIFolderExtraction={canUseAIFolderExtraction}
|
|
42
|
+
canUseAIFolderExtractionAgentSelector={canUseAIFolderExtractionAgentSelector}
|
|
40
43
|
cascadePolicy={instance.cascadePolicy}
|
|
41
44
|
data={instance.data}
|
|
42
45
|
hasError={hasError}
|
|
@@ -15,6 +15,7 @@ type Props = {
|
|
|
15
15
|
blurExceptionClassNames?: Array<string>,
|
|
16
16
|
canAdd: boolean,
|
|
17
17
|
canUseAIFolderExtraction?: boolean,
|
|
18
|
+
canUseAIFolderExtractionAgentSelector?: boolean,
|
|
18
19
|
editors?: Array<MetadataEditor>,
|
|
19
20
|
isCascadingPolicyApplicable?: boolean,
|
|
20
21
|
isDropdownBusy?: boolean,
|
|
@@ -37,6 +38,7 @@ const MetadataInstanceEditor = ({
|
|
|
37
38
|
blurExceptionClassNames,
|
|
38
39
|
canAdd,
|
|
39
40
|
canUseAIFolderExtraction = false,
|
|
41
|
+
canUseAIFolderExtractionAgentSelector = false,
|
|
40
42
|
isCascadingPolicyApplicable = false,
|
|
41
43
|
isDropdownBusy,
|
|
42
44
|
editors = [],
|
|
@@ -64,6 +66,7 @@ const MetadataInstanceEditor = ({
|
|
|
64
66
|
<ScrollWrapper>
|
|
65
67
|
<Instances
|
|
66
68
|
canUseAIFolderExtraction={canUseAIFolderExtraction}
|
|
69
|
+
canUseAIFolderExtractionAgentSelector={canUseAIFolderExtractionAgentSelector}
|
|
67
70
|
editors={editors}
|
|
68
71
|
isCascadingPolicyApplicable={isCascadingPolicyApplicable}
|
|
69
72
|
onModification={onModification}
|
|
@@ -13,7 +13,7 @@ import { Flyout, Overlay } from '../../components/flyout';
|
|
|
13
13
|
|
|
14
14
|
import MenuToggle from '../../components/dropdown-menu/MenuToggle';
|
|
15
15
|
import messages from './messages';
|
|
16
|
-
import TEMPLATE_CUSTOM_PROPERTIES from './constants';
|
|
16
|
+
import { TEMPLATE_CUSTOM_PROPERTIES } from './constants';
|
|
17
17
|
import type { MetadataTemplate } from '../../common/types/metadata';
|
|
18
18
|
import './TemplateDropdown.scss';
|
|
19
19
|
|
|
@@ -13,12 +13,21 @@ type Props = {
|
|
|
13
13
|
canEdit: boolean,
|
|
14
14
|
data: MetadataFields,
|
|
15
15
|
errors: { [string]: React.Node },
|
|
16
|
+
isDisabled?: boolean,
|
|
16
17
|
onFieldChange?: (key: string, value: MetadataFieldValue, type: string) => void,
|
|
17
18
|
onFieldRemove?: (key: string) => void,
|
|
18
19
|
template: MetadataTemplate,
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
const TemplatedInstance = ({
|
|
22
|
+
const TemplatedInstance = ({
|
|
23
|
+
canEdit,
|
|
24
|
+
data = {},
|
|
25
|
+
errors,
|
|
26
|
+
isDisabled,
|
|
27
|
+
onFieldChange,
|
|
28
|
+
onFieldRemove,
|
|
29
|
+
template,
|
|
30
|
+
}: Props) => {
|
|
22
31
|
const { fields = [] } = template;
|
|
23
32
|
const hasFields = fields.length > 0;
|
|
24
33
|
const hasVisibleFields = hasFields && fields.some(field => !isHidden(field));
|
|
@@ -39,6 +48,7 @@ const TemplatedInstance = ({ canEdit, data = {}, errors, onFieldChange, onFieldR
|
|
|
39
48
|
description={field.description}
|
|
40
49
|
displayName={field.displayName}
|
|
41
50
|
error={errors[field.key]}
|
|
51
|
+
isDisabled={isDisabled}
|
|
42
52
|
isHidden={isHidden(field)} // Checking both isHidden and hidden attributes due to differences in V2 and V3 APIs
|
|
43
53
|
onChange={(key: string, value: MetadataFieldValue) => {
|
|
44
54
|
if (canEdit && onFieldChange) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
|
|
3
5
|
import { screen, render, within } from '../../../test-utils/testing-library';
|
|
4
6
|
|
|
5
7
|
import CascadePolicy from '../CascadePolicy';
|
|
@@ -95,8 +97,97 @@ describe('features/metadata-instance-editor/CascadePolicy', () => {
|
|
|
95
97
|
|
|
96
98
|
describe('AI Agent Selector', () => {
|
|
97
99
|
test('should render AI agent selector with default to basic when AI features are enabled', () => {
|
|
98
|
-
render(
|
|
100
|
+
render(
|
|
101
|
+
<CascadePolicy
|
|
102
|
+
canEdit
|
|
103
|
+
canUseAIFolderExtraction
|
|
104
|
+
canUseAIFolderExtractionAgentSelector
|
|
105
|
+
shouldShowCascadeOptions
|
|
106
|
+
/>,
|
|
107
|
+
);
|
|
99
108
|
expect(screen.getByRole('button', { name: 'Agent Basic' })).toBeInTheDocument();
|
|
100
109
|
});
|
|
110
|
+
|
|
111
|
+
test('should not render AI agent selector when canUseAIFolderExtractionAgentSelector is false', () => {
|
|
112
|
+
render(<CascadePolicy canEdit canUseAIFolderExtraction shouldShowCascadeOptions />);
|
|
113
|
+
expect(screen.queryByRole('button', { name: 'Agent Basic' })).not.toBeInTheDocument();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('AI Autofill Toggle', () => {
|
|
118
|
+
test('should disable toggle when isExistingAIExtractionCascadePolicy is true', () => {
|
|
119
|
+
render(
|
|
120
|
+
<CascadePolicy
|
|
121
|
+
canEdit
|
|
122
|
+
canUseAIFolderExtraction
|
|
123
|
+
shouldShowCascadeOptions
|
|
124
|
+
isExistingAIExtractionCascadePolicy
|
|
125
|
+
/>,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
129
|
+
const toggle = within(aiSection).getByRole('switch');
|
|
130
|
+
|
|
131
|
+
expect(toggle).toBeDisabled();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('should enable toggle when isExistingAIExtractionCascadePolicy is false', () => {
|
|
135
|
+
render(
|
|
136
|
+
<CascadePolicy
|
|
137
|
+
canEdit
|
|
138
|
+
canUseAIFolderExtraction
|
|
139
|
+
shouldShowCascadeOptions
|
|
140
|
+
isExistingAIExtractionCascadePolicy={false}
|
|
141
|
+
/>,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
145
|
+
const toggle = within(aiSection).getByRole('switch');
|
|
146
|
+
|
|
147
|
+
expect(toggle).not.toBeDisabled();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('should call onAIFolderExtractionToggle when toggle is clicked and enabled', async () => {
|
|
151
|
+
const onAIFolderExtractionToggle = jest.fn();
|
|
152
|
+
|
|
153
|
+
render(
|
|
154
|
+
<CascadePolicy
|
|
155
|
+
canEdit
|
|
156
|
+
canUseAIFolderExtraction
|
|
157
|
+
shouldShowCascadeOptions
|
|
158
|
+
isExistingAIExtractionCascadePolicy={false}
|
|
159
|
+
onAIFolderExtractionToggle={onAIFolderExtractionToggle}
|
|
160
|
+
/>,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
164
|
+
const toggle = within(aiSection).getByRole('switch');
|
|
165
|
+
|
|
166
|
+
await userEvent.click(toggle);
|
|
167
|
+
|
|
168
|
+
expect(onAIFolderExtractionToggle).toHaveBeenCalledTimes(1);
|
|
169
|
+
expect(onAIFolderExtractionToggle).toHaveBeenCalledWith(true);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('should not call onAIFolderExtractionToggle when toggle is clicked but disabled', async () => {
|
|
173
|
+
const onAIFolderExtractionToggle = jest.fn();
|
|
174
|
+
|
|
175
|
+
render(
|
|
176
|
+
<CascadePolicy
|
|
177
|
+
canEdit
|
|
178
|
+
canUseAIFolderExtraction
|
|
179
|
+
shouldShowCascadeOptions
|
|
180
|
+
isExistingAIExtractionCascadePolicy={true}
|
|
181
|
+
onAIFolderExtractionToggle={onAIFolderExtractionToggle}
|
|
182
|
+
/>,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
186
|
+
const toggle = within(aiSection).getByRole('switch');
|
|
187
|
+
|
|
188
|
+
await userEvent.click(toggle);
|
|
189
|
+
|
|
190
|
+
expect(onAIFolderExtractionToggle).not.toHaveBeenCalled();
|
|
191
|
+
});
|
|
101
192
|
});
|
|
102
193
|
});
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { createIntl } from 'react-intl';
|
|
4
|
+
import { render, screen, within } from '../../../test-utils/testing-library';
|
|
5
|
+
import { CASCADE_POLICY_TYPE_AI_EXTRACT, TEMPLATE_CUSTOM_PROPERTIES } from '../constants';
|
|
4
6
|
import { InstanceBase as Instance } from '../Instance';
|
|
5
7
|
import { isValidValue } from '../../metadata-instance-fields/validateMetadataField';
|
|
6
8
|
|
|
9
|
+
// Add RTL imports
|
|
10
|
+
|
|
7
11
|
jest.mock('../../metadata-instance-fields/validateMetadataField');
|
|
8
12
|
|
|
9
13
|
const data = {
|
|
@@ -718,3 +722,204 @@ describe('features/metadata-instance-editor/fields/Instance', () => {
|
|
|
718
722
|
});
|
|
719
723
|
});
|
|
720
724
|
});
|
|
725
|
+
|
|
726
|
+
// New RTL tests
|
|
727
|
+
const testFields = [
|
|
728
|
+
{
|
|
729
|
+
id: 'field1',
|
|
730
|
+
type: 'string',
|
|
731
|
+
key: 'stringfield',
|
|
732
|
+
displayName: 'String Field',
|
|
733
|
+
description: 'example of a string field',
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
id: 'field2',
|
|
737
|
+
type: 'float',
|
|
738
|
+
key: 'floatfield',
|
|
739
|
+
displayName: 'Float Field',
|
|
740
|
+
description: 'example of a float field',
|
|
741
|
+
},
|
|
742
|
+
];
|
|
743
|
+
|
|
744
|
+
const testData = {
|
|
745
|
+
stringfield: 'some string',
|
|
746
|
+
floatfield: 1.0,
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
const getBaseProps = (props = {}) => ({
|
|
750
|
+
id: 'test-instance',
|
|
751
|
+
canEdit: true,
|
|
752
|
+
data: { ...testData },
|
|
753
|
+
template: {
|
|
754
|
+
id: 'template-1',
|
|
755
|
+
displayName: 'Test Template',
|
|
756
|
+
fields: [...testFields],
|
|
757
|
+
templateKey: 'testTemplateKey',
|
|
758
|
+
},
|
|
759
|
+
intl: createIntl({ locale: 'en' }),
|
|
760
|
+
onSave: jest.fn(),
|
|
761
|
+
onModification: jest.fn(),
|
|
762
|
+
onRemove: jest.fn(),
|
|
763
|
+
isDirty: false,
|
|
764
|
+
hasError: false,
|
|
765
|
+
isCascadingPolicyApplicable: true,
|
|
766
|
+
cascadePolicy: {
|
|
767
|
+
id: 'policy-1',
|
|
768
|
+
canEdit: true,
|
|
769
|
+
isEnabled: true,
|
|
770
|
+
scope: 'enterprise_123',
|
|
771
|
+
cascadePolicyType: 'regular', // default to non-AI
|
|
772
|
+
},
|
|
773
|
+
canUseAIFolderExtraction: true, // Assume feature flag is on
|
|
774
|
+
canUseAIFolderExtractionAgentSelector: false,
|
|
775
|
+
...props,
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
describe('Instance Component - React Testing Library', () => {
|
|
779
|
+
beforeEach(() => {
|
|
780
|
+
jest.clearAllMocks();
|
|
781
|
+
isValidValue.mockReturnValue(true); // Default mock for isValidValue
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
describe('Initialization based on cascadePolicy.cascadePolicyType', () => {
|
|
785
|
+
test('should initialize with AI folder extraction enabled and fields disabled if cascadePolicyType is "ai_extract"', async () => {
|
|
786
|
+
render(
|
|
787
|
+
<Instance
|
|
788
|
+
{...getBaseProps({
|
|
789
|
+
cascadePolicy: {
|
|
790
|
+
id: 'policy-ai',
|
|
791
|
+
canEdit: true,
|
|
792
|
+
isEnabled: true,
|
|
793
|
+
scope: 'enterprise_123',
|
|
794
|
+
cascadePolicyType: CASCADE_POLICY_TYPE_AI_EXTRACT,
|
|
795
|
+
},
|
|
796
|
+
})}
|
|
797
|
+
/>,
|
|
798
|
+
);
|
|
799
|
+
|
|
800
|
+
// Click Edit button to enable editing
|
|
801
|
+
const editButton = screen.getByRole('button', { name: 'Edit Metadata' }); // Assuming 'Edit Metadata' is the rendered name
|
|
802
|
+
await userEvent.click(editButton);
|
|
803
|
+
|
|
804
|
+
// Fields should be disabled because AI extraction is on by default from policy
|
|
805
|
+
// Input fields are part of TemplatedInstance, which is only rendered if Collapsible is open.
|
|
806
|
+
// Default state has isOpen true if not specified or based on single field length.
|
|
807
|
+
// Let's assume it's open.
|
|
808
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).toBeDisabled();
|
|
809
|
+
expect(screen.getByRole('textbox', { name: 'Float Field example of a float field' })).toBeDisabled();
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
test('should initialize with AI folder extraction disabled and fields enabled if cascadePolicyType is not "ai_extract"', async () => {
|
|
813
|
+
render(<Instance {...getBaseProps()} />); // default policy is not 'ai_extract'
|
|
814
|
+
|
|
815
|
+
// Click Edit button to enable editing
|
|
816
|
+
const editButton = screen.getByRole('button', { name: 'Edit Metadata' }); // Assuming 'Edit Metadata' is the rendered name
|
|
817
|
+
await userEvent.click(editButton);
|
|
818
|
+
|
|
819
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).not.toBeDisabled();
|
|
820
|
+
expect(screen.getByRole('textbox', { name: 'Float Field example of a float field' })).not.toBeDisabled();
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
test('should initialize with AI folder extraction disabled if cascadePolicy is undefined', async () => {
|
|
824
|
+
render(<Instance {...getBaseProps({ cascadePolicy: undefined, isCascadingPolicyApplicable: false })} />);
|
|
825
|
+
|
|
826
|
+
// Click Edit button to enable editing
|
|
827
|
+
const editButton = screen.getByRole('button', { name: 'Edit Metadata' }); // Assuming 'Edit Metadata' is the rendered name
|
|
828
|
+
await userEvent.click(editButton);
|
|
829
|
+
|
|
830
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).not.toBeDisabled();
|
|
831
|
+
expect(screen.getByRole('textbox', { name: 'Float Field example of a float field' })).not.toBeDisabled();
|
|
832
|
+
});
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
describe('AI Folder Extraction Toggle Interaction', () => {
|
|
836
|
+
test('should toggle AI folder extraction, disable/enable fields', async () => {
|
|
837
|
+
render(<Instance {...getBaseProps()} />);
|
|
838
|
+
|
|
839
|
+
// Click Edit button to enable editing
|
|
840
|
+
const editButton = screen.getByRole('button', { name: 'Edit Metadata' }); // Assuming 'Edit Metadata' is the rendered name
|
|
841
|
+
await userEvent.click(editButton);
|
|
842
|
+
|
|
843
|
+
// Initially, fields are enabled as default policy is not 'ai_extract'
|
|
844
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).not.toBeDisabled();
|
|
845
|
+
|
|
846
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
847
|
+
const aiToggle = within(aiSection).getByRole('switch');
|
|
848
|
+
|
|
849
|
+
// Turn AI toggle ON
|
|
850
|
+
await userEvent.click(aiToggle);
|
|
851
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).toBeDisabled();
|
|
852
|
+
|
|
853
|
+
// Turn AI toggle OFF
|
|
854
|
+
await userEvent.click(aiToggle);
|
|
855
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).not.toBeDisabled();
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
describe('Props passed to CascadePolicy', () => {
|
|
860
|
+
test('should pass canUseAIFolderExtractionAgentSelector to CascadePolicy', async () => {
|
|
861
|
+
render(<Instance {...getBaseProps({ canUseAIFolderExtractionAgentSelector: true })} />);
|
|
862
|
+
|
|
863
|
+
const editButton = screen.queryByRole('button', { name: 'Edit Metadata' });
|
|
864
|
+
if (editButton) await userEvent.click(editButton); // Enter edit mode to ensure CascadePolicy options are visible
|
|
865
|
+
|
|
866
|
+
expect(screen.getByRole('button', { name: 'Agent Basic' })).toBeInTheDocument();
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
test('should pass isExistingAIExtractionCascadePolicy=true to CascadePolicy if policy is ai_extract', async () => {
|
|
870
|
+
render(
|
|
871
|
+
<Instance
|
|
872
|
+
{...getBaseProps({
|
|
873
|
+
cascadePolicy: {
|
|
874
|
+
id: 'policy-ai',
|
|
875
|
+
canEdit: true,
|
|
876
|
+
isEnabled: true,
|
|
877
|
+
scope: 'enterprise_123',
|
|
878
|
+
cascadePolicyType: CASCADE_POLICY_TYPE_AI_EXTRACT,
|
|
879
|
+
},
|
|
880
|
+
})}
|
|
881
|
+
/>,
|
|
882
|
+
);
|
|
883
|
+
const editButton = screen.queryByRole('button', { name: 'Edit Metadata' });
|
|
884
|
+
if (editButton) await userEvent.click(editButton);
|
|
885
|
+
|
|
886
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
887
|
+
const aiToggle = within(aiSection).getByRole('switch');
|
|
888
|
+
expect(aiToggle).toBeDisabled();
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
test('should pass isExistingAIExtractionCascadePolicy=false to CascadePolicy if policy is not ai_extract', async () => {
|
|
892
|
+
render(<Instance {...getBaseProps()} />);
|
|
893
|
+
const editButton = screen.queryByRole('button', { name: 'Edit Metadata' });
|
|
894
|
+
if (editButton) await userEvent.click(editButton);
|
|
895
|
+
|
|
896
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
897
|
+
const aiToggle = within(aiSection).getByRole('switch');
|
|
898
|
+
expect(aiToggle).not.toBeDisabled();
|
|
899
|
+
});
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
describe('Props passed to TemplatedInstance', () => {
|
|
903
|
+
test('should pass isDisabled=true to TemplatedInstance when AI folder extraction is enabled', async () => {
|
|
904
|
+
render(<Instance {...getBaseProps()} />);
|
|
905
|
+
const editButton = screen.getByRole('button', { name: 'Edit Metadata' });
|
|
906
|
+
await userEvent.click(editButton);
|
|
907
|
+
|
|
908
|
+
const aiSection = screen.getByTestId('ai-folder-extraction');
|
|
909
|
+
const aiToggle = within(aiSection).getByRole('switch');
|
|
910
|
+
|
|
911
|
+
await userEvent.click(aiToggle); // Turn AI ON
|
|
912
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).toBeDisabled();
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
test('should pass isDisabled=false to TemplatedInstance when AI folder extraction is disabled', async () => {
|
|
916
|
+
render(<Instance {...getBaseProps()} />);
|
|
917
|
+
const editButton = screen.queryByRole('button', { name: 'Edit Metadata' });
|
|
918
|
+
// If instance starts in non-edit mode, fields might not be interactive until edit is clicked
|
|
919
|
+
if (editButton) await userEvent.click(editButton);
|
|
920
|
+
|
|
921
|
+
// AI is off by default
|
|
922
|
+
expect(screen.getByRole('textbox', { name: 'String Field example of a string field' })).not.toBeDisabled();
|
|
923
|
+
});
|
|
924
|
+
});
|
|
925
|
+
});
|