Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/api/__tests__/Metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,34 @@ describe('api/Metadata', () => {
expect(result.fields[0].isExtracted).toBe(true);
});

test('should set isExtracted when process is the legacy AI Extract value and isBoundingBoxOrConfidenceScoreReviewEnabled is true', () => {
const instance = {
$id: '321',
$template: '',
$canEdit: true,
testStringField: {
values: 'California',
details: {
process: 'AI Extract',
},
},
};
const template = {
displayName: 'Test template',
fields: [
{ description: 'Test', displayName: 'Test field', id: '1', key: 'testStringField', type: 'string' },
],
id: '123456',
templateKey: 'instance_from_template',
scope: 'enterprise',
};

const result = metadata.createTemplateInstance(instance, template, true, false, true);

expect(result.fields[0].value).toBe('California');
expect(result.fields[0].isExtracted).toBe(true);
});

test('should not set isExtracted when process is not AI_EXTRACTED', () => {
const instance = {
$id: '321',
Expand Down
8 changes: 8 additions & 0 deletions src/api/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ describe('api/utils', () => {
expect(checkIsExtractedProcessFieldValue(fieldValue)).toBe(true);
});

test('should return true when process is the legacy AI Extract value', () => {
const fieldValue = {
values: 'California',
details: { process: 'AI Extract' },
};
expect(checkIsExtractedProcessFieldValue(fieldValue)).toBe(true);
});

test('should return false when process is not AI_EXTRACTED', () => {
const fieldValue = {
values: 'California',
Expand Down
8 changes: 6 additions & 2 deletions src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
} from '../common/types/metadata';
import { FIELD_TYPE_TAXONOMY } from '../features/metadata-instance-fields/constants';

import { AI_EXTRACTED_PROCESS, AI_ACCEPTED_PROCESS } from '../constants';
import { AI_EXTRACTED_PROCESS, AI_EXTRACTED_PROCESS_LEGACY, AI_ACCEPTED_PROCESS } from '../constants';

/**
* Formats comment data (including replies) for use in components.
Expand Down Expand Up @@ -104,7 +104,11 @@ const checkIsExtractedProcessFieldValue = (fieldValue: any): boolean => {

const { details } = ((fieldValue: any): MetadataDetailedFieldValue);

return details != null && typeof details.process === 'string' && details.process === AI_EXTRACTED_PROCESS;
return (
details != null &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
details != null &&
details !== null &&

typeof details.process === 'string' &&
(details.process === AI_EXTRACTED_PROCESS || details.process === AI_EXTRACTED_PROCESS_LEGACY)
);
};

const mergeDetailedAndHydratedInstances = (
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ export const SIDEBAR_VIEW_VERSIONS: 'versions' = 'versions';
export const SIDEBAR_VIEW_DOCGEN: 'docgen' = 'docgen';
export const AI_ACCEPTED_PROCESS: 'AI_ACCEPTED' = 'AI_ACCEPTED';
export const AI_EXTRACTED_PROCESS: 'AI_EXTRACTED' = 'AI_EXTRACTED';
export const AI_EXTRACTED_PROCESS_LEGACY: 'AI Extract' = 'AI Extract';

/* ------------------ HTTP Requests ---------------------- */
export const HTTP_GET: 'GET' = 'GET';
Expand Down
Loading