Skip to content

Commit

Permalink
feat: TagToolInstanceAdaptor export fn: 'setValid' and getter 'valid'
Browse files Browse the repository at this point in the history
  • Loading branch information
Glenfiddish committed Jun 8, 2022
1 parent 7fc0313 commit e73ca3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface IVideoTagInstanceAdaptorProps {
interface ITagInstanceAdaptorState {
tagResult: any[];
labelSelectedList: any;
valid: boolean;
}

export class TagToolInstanceAdaptor extends React.Component<
Expand All @@ -46,23 +47,28 @@ export class TagToolInstanceAdaptor extends React.Component<
this.state = {
tagResult: [],
labelSelectedList: [],
valid: true,
};
}

get config() {
public get config() {
const stepInfo = StepUtils.getCurrentStepInfo(this.props.step, this.props.stepList);
return jsonParser(stepInfo?.config);
}

/** Just implementation, no actual logic */
get history() {
public get history() {
return { initRecord: () => {} };
}

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

public get valid() {
return this.state.valid;
}

public clearResult = (sendMsg: boolean, value?: string) => {
const newTag = value
? this.state.tagResult.map((v) => {
Expand All @@ -79,13 +85,17 @@ export class TagToolInstanceAdaptor extends React.Component<
};

public exportData = () => {
return [this.state.tagResult, { valid: true }];
return [this.state.tagResult, { valid: this.state.valid }];
};

public singleOn(event: string, func: () => void) {
this.fns[event] = func;
}

public on(event: string, func: () => void) {
this.singleOn(event, func);
}

public getTagResultByCode(num1: number, num2?: number) {
try {
const inputList = this.config?.inputList ?? [];
Expand Down Expand Up @@ -218,6 +228,10 @@ export class TagToolInstanceAdaptor extends React.Component<
}
};

public setValid = (valid: boolean) => {
this.setState({ valid });
};

public componentDidMount() {
document.addEventListener('keydown', this.keydown);
this.props.onMounted(this);
Expand All @@ -231,8 +245,10 @@ export class TagToolInstanceAdaptor extends React.Component<
/** Observer imgIndex and set tagResult */
public shouldComponentUpdate({ imgIndex, imgList, step }: IVideoTagInstanceAdaptorProps) {
if (imgIndex !== this.props.imgIndex) {
const res = jsonParser(imgList[imgIndex].result)[`step_${step}`];
this.setState({
tagResult: jsonParser(imgList[imgIndex].result)[`step_${step}`]?.result ?? [],
tagResult: res?.result ?? [],
valid: res.valid,
});
}
return true;
Expand Down
3 changes: 0 additions & 3 deletions packages/lb-demo/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import { getStepList, getDependStepList } from './mock/taskConfig';
import qs from 'qs';
import { AnnotationView } from '@labelbee/lb-components';
import { DEFAULT_ANNOTATIONS } from './mock';
import { cTool } from '@labelbee/lb-annotation';
import StepUtils from '@labelbee/lb-components/dist/utils/StepUtils';

const { EVideoToolName } = cTool;

const App = () => {
const tool = qs.parse(window.location.search, { ignoreQueryPrefix: true, comma: true }).tool;

Expand Down

0 comments on commit e73ca3c

Please sign in to comment.