Skip to content
Merged
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@
"@box/frontend": "^11.0.1",
"@box/item-icon": "^2.37.5",
"@box/languages": "^1.0.0",
"@box/metadata-editor": "^1.69.6",
"@box/metadata-editor": "^1.73.4",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"@box/metadata-filter": "^1.80.23",
"@box/metadata-template-browser": "^1.24.11",
"@box/metadata-view": "^1.53.26",
"@box/react-virtualized": "^9.22.3-rc-box.10",
"@box/readable-time": "^1.43.13",
Expand Down Expand Up @@ -305,8 +306,9 @@
"@box/content-field": "^1.40.23",
"@box/copy-input": "^1.42.16",
"@box/item-icon": "^2.37.5",
"@box/metadata-editor": "^1.69.6",
"@box/metadata-editor": "^1.73.4",
"@box/metadata-filter": "^1.80.23",
"@box/metadata-template-browser": "^1.24.11",
Comment thread
dlasecki-box marked this conversation as resolved.
"@box/metadata-view": "^1.53.26",
"@box/react-virtualized": "^9.22.3-rc-box.10",
"@box/readable-time": "^1.43.13",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'@box/item-icon',
'@box/metadata-editor',
'@box/metadata-filter',
'@box/metadata-template-browser',
'@box/metadata-view',
'@box/unified-share-modal',
'@box/user-selector',
Expand Down
2 changes: 1 addition & 1 deletion scripts/jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ module.exports = {
testMatch: ['**/__tests__/**/*.test.+(js|jsx|ts|tsx)'],
testPathIgnorePatterns: ['stories.test.js$', 'stories.test.tsx$', 'stories.test.d.ts'],
transformIgnorePatterns: [
'node_modules/(?!(@box/activity-feed|@box/collaboration-popover|@box/react-virtualized/dist/es|@box/cldr-data|@box/blueprint-web|@box/blueprint-web-assets|@box/metadata-editor|@box/box-ai-content-answers|@box/box-ai-agent-selector|@box/item-icon|@box/combobox-with-api|@box/tree|@box/metadata-filter|@box/metadata-view|@box/content-field|@box/types|@box/box-item-type-selector|@box/unified-share-modal|@box/user-selector|@box/copy-input|@box/readable-time|@box/threaded-annotations|@box/uploads-manager)/)',
'node_modules/(?!(@box/activity-feed|@box/collaboration-popover|@box/react-virtualized/dist/es|@box/cldr-data|@box/blueprint-web|@box/blueprint-web-assets|@box/metadata-editor|@box/metadata-template-browser|@box/box-ai-content-answers|@box/box-ai-agent-selector|@box/item-icon|@box/combobox-with-api|@box/tree|@box/metadata-filter|@box/metadata-view|@box/content-field|@box/types|@box/box-item-type-selector|@box/unified-share-modal|@box/user-selector|@box/copy-input|@box/readable-time|@box/threaded-annotations|@box/uploads-manager)/)',
],
};
72 changes: 45 additions & 27 deletions src/api/Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import uniqueId from 'lodash/uniqueId';
import { getBadItemError, getBadPermissionsError, isUserCorrectableError } from '../utils/error';
import { getTypedFileId, getTypedFolderId } from '../utils/file';
import {
checkIsExtractedProcessFieldValue,
extractDetailedFieldValue,
formatMetadataFieldValue,
handleOnAbort,
Expand All @@ -27,6 +28,7 @@ import {
import File from './File';
import {
AI_ACCEPTED_PROCESS,
AI_EXTRACTED_PROCESS,
HEADER_CONTENT_TYPE,
METADATA_SCOPE_ENTERPRISE,
METADATA_SCOPE_GLOBAL,
Expand Down Expand Up @@ -459,20 +461,20 @@ class Metadata extends File {
*
* @param {string} id - file id
* @param {boolean} isMetadataRedesign - feature flag
* @param {boolean} isConfidenceScoreEnabled - whether to fetch detailed view with confidence scores
* @param {boolean} isBoundingBoxOrConfidenceScoreReviewEnabled - whether to fetch detailed view
* @return {Object} array of metadata instances
*/
async getInstances(
id: string,
isMetadataRedesign: boolean = false,
isConfidenceScoreEnabled: boolean = false,
isBoundingBoxOrConfidenceScoreReviewEnabled: boolean = false,
): Promise<Array<MetadataInstanceV2>> {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
this.errorCode = ERROR_CODE_FETCH_METADATA;

const baseUrl = this.getMetadataUrl(id);
const requestId = getTypedFileId(id);

if (isMetadataRedesign && isConfidenceScoreEnabled) {
if (isMetadataRedesign && isBoundingBoxOrConfidenceScoreReviewEnabled) {
return this.getDetailedInstancesWithHydratedTaxonomy(baseUrl, requestId);
}

Expand Down Expand Up @@ -616,7 +618,7 @@ class Metadata extends File {
template: MetadataTemplate,
canEdit: boolean,
isExternallyOwned: boolean = false,
isConfidenceScoreEnabled: boolean = false,
isBoundingBoxOrConfidenceScoreReviewEnabled: boolean = false,
): MetadataTemplateInstance {
const fields: MetadataTemplateInstanceField[] = [];

Expand All @@ -635,7 +637,7 @@ class Metadata extends File {
value,
};

if (isConfidenceScoreEnabled) {
if (isBoundingBoxOrConfidenceScoreReviewEnabled) {
const confidenceScore = mapDetailedFieldToConfidenceScore(rawValue);
if (confidenceScore) {
fieldEntry.confidenceScore = confidenceScore;
Expand All @@ -645,6 +647,10 @@ class Metadata extends File {
if (targetLocation) {
fieldEntry.targetLocation = targetLocation;
}

if (checkIsExtractedProcessFieldValue(rawValue)) {
fieldEntry.isExtracted = true;
}
}

fields.push(fieldEntry);
Expand Down Expand Up @@ -693,7 +699,7 @@ class Metadata extends File {
enterpriseTemplates: Array<MetadataTemplate>,
globalTemplates: Array<MetadataTemplate>,
canEdit: boolean,
isConfidenceScoreEnabled: boolean = false,
isBoundingBoxOrConfidenceScoreReviewEnabled: boolean = false,
): Promise<Array<MetadataTemplateInstance>> {
// Get all usable templates for metadata instances
const templates: Array<MetadataTemplate> = [customPropertiesTemplate].concat(
Expand All @@ -714,7 +720,7 @@ class Metadata extends File {
result.template,
canEdit,
result.isExternallyOwned,
isConfidenceScoreEnabled,
isBoundingBoxOrConfidenceScoreReviewEnabled,
),
);
}
Expand All @@ -733,6 +739,7 @@ class Metadata extends File {
* @param {boolean} hasMetadataFeature - metadata feature check
* @param {Object} options - fetch options
* @param {boolean} isMetadataRedesign - is Metadata Sidebar redesigned
* @param {boolean} isBoundingBoxOrConfidenceScoreReviewEnabled - whether to include bounding box or confidence score details in the payload
* @return {Promise}
*/
async getMetadata(
Expand All @@ -746,7 +753,7 @@ class Metadata extends File {
hasMetadataFeature: boolean,
options: RequestOptions = {},
isMetadataRedesign: boolean = false,
isConfidenceScoreEnabled: boolean = false,
isBoundingBoxOrConfidenceScoreReviewEnabled: boolean = false,
): Promise<void> {
const { id, permissions, is_externally_owned }: BoxItem = file;
this.errorCode = ERROR_CODE_FETCH_METADATA;
Expand Down Expand Up @@ -779,7 +786,7 @@ class Metadata extends File {
try {
const customPropertiesTemplate: MetadataTemplate = this.getCustomPropertiesTemplate();
const [instances, globalTemplates, enterpriseTemplates] = await Promise.all([
this.getInstances(id, isMetadataRedesign, isConfidenceScoreEnabled),
this.getInstances(id, isMetadataRedesign, isBoundingBoxOrConfidenceScoreReviewEnabled),
this.getTemplates(id, METADATA_SCOPE_GLOBAL),
hasMetadataFeature ? this.getTemplates(id, METADATA_SCOPE_ENTERPRISE) : Promise.resolve([]),
]);
Expand All @@ -795,7 +802,7 @@ class Metadata extends File {
enterpriseTemplates,
globalTemplates,
!!permissions.can_upload,
isConfidenceScoreEnabled,
isBoundingBoxOrConfidenceScoreReviewEnabled,
)
: [];
const editors = !isMetadataRedesign
Expand Down Expand Up @@ -1190,15 +1197,15 @@ class Metadata extends File {
* @param {Object} template - Metadata Redesign template
* @param {Function} successCallback - Success callback
* @param {Function} errorCallback - Error callback
* @param {boolean} isConfidenceScoreEnabled - whether to include confidence score details in the payload
* @param {boolean} isBoundingBoxOrConfidenceScoreReviewEnabled - whether to include bounding box or confidence score details in the payload
* @return {Promise}
*/
async createMetadataRedesign(
file: BoxItem,
template: MetadataTemplateInstance,
successCallback: Function,
errorCallback: ElementsErrorCallback,
isConfidenceScoreEnabled: boolean = false,
isBoundingBoxOrConfidenceScoreReviewEnabled: boolean = false,
): Promise<void> {
this.errorCode = ERROR_CODE_CREATE_METADATA;
if (!file || !template) {
Expand Down Expand Up @@ -1248,26 +1255,37 @@ class Metadata extends File {
return acc;
}, {});

if (isConfidenceScoreEnabled) {
if (isBoundingBoxOrConfidenceScoreReviewEnabled) {
const details = template.fields.reduce((acc, field) => {
if (field.confidenceScore) {
const entry: {
confidenceScore: number,
confidenceLevel: string,
process?: string,
targetLocation?: string,
} = {
confidenceScore: field.confidenceScore.value,
confidenceLevel: field.confidenceScore.level,
};
if (field.confidenceScore.isAccepted) {
const entry: {
confidenceScore?: number,
confidenceLevel?: string,
process?: string,
targetLocation?: string,
} = {};

if (field.isExtracted) {
entry.process = AI_EXTRACTED_PROCESS;
}

const { confidenceScore } = field;
if (confidenceScore) {
entry.confidenceScore = confidenceScore.value;
entry.confidenceLevel = confidenceScore.level;

if (confidenceScore.isAccepted) {
entry.process = AI_ACCEPTED_PROCESS;
}
if (field.targetLocation) {
entry.targetLocation = JSON.stringify(field.targetLocation);
}
}

if (field.targetLocation) {
entry.targetLocation = JSON.stringify(field.targetLocation);
}

if (Object.keys(entry).length > 0) {
acc[field.key] = entry;
}

return acc;
}, {});

Expand Down
Loading
Loading