Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a button to frame player to copy filename #8989

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added

- Button to frame player to copy filename
(<https://github.com/cvat-ai/cvat/pull/8989>)
10 changes: 6 additions & 4 deletions cvat-ui/src/components/annotation-page/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@

.cvat-player-frame-url-icon,
.cvat-player-delete-frame,
.cvat-player-restore-frame {
.cvat-player-restore-frame,
.cvat-player-copy-frame-name-icon {
opacity: 0.7;
color: $objects-bar-icons-color;

Expand All @@ -199,9 +200,10 @@
}
}

.cvat-player-delete-frame,
.cvat-player-restore-frame {
margin-left: $grid-unit-size * 2;
.cvat-player-frame-actions {
span:not(:first-child) {
margin-left: $grid-unit-size;
}
}

.cvat-player-frame-selector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
} from 'react';

import { Row, Col } from 'antd/lib/grid';
import Icon, { LinkOutlined, DeleteOutlined } from '@ant-design/icons';
import Icon, { LinkOutlined, DeleteOutlined, CopyOutlined } from '@ant-design/icons';
import Slider from 'antd/lib/slider';
import InputNumber from 'antd/lib/input-number';
import Text from 'antd/lib/typography/Text';
Expand Down Expand Up @@ -39,6 +39,7 @@ interface Props {
onSliderChange(value: number): void;
onInputChange(value: number): void;
onURLIconClick(): void;
onCopyFrameFileNameIconClick(): void;
onDeleteFrame(): void;
onRestoreFrame(): void;
switchNavigationBlocked(blocked: boolean): void;
Expand Down Expand Up @@ -79,6 +80,7 @@ function PlayerNavigation(props: Props): JSX.Element {
onSliderChange,
onInputChange,
onURLIconClick,
onCopyFrameFileNameIconClick,
onDeleteFrame,
onRestoreFrame,
switchNavigationBlocked,
Expand Down Expand Up @@ -186,7 +188,10 @@ function PlayerNavigation(props: Props): JSX.Element {
<Text type='secondary'>{frameFilename}</Text>
</CVATTooltip>
</Col>
<Col offset={1}>
<Col className='cvat-player-frame-actions' offset={1}>
<CVATTooltip title='Copy frame filename'>
<CopyOutlined className='cvat-player-copy-frame-name-icon' onClick={onCopyFrameFileNameIconClick} />
</CVATTooltip>
<CVATTooltip title='Create frame URL'>
<LinkOutlined className='cvat-player-frame-url-icon' onClick={onURLIconClick} />
</CVATTooltip>
Expand Down
3 changes: 3 additions & 0 deletions cvat-ui/src/components/annotation-page/top-bar/top-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface Props {
onSliderChange(value: number): void;
onInputChange(value: number): void;
onURLIconClick(): void;
onCopyFrameFileNameIconClick(): void;
onUndoClick(): void;
onRedoClick(): void;
onFinishDraw(): void;
Expand Down Expand Up @@ -117,6 +118,7 @@ export default function AnnotationTopBarComponent(props: Props): JSX.Element {
onSliderChange,
onInputChange,
onURLIconClick,
onCopyFrameFileNameIconClick,
onUndoClick,
onRedoClick,
onFinishDraw,
Expand Down Expand Up @@ -171,6 +173,7 @@ export default function AnnotationTopBarComponent(props: Props): JSX.Element {
onSliderChange={onSliderChange}
onInputChange={onInputChange}
onURLIconClick={onURLIconClick}
onCopyFrameFileNameIconClick={onCopyFrameFileNameIconClick}
onDeleteFrame={onDeleteFrame}
onRestoreFrame={onRestoreFrame}
switchNavigationBlocked={switchNavigationBlocked}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { Canvas, CanvasMode } from 'cvat-canvas-wrapper';
import { Canvas3d } from 'cvat-canvas3d-wrapper';
import { filterApplicableLabels } from 'utils/filter-applicable-labels';
import { toClipboard } from 'utils/to-clipboard';

interface OwnProps {
readonly: boolean;
Expand Down Expand Up @@ -233,16 +234,7 @@ class ObjectItemContainer extends React.PureComponent<Props, State> {
const search = `frame=${frameNumber}&type=${objectState.objectType}&serverID=${objectState.serverID}`;
const url = `${origin}${pathname}?${search}`;

const fallback = (): void => {
// eslint-disable-next-line
window.prompt('Browser Clipboard API not allowed, please copy manually', url);
};

if (window.isSecureContext) {
window.navigator.clipboard.writeText(url).catch(fallback);
} else {
fallback();
}
toClipboard(url);
};

private switchOrientation = (): void => {
Expand Down
17 changes: 8 additions & 9 deletions cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import isAbleToChangeFrame from 'utils/is-able-to-change-frame';
import { KeyMap } from 'utils/mousetrap-react';
import { switchToolsBlockerState } from 'actions/settings-actions';
import { writeLatestFrame } from 'utils/remember-latest-frame';
import { toClipboard } from 'utils/to-clipboard';

interface StateToProps {
jobInstance: Job;
Expand Down Expand Up @@ -567,16 +568,13 @@ class AnnotationTopBarContainer extends React.PureComponent<Props> {
const { origin, pathname } = window.location;
const url = `${origin}${pathname}?frame=${frameNumber}`;

const fallback = (): void => {
// eslint-disable-next-line
window.prompt('Browser Clipboard API not allowed, please copy manually', url);
};
toClipboard(url);
};

if (window.isSecureContext) {
window.navigator.clipboard.writeText(url).catch(fallback);
} else {
fallback();
}
private onCopyFrameFileNameIconClick = (): void => {
const { frameFilename } = this.props;

toClipboard(frameFilename);
};

private onDeleteFrame = (): void => {
Expand Down Expand Up @@ -670,6 +668,7 @@ class AnnotationTopBarContainer extends React.PureComponent<Props> {
onSliderChange={this.onChangePlayerSliderValue}
onInputChange={this.onChangePlayerInputValue}
onURLIconClick={this.onURLIconClick}
onCopyFrameFileNameIconClick={this.onCopyFrameFileNameIconClick}
onDeleteFrame={this.onDeleteFrame}
onRestoreFrame={this.onRestoreFrame}
changeWorkspace={this.changeWorkspace}
Expand Down
16 changes: 16 additions & 0 deletions cvat-ui/src/utils/to-clipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

export function toClipboard(text: string): void {
const fallback = (): void => {
// eslint-disable-next-line
window.prompt('Browser Clipboard API not allowed, please copy manually', text);
};

if (window.isSecureContext) {
window.navigator.clipboard.writeText(text).catch(fallback);
} else {
fallback();
}
}
Loading