Skip to content

Commit

Permalink
fix: Fix problems from comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Glenfiddish committed Jun 8, 2022
1 parent 865575d commit 145d20a
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReloadOutlined } from '@ant-design/icons';
import { Button } from 'antd/es';
import React from 'react';
import { useTranslation } from 'react-i18next';

export interface IFileErrorProps {
width?: number;
Expand All @@ -11,7 +12,7 @@ export interface IFileErrorProps {
ignoreOffsetY?: boolean;
layerStyle?: React.CSSProperties;
backgroundColor: string;
fileTypeName?: string;
fileType?: string;
isError?: boolean;
}

Expand All @@ -23,9 +24,11 @@ const FileError = (props: IFileErrorProps) => {
hideSetInvalidTips,
ignoreOffsetY,
backgroundColor,
fileTypeName = '图片',
fileType = 'image',
} = props;

const { t } = useTranslation();

const top = !ignoreOffsetY ? 40 : 0;

const layerStyle: React.CSSProperties = props.layerStyle || {
Expand Down Expand Up @@ -60,9 +63,7 @@ const FileError = (props: IFileErrorProps) => {
<Button type='primary' shape='circle' icon={<ReloadOutlined />} onClick={reloadImage} />
</div>
<div>
{`${fileTypeName}加载失败, 请重新加载${
hideSetInvalidTips ? '' : ` 或 将${fileTypeName}标为无效`
}`}
{`${t(`${fileType}ErrorAndReload`)}${hideSetInvalidTips ? '' : t('orMaskAsInvalid')}`}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
*/

import React from 'react';
import { useTranslation } from 'react-i18next';

export interface IFileInvalidProps {
fileTypeName?: string;
fileType?: string;
isValid: boolean;
}

const FileInvalid: React.FC<IFileInvalidProps> = ({ fileTypeName = '图片', isValid }) => {
const FileInvalid: React.FC<IFileInvalidProps> = ({ fileType = 'image', isValid }) => {
const { t } = useTranslation();

if (isValid) {
return null;
}
Expand All @@ -30,7 +33,7 @@ const FileInvalid: React.FC<IFileInvalidProps> = ({ fileTypeName = '图片', isV
justifyContent: 'center',
}}
>
{`无效${fileTypeName},请跳过`}
{t(`${fileType}InvalidAndSkip`)}
</div>
);
};
Expand Down
12 changes: 4 additions & 8 deletions packages/lb-components/src/components/fileException/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ import FileInvalid, { IFileInvalidProps } from './FileInvalid';
interface IFileExceptionProps {
errorProps: IFileErrorProps & { isError: boolean };
invalidProps: IFileInvalidProps;
fileTypeName: string;
fileType: string;
}

const FileException: React.FC<IFileExceptionProps> = ({
invalidProps,
errorProps,
fileTypeName,
}) => {
const FileException: React.FC<IFileExceptionProps> = ({ invalidProps, errorProps, fileType }) => {
if (!invalidProps.isValid) {
return <FileInvalid {...{ fileTypeName, ...invalidProps }} />;
return <FileInvalid {...{ fileType, ...invalidProps }} />;
}

if (errorProps.isError) {
return <FileError {...{ fileTypeName, ...errorProps }} />;
return <FileError {...{ fileType, ...errorProps }} />;
}
return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import { IStepInfo } from '@/types/step';
import _ from 'lodash';
import type { ObjectString } from './types';
import { getKeyCodeNumber } from './utils';
import { IFileItem } from '@/types/data';

export interface IVideoTagInstanceAdaptorProps {
imgIndex: number;
imgList: any[];
imgList: IFileItem[];
pageForward: () => void;
pageJump: (page: string) => void;
pageBackward: () => void;
Expand All @@ -29,8 +30,9 @@ export interface IVideoTagInstanceAdaptorProps {
}

interface IVideoTagInstanceAdaptorState {
// TODO: Use ITagResult from 'lb-annotation'
tagResult: any[];
labelSelectedList: any;
labelSelectedList: number[];
valid: boolean;
}

Expand Down Expand Up @@ -62,7 +64,7 @@ export class TagToolInstanceAdaptor extends React.Component<
}

get currentTagResult() {
return this.state.tagResult[0];
return this.state.tagResult[0] ?? {};
}

public get valid() {
Expand Down Expand Up @@ -140,7 +142,7 @@ export class TagToolInstanceAdaptor extends React.Component<
const tagResult = [
{
sourceID: CommonToolUtils.getSourceID(),
id: uuid(8, 62),
id: this.currentTagResult?.id ?? uuid(8, 62),
result: tagRes,
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { result2LabelKey } from './utils';
import type { ITagLabelsArray } from './types';
import { IInputList } from '@/types/main';

interface IVideoTagLayerProps {
result: Array<{ result: { [key: string]: string } }>;
inputList: any[];
inputList: IInputList[];
}

const tagLayerCSSProperty: React.CSSProperties = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class VideoPlayer extends React.Component<IVideoPlayerProps, IVideoPlayer
/>

<FileException
fileTypeName='视频'
fileType='video'
errorProps={{
reloadImage: this.reload,
backgroundColor: '#e2e2e2',
Expand Down
18 changes: 13 additions & 5 deletions packages/lb-components/src/store/annotation/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ export const annotationReducer = (
case ANNOTATION_ACTIONS.LOAD_FILE_DATA: {
const { imgList, step, toolInstance, annotationEngine, stepList } = state;

if (!toolInstance || !annotationEngine) {
return state;
}

const currentStepInfo = StepUtils.getCurrentStepInfo(step, stepList);

const { nextIndex, imgNode, nextBasicIndex, imgError } = action.payload;
Expand Down Expand Up @@ -413,10 +417,10 @@ export const annotationReducer = (

case ANNOTATION_ACTIONS.INIT_TOOL: {
const { imgNode } = state;
const instances = updateToolInstance(state, imgNode);
const instance = updateToolInstance(state, imgNode);

if (instances) {
const { toolInstance, annotationEngine } = instances;
if (instance) {
const { toolInstance, annotationEngine } = instance;
return {
...state,
toolInstance,
Expand All @@ -430,10 +434,14 @@ export const annotationReducer = (
}

case ANNOTATION_ACTIONS.SET_TOOL: {
if (action.payload.instance) {
const instance = action.payload?.instance;
if (instance) {
return {
...state,
toolInstance: action.payload.instance,
toolInstance: instance,
annotationEngine: {
toolInstance: instance,
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/lb-components/src/store/annotation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface CommonActions {

export interface AnnotationState {
toolInstance: ToolInstance | null;
annotationEngine: AnnotationEngine | null;
annotationEngine: AnnotationEngine | null | { toolInstance: ToolInstance };
imgList: IFileItem[];
config: string;
imgIndex: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/lb-demo/src/mock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const tagDefaultResult = JSON.stringify({
export const videoTagDefaultResult = JSON.stringify({
step_1: {
dataSource: 0,
tool: 'tagTool',
tool: 'videoTagTool',
result: [],
},
});
Expand Down
14 changes: 12 additions & 2 deletions packages/lb-utils/src/i18n/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@
"Speed": "Speed",
"PlayPause": "Play / Pause",
"FastForward": "Fast Forward",
"Rewind": "Rewind"
"Rewind": "Rewind",
"videoInvalidAndSkip": "Video invalid, please skip",
"imageInvalidAndSkip": "Image invalid, please skip",
"videoErrorAndReload": "Failed to load video, please reload",
"imageErrorAndReload": "Failed to load image, please reload",
"orMaskAsInvalid": " or mask it as invalid"
},
"cn": {
"TextInput": "文本输入",
Expand Down Expand Up @@ -219,6 +224,11 @@
"Speed": "倍速",
"PlayPause": "播放/暂停",
"FastForward": "快进",
"Rewind": "快退"
"Rewind": "快退",
"videoInvalidAndSkip": "无效视频,请跳过",
"imageInvalidAndSkip": "无效图片,请跳过",
"videoErrorAndReload": "视频加载失败, 请重新加载",
"imageErrorAndReload": "图片加载失败, 请重新加载",
"orMaskAsInvalid": " 或 将其标为无效"
}
}

0 comments on commit 145d20a

Please sign in to comment.