Skip to content

Commit 08be836

Browse files
committed
fix(frontend): pre-annotation is higher priority than default options
1 parent 4bc0743 commit 08be836

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

apps/frontend/src/utils/convertAudioAndVideoSample.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import _ from 'lodash';
22
import type { AnnotationsWithGlobal, MediaAnnotatorConfig, MediaSample } from '@labelu/audio-annotator-react';
33

44
import type { ParsedResult, SampleResponse } from '@/api/types';
5-
import { MediaType } from '@/api/types';
5+
import { MediaType, SampleState } from '@/api/types';
66

77
import { jsonParse } from './index';
88
import { generateDefaultValues } from './generateGlobalToolDefaultValues';
99

10-
export function convertMediaAnnotations(mediaType: MediaType, result: ParsedResult, config: MediaAnnotatorConfig) {
10+
export function convertMediaAnnotations(
11+
mediaType: MediaType,
12+
result: ParsedResult,
13+
config: MediaAnnotatorConfig,
14+
state?: SampleState,
15+
) {
1116
// annotation
1217
const pool = [
1318
['segment', MediaType.VIDEO === mediaType ? 'videoSegmentTool' : 'audioSegmentTool'],
@@ -20,7 +25,7 @@ export function convertMediaAnnotations(mediaType: MediaType, result: ParsedResu
2025
.map(([type, key]) => {
2126
const items = _.get(result, [key, 'result'], []);
2227

23-
if (!items.length && (type === 'tag' || type === 'text')) {
28+
if (!items.length && (type === 'tag' || type === 'text') && state !== SampleState.NEW) {
2429
// 生成全局工具的默认值
2530
return [type, generateDefaultValues(config?.[type])];
2631
}
@@ -60,6 +65,6 @@ export function convertAudioAndVideoSample(
6065
url: [MediaType.VIDEO, MediaType.AUDIO].includes(mediaType as MediaType)
6166
? sample.file.url.replace('attachment', 'partial')
6267
: sample.file.url,
63-
data: convertMediaAnnotations(mediaType!, resultParsed, config),
68+
data: convertMediaAnnotations(mediaType!, resultParsed, config, sample.state),
6469
};
6570
}

apps/frontend/src/utils/convertImageSample.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { omit } from 'lodash/fp';
44
import type { ToolName } from '@labelu/image';
55
import { TOOL_NAMES } from '@labelu/image';
66

7-
import type { ParsedResult, SampleResponse } from '@/api/types';
7+
import { SampleState, type ParsedResult, type SampleResponse } from '@/api/types';
88

99
import { jsonParse } from './index';
1010
import { generateDefaultValues } from './generateGlobalToolDefaultValues';
1111

1212
export function convertImageAnnotations(
1313
result: ParsedResult,
1414
config: Pick<ImageAnnotatorOptions, ToolName> & GlobalToolConfig,
15+
state?: SampleState,
1516
) {
1617
// annotation
1718
const pool = [
@@ -31,7 +32,7 @@ export function convertImageAnnotations(
3132
}
3233

3334
const items = _.get(result, [key, 'result']) || _.get(result, [type, 'result'], []);
34-
if (!items.length && (type === 'tag' || type === 'text')) {
35+
if (!items.length && (type === 'tag' || type === 'text') && state !== SampleState.NEW) {
3536
// 生成全局工具的默认值
3637
return [type, generateDefaultValues(config?.[type])];
3738
}
@@ -80,7 +81,7 @@ export function convertImageSample(
8081
return {
8182
id,
8283
url,
83-
data: convertImageAnnotations(resultParsed, config),
84+
data: convertImageAnnotations(resultParsed, config, sample.state),
8485
meta: _.pick(resultParsed, ['width', 'height', 'rotate']),
8586
};
8687
}

0 commit comments

Comments
 (0)