-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hotkeys to change labels (#3070)
* temp commit * Added ability to change default label and object label by using Ctrl+{number} * Removed extra changes * Minor refactoring * Added ability to change assigned keys * Redesigned popover * Added changelog record & updated version * Added memoization * Some minor changes * Applied comments Co-authored-by: Dmitry Kalinin <dmitry.kalinin@intel.com>
- Loading branch information
1 parent
d2a1d12
commit 7524202
Showing
19 changed files
with
341 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...onents/annotation-page/standard-workspace/objects-side-bar/label-key-selector-popover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (C) 2021 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import Popover from 'antd/lib/popover'; | ||
import Button from 'antd/lib/button'; | ||
import { Row, Col } from 'antd/lib/grid'; | ||
import Text from 'antd/lib/typography/Text'; | ||
|
||
import { CombinedState } from 'reducers/interfaces'; | ||
import CVATTooltip from 'components/common/cvat-tooltip'; | ||
|
||
interface LabelKeySelectorPopoverProps { | ||
updateLabelShortcutKey(updatedKey: string, labelID: number): void; | ||
keyToLabelMapping: Record<string, number>; | ||
labelID: number; | ||
children: JSX.Element; | ||
} | ||
|
||
interface LabelKeySelectorPopoverContentProps { | ||
updateLabelShortcutKey(updatedKey: string, labelID: number): void; | ||
labelID: number; | ||
keyToLabelMapping: Record<string, number>; | ||
} | ||
|
||
function PopoverContent(props: LabelKeySelectorPopoverContentProps): JSX.Element { | ||
const { keyToLabelMapping, labelID, updateLabelShortcutKey } = props; | ||
const labels = useSelector((state: CombinedState) => state.annotation.job.labels); | ||
|
||
return ( | ||
<div className='cvat-label-item-setup-shortcut-popover'> | ||
{[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], ['0']].map((arr, i_) => ( | ||
<Row justify='space-around' gutter={[16, 16]} key={i_}> | ||
{arr.map((i) => { | ||
const previousLabelID = keyToLabelMapping[i]; | ||
const labelName = Number.isInteger(previousLabelID) ? | ||
labels.filter((label: any): boolean => label.id === previousLabelID)[0]?.name || | ||
'undefined' : | ||
'None'; | ||
|
||
return ( | ||
<Col key={i} span={8}> | ||
<CVATTooltip title={labelName}> | ||
<Button onClick={() => updateLabelShortcutKey(i, labelID)}> | ||
<Text>{`${i}:`}</Text> | ||
<Text type='secondary'>{labelName}</Text> | ||
</Button> | ||
</CVATTooltip> | ||
</Col> | ||
); | ||
})} | ||
</Row> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
const MemoizedContent = React.memo(PopoverContent); | ||
|
||
function LabelKeySelectorPopover(props: LabelKeySelectorPopoverProps): JSX.Element { | ||
const { | ||
children, labelID, updateLabelShortcutKey, keyToLabelMapping, | ||
} = props; | ||
|
||
return ( | ||
<Popover | ||
destroyTooltipOnHide={{ keepParent: false }} | ||
trigger='click' | ||
content={( | ||
<MemoizedContent | ||
keyToLabelMapping={keyToLabelMapping} | ||
labelID={labelID} | ||
updateLabelShortcutKey={updateLabelShortcutKey} | ||
/> | ||
)} | ||
placement='left' | ||
> | ||
{children} | ||
</Popover> | ||
); | ||
} | ||
|
||
export default React.memo(LabelKeySelectorPopover); |
Oops, something went wrong.