You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.9 KiB
TypeScript
163 lines
4.9 KiB
TypeScript
// Copyright (C) 2020 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import React, { useState } from 'react';
|
|
import { Row, Col } from 'antd/lib/grid';
|
|
import Icon from 'antd/lib/icon';
|
|
import Select, { OptionProps } from 'antd/lib/select';
|
|
import Dropdown from 'antd/lib/dropdown';
|
|
import Text from 'antd/lib/typography/Text';
|
|
import Tooltip from 'antd/lib/tooltip';
|
|
|
|
import { ObjectType, ShapeType, ColorBy } from 'reducers/interfaces';
|
|
import ItemMenu from './object-item-menu';
|
|
|
|
interface Props {
|
|
clientID: number;
|
|
serverID: number | undefined;
|
|
labelID: number;
|
|
labels: any[];
|
|
shapeType: ShapeType;
|
|
objectType: ObjectType;
|
|
color: string;
|
|
colorBy: ColorBy;
|
|
type: string;
|
|
locked: boolean;
|
|
changeColorShortcut: string;
|
|
copyShortcut: string;
|
|
pasteShortcut: string;
|
|
propagateShortcut: string;
|
|
toBackgroundShortcut: string;
|
|
toForegroundShortcut: string;
|
|
removeShortcut: string;
|
|
changeColor(color: string): void;
|
|
changeLabel(labelID: string): void;
|
|
copy(): void;
|
|
remove(): void;
|
|
propagate(): void;
|
|
createURL(): void;
|
|
switchOrientation(): void;
|
|
toBackground(): void;
|
|
toForeground(): void;
|
|
resetCuboidPerspective(): void;
|
|
}
|
|
|
|
function ItemTopComponent(props: Props): JSX.Element {
|
|
const {
|
|
clientID,
|
|
serverID,
|
|
labelID,
|
|
labels,
|
|
shapeType,
|
|
objectType,
|
|
color,
|
|
colorBy,
|
|
type,
|
|
locked,
|
|
changeColorShortcut,
|
|
copyShortcut,
|
|
pasteShortcut,
|
|
propagateShortcut,
|
|
toBackgroundShortcut,
|
|
toForegroundShortcut,
|
|
removeShortcut,
|
|
changeColor,
|
|
changeLabel,
|
|
copy,
|
|
remove,
|
|
propagate,
|
|
createURL,
|
|
switchOrientation,
|
|
toBackground,
|
|
toForeground,
|
|
resetCuboidPerspective,
|
|
} = props;
|
|
|
|
const [menuVisible, setMenuVisible] = useState(false);
|
|
const [colorPickerVisible, setColorPickerVisible] = useState(false);
|
|
|
|
const changeMenuVisible = (visible: boolean): void => {
|
|
if (!visible && colorPickerVisible) return;
|
|
setMenuVisible(visible);
|
|
};
|
|
|
|
const changeColorPickerVisible = (visible: boolean): void => {
|
|
if (!visible) {
|
|
setMenuVisible(false);
|
|
}
|
|
setColorPickerVisible(visible);
|
|
};
|
|
|
|
return (
|
|
<Row type='flex' align='middle'>
|
|
<Col span={10}>
|
|
<Text style={{ fontSize: 12 }}>{clientID}</Text>
|
|
<br />
|
|
<Text type='secondary' style={{ fontSize: 10 }}>{type}</Text>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Tooltip title='Change current label' mouseLeaveDelay={0}>
|
|
<Select
|
|
size='small'
|
|
value={`${labelID}`}
|
|
onChange={changeLabel}
|
|
showSearch
|
|
filterOption={(input: string, option: React.ReactElement<OptionProps>) => {
|
|
const { children } = option.props;
|
|
if (typeof (children) === 'string') {
|
|
return children.toLowerCase().includes(input.toLowerCase());
|
|
}
|
|
|
|
return false;
|
|
}}
|
|
>
|
|
{ labels.map((label: any): JSX.Element => (
|
|
<Select.Option key={label.id} value={`${label.id}`}>
|
|
{label.name}
|
|
</Select.Option>
|
|
))}
|
|
</Select>
|
|
</Tooltip>
|
|
</Col>
|
|
<Col span={2}>
|
|
<Dropdown
|
|
visible={menuVisible}
|
|
onVisibleChange={changeMenuVisible}
|
|
placement='bottomLeft'
|
|
overlay={ItemMenu({
|
|
serverID,
|
|
locked,
|
|
shapeType,
|
|
objectType,
|
|
color,
|
|
colorBy,
|
|
colorPickerVisible,
|
|
changeColorShortcut,
|
|
copyShortcut,
|
|
pasteShortcut,
|
|
propagateShortcut,
|
|
toBackgroundShortcut,
|
|
toForegroundShortcut,
|
|
removeShortcut,
|
|
changeColor,
|
|
copy,
|
|
remove,
|
|
propagate,
|
|
createURL,
|
|
switchOrientation,
|
|
toBackground,
|
|
toForeground,
|
|
resetCuboidPerspective,
|
|
changeColorPickerVisible,
|
|
})}
|
|
>
|
|
<Icon type='more' />
|
|
</Dropdown>
|
|
</Col>
|
|
</Row>
|
|
);
|
|
}
|
|
|
|
export default React.memo(ItemTopComponent);
|