Skip to content

Commit

Permalink
feat(lb-components): Add action like updateValid and beforeRotate
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwin-L committed Sep 28, 2022
1 parent f71143c commit 61c1ef1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/lb-components/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface AppProps {

// data Correction
skipBeforePageTurning?: (pageTurning: Function) => void;
beforeRotate?: () => boolean;

drawLayerSlot?: (props: {
zoom: number;
Expand Down Expand Up @@ -97,6 +98,7 @@ const App: React.FC<AppProps> = (props) => {
loadFileList,
defaultLang = 'cn',
skipBeforePageTurning,
beforeRotate,
} = props;

useEffect(() => {
Expand All @@ -112,6 +114,7 @@ const App: React.FC<AppProps> = (props) => {
onPageChange,
onStepChange,
skipBeforePageTurning,
beforeRotate,
}),
);

Expand All @@ -131,6 +134,7 @@ const App: React.FC<AppProps> = (props) => {
onSave,
onPageChange,
onStepChange,
beforeRotate,
}),
);

Expand All @@ -145,6 +149,7 @@ const App: React.FC<AppProps> = (props) => {
onPageChange,
onStepChange,
defaultLang,
beforeRotate,
]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PageForward,
UpdateToolInstance,
CopyBackWordResult,
UpdateValid,
} from '@/store/annotation/actionCreators';
import { ISize } from '@/types/main';
import { message } from 'antd';
Expand Down Expand Up @@ -68,6 +69,10 @@ export const ViewportProviderComponent = (props: any) => {
if (e.keyCode === EKeyCode.C && e.altKey === true) {
dispatch(CopyBackWordResult());
}

if (e.keyCode === EKeyCode.Y) {
dispatch(UpdateValid());
}
}

/**
Expand Down
7 changes: 4 additions & 3 deletions packages/lb-components/src/store/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export const ANNOTATION_ACTIONS = {
CALC_STEP_PROGRESS: '@@CALC_STEP_PROGRESS',
SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED: '@@SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED',
SKIP_BEFORE_PAGE_TURNING: '@@SKIP_BEFORE_PAGE_TURNING',
UPDATE_BEFORE_ROTATE: '@@UPDATE_BEFORE_ROTATE',
SET_LOADING: '@@SET_LOADING',
SET_POINT_CLOUD_LOADING: '@@SET_POINT_CLOUD_LOADING',



SET_TASK_STEP_LIST: '@@SET_TASK_STEP_LIST'
SET_TASK_STEP_LIST: '@@SET_TASK_STEP_LIST',
UPDATE_ANNOTATION_VALID: '@@UPDATE_ANNOTATION_VALID',
};

export const IMAGE_ATTRIBUTE_ACTIONS = {
Expand Down
27 changes: 26 additions & 1 deletion packages/lb-components/src/store/annotation/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ export function UpdateRotate(): AnnotationActionTypes {
};
}

export function UpdateValid(): AnnotationActionTypes {
return {
type: ANNOTATION_ACTIONS.UPDATE_ANNOTATION_VALID,
};
}

export function UpdateSkipBeforePageTurning(skipBeforePageTurning: (pageTurning: Function) => {}): AnnotationActionTypes {
return {
type: ANNOTATION_ACTIONS.SKIP_BEFORE_PAGE_TURNING,
Expand All @@ -176,6 +182,15 @@ export function UpdateSkipBeforePageTurning(skipBeforePageTurning: (pageTurning:
};
}

export function UpdateBeforeRotate(beforeRotate: () => {}): AnnotationActionTypes {
return {
type: ANNOTATION_ACTIONS.UPDATE_BEFORE_ROTATE,
payload: {
beforeRotate,
},
};
}

export function CopyBackWordResult(): AnnotationActionTypes {
return {
type: ANNOTATION_ACTIONS.COPY_BACKWARD_RESULT,
Expand All @@ -196,7 +211,8 @@ export function InitTaskData({
loadFileList,
step,
stepList,
skipBeforePageTurning
skipBeforePageTurning,
beforeRotate
}: any): any {
const tasks: any[] = [];

Expand Down Expand Up @@ -230,6 +246,10 @@ export function InitTaskData({
tasks.push(UpdateSkipBeforePageTurning(skipBeforePageTurning));
}

if (beforeRotate) {
tasks.push(UpdateBeforeRotate(beforeRotate));
}

tasks.push(SetTaskConfig({ stepList, step }));

tasks.push({
Expand All @@ -256,6 +276,7 @@ export function UpdateInjectFunc({
pageSize,
loadFileList,
stepList,
beforeRotate
}: any): any {
const tasks: any[] = [];

Expand Down Expand Up @@ -285,6 +306,10 @@ export function UpdateInjectFunc({
tasks.push(UpdatePageSize(pageSize));
}

if (beforeRotate) {
tasks.push(UpdateBeforeRotate(beforeRotate));
}

tasks.push(SetTaskStepList({ stepList }));

return (dispatch: any) => dispatchTasks(dispatch, tasks);
Expand Down
34 changes: 33 additions & 1 deletion packages/lb-components/src/store/annotation/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import StepUtils from '@/utils/StepUtils';
import ToolUtils from '@/utils/ToolUtils';
import { AnnotationEngine, CommonToolUtils, ImgUtils } from '@labelbee/lb-annotation';
import { i18n } from '@labelbee/lb-utils';
import { Modal } from 'antd';
import { message } from 'antd/es';
import _ from 'lodash';
import { SetAnnotationLoading } from './actionCreators';
Expand Down Expand Up @@ -545,6 +546,13 @@ export const annotationReducer = (
};
}

case ANNOTATION_ACTIONS.UPDATE_BEFORE_ROTATE: {
return {
...state,
beforeRotate: action.payload.beforeRotate,
};
}

case ANNOTATION_ACTIONS.SKIP_BEFORE_PAGE_TURNING: {
return {
...state,
Expand All @@ -565,8 +573,32 @@ export const annotationReducer = (
}

case ANNOTATION_ACTIONS.UPDATE_ROTATE: {
const { toolInstance } = state;
const { toolInstance, beforeRotate } = state;

// DataCheck before rotate.
if (beforeRotate) {
if (beforeRotate() === false) {
return state;
}
}

toolInstance?.updateRotate();
return state;
}

case ANNOTATION_ACTIONS.UPDATE_ANNOTATION_VALID: {
const { toolInstance } = state;
const valid = toolInstance?.valid ?? true;

Modal.destroyAll();
Modal.confirm({
content: `是否确认${valid ? '标为无效' : '取消无效'}文件`,
onOk: () => {
toolInstance?.setValid(!valid);
},
okText: '确认',
cancelText: '取消',
});

return state;
}
Expand Down
1 change: 1 addition & 0 deletions packages/lb-components/src/store/annotation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface AnnotationState {
triggerEventAfterIndexChanged: boolean;

skipBeforePageTurning?: (pageTurning: Function) => void;
beforeRotate?: () => boolean;

pointCloudLoading: boolean;
}
Expand Down

0 comments on commit 61c1ef1

Please sign in to comment.