Skip to content

Commit

Permalink
fix: Solve the problem caused by discontinuous steps in stepList
Browse files Browse the repository at this point in the history
If the step in stepList is discontinuous,it will be broken
  • Loading branch information
lihqi committed Dec 22, 2021
1 parent 766eab8 commit 007ed21
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
12 changes: 10 additions & 2 deletions packages/lb-components/src/store/annotation/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,18 @@ export function InitTaskData({
return (dispatch: any) => dispatchTasks(dispatch, tasks);
}

/** 获取下一步的step */
const getNextStep = (step: number, stepList: any) => {
const currentStepIndex = stepList?.findIndex((element: any) => element?.step === step);
return stepList[currentStepIndex + 1]?.step;
};

/** 切换到下一步 */
export const ToNextStep = (pageNumber?: number) => (dispatch: any, getState: any) => {
const { step } = getState().annotation;
return [dispatch(UpdateProcessingStep(step + 1, pageNumber))];
const { annotation } = getState();
const { step, stepList } = annotation;
const nextStep = getNextStep(step, stepList);
return [dispatch(UpdateProcessingStep(nextStep, pageNumber))];
};

/**
Expand Down
18 changes: 8 additions & 10 deletions packages/lb-components/src/store/annotation/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,14 @@ export const annotationReducer = (
return state;
}

if (toStep <= stepList.length) {
const stepConfig = getStepConfig(stepList, toStep);
annotationEngine.setToolName(stepConfig.tool, stepConfig.config);

return {
...state,
step: toStep,
toolInstance: annotationEngine.toolInstance,
};
}
const stepConfig = getStepConfig(stepList, toStep);
annotationEngine.setToolName(stepConfig.tool, stepConfig.config);

return {
...state,
step: toStep,
toolInstance: annotationEngine.toolInstance,
};
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IStepInfo } from '@/types/step';
import { i18n } from '@labelbee/lb-utils';
import { useTranslation } from 'react-i18next';
import useSize from '@/hooks/useSize';
import { last } from 'lodash';

interface INextStep {
stepProgress: number;
Expand Down Expand Up @@ -44,8 +45,10 @@ const NextButton: React.FC<{ disabled: boolean }> = ({ disabled }) => {

const NextStep: React.FC<INextStep> = ({ step, stepProgress, stepList }) => {
const { t } = useTranslation();
// 最后一步不显示下一步按钮
const lastStep = last(stepList)?.step;

if (stepList.length < 2 || step === stepList.length) {
if (stepList.length < 2 || step === lastStep) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lb-utils/lib/i18n/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@
"ClearThisOption": "清空此选项",
"RestoreImageAttributes": "还原图片属性",
"ConfirmTo": "确认",
"rectTool": "标签",
"tagTool": "标点",
"rectTool": "拉框",
"tagTool": "标签",
"polygonTool": "多边形",
"lineTool": "线条",
"pointTool": "标点",
Expand Down

0 comments on commit 007ed21

Please sign in to comment.