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

Fixed disabling the requests, improved notification links #8197

Merged
merged 9 commits into from
Jul 29, 2024
Merged
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
8 changes: 8 additions & 0 deletions changelog.d/20240719_132628_klakhov_improved_requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Fixed

- Request card was not disabed properly after downloading
(<https://github.com/cvat-ai/cvat/pull/8197>)

### Changed
- Following the link in notification no longer reloads the page
(<https://github.com/cvat-ai/cvat/pull/8197>)
2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.64.0",
"version": "1.64.1",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions cvat-ui/src/actions/requests-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum RequestsActionsTypes {
CANCEL_REQUEST_FAILED = 'CANCEL_REQUEST_FAILED',
DELETE_REQUEST = 'DELETE_REQUEST',
DELETE_REQUEST_FAILED = 'DELETE_REQUEST_FAILED',
DISABLE_REQUEST = 'DISABLE_REQUEST',
}

export const requestsActions = {
Expand All @@ -44,6 +45,9 @@ export const requestsActions = {
cancelRequestFailed: (request: Request, error: any) => createAction(
RequestsActionsTypes.CANCEL_REQUEST_FAILED, { request, error },
),
disableRequest: (request: Request) => createAction(
RequestsActionsTypes.DISABLE_REQUEST, { request },
),
};

export type RequestsActions = ActionUnion<typeof requestsActions>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ import {
import DetectorRunner, { DetectorRequestBody } from 'components/model-runner-modal/detector-runner';
import LabelSelector from 'components/label-selector/label-selector';
import CVATTooltip from 'components/common/cvat-tooltip';
import CVATMarkdown from 'components/common/cvat-markdown';

import ApproximationAccuracy, {
thresholdFromAccuracy,
} from 'components/annotation-page/standard-workspace/controls-side-bar/approximation-accuracy';
import { switchToolsBlockerState } from 'actions/settings-actions';
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
import withVisibilityHandling from './handle-popover-visibility';
import ToolsTooltips from './interactor-tooltips';

Expand Down Expand Up @@ -440,7 +440,7 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
setTimeout(() => this.runInteractionRequest(interactionId));
} catch (error: any) {
notification.error({
description: <ReactMarkdown>{error.message}</ReactMarkdown>,
description: <CVATMarkdown>{error.message}</CVATMarkdown>,
message: 'Interaction error occurred',
duration: null,
});
Expand Down Expand Up @@ -533,7 +533,7 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
fetchAnnotations();
} catch (error: any) {
notification.error({
description: <ReactMarkdown>{error.message}</ReactMarkdown>,
description: <CVATMarkdown>{error.message}</CVATMarkdown>,
message: 'Tracking error occurred',
duration: null,
});
Expand Down Expand Up @@ -787,7 +787,7 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
} catch (error: any) {
notification.error({
message: 'Tracker initialization error',
description: <ReactMarkdown>{error.message}</ReactMarkdown>,
description: <CVATMarkdown>{error.message}</CVATMarkdown>,
duration: null,
});
} finally {
Expand Down Expand Up @@ -841,7 +841,7 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
} catch (error: any) {
notification.error({
message: 'Tracking error',
description: <ReactMarkdown>{error.message}</ReactMarkdown>,
description: <CVATMarkdown>{error.message}</CVATMarkdown>,
duration: null,
});
} finally {
Expand Down Expand Up @@ -900,7 +900,7 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
} catch (error: any) {
notification.error({
message: 'Could not initialize OpenCV',
description: <ReactMarkdown>{error.message}</ReactMarkdown>,
description: <CVATMarkdown>{error.message}</CVATMarkdown>,
duration: null,
});
} finally {
Expand Down Expand Up @@ -1346,7 +1346,7 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
onSwitchToolsBlockerState({ buttonVisible: false });
} catch (error: any) {
notification.error({
description: <ReactMarkdown>{error.message}</ReactMarkdown>,
description: <CVATMarkdown>{error.message}</CVATMarkdown>,
message: 'Detection error occurred',
duration: null,
});
Expand Down
45 changes: 45 additions & 0 deletions cvat-ui/src/components/common/cvat-markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (C) 2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

import Button from 'antd/lib/button';
klakhov marked this conversation as resolved.
Show resolved Hide resolved
import React from 'react';
import ReactMarkdown from 'react-markdown';
import { RouteComponentProps } from 'react-router-dom';

export type UseHistoryType = RouteComponentProps['history'];

const RouterLinkHOC = (history?: UseHistoryType) => (
function (props: { children: React.ReactNode, href?: string }): JSX.Element {
const { href, children } = props;
klakhov marked this conversation as resolved.
Show resolved Hide resolved

if (href?.match(/^\//) && history) {
return (
<Button
type='link'
className='cvat-notification-link'
onClick={() => {
history.push(href);
}}
>
{children}
</Button>
);
}

return (<a href={href}>{children}</a>);
});

export default function CVATMarkdown(props: { history?: UseHistoryType, children: string }): JSX.Element {
const { children, history } = props;

return (
<ReactMarkdown
components={{
a: RouterLinkHOC(history),
}}
>
{children}
</ReactMarkdown>
);
}
18 changes: 9 additions & 9 deletions cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Spin from 'antd/lib/spin';
import { DisconnectOutlined } from '@ant-design/icons';
import Space from 'antd/lib/space';
import Text from 'antd/lib/typography/Text';
import ReactMarkdown from 'react-markdown';

import LogoutComponent from 'components/logout-component';
import LoginPageContainer from 'containers/login-page/login-page';
Expand Down Expand Up @@ -77,6 +76,7 @@ import '../styles.scss';
import appConfig from 'config';
import EventRecorder from 'utils/event-recorder';
import { authQuery } from 'utils/auth-query';
import CVATMarkdown from './common/cvat-markdown';
import EmailConfirmationPage from './email-confirmation-pages/email-confirmed';
import EmailVerificationSentPage from './email-confirmation-pages/email-verification-sent';
import IncorrectEmailConfirmationPage from './email-confirmation-pages/incorrect-email-confirmation';
Expand Down Expand Up @@ -358,20 +358,20 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
}

private showMessages(): void {
const { notifications, resetMessages, history } = this.props;

function showMessage(notificationState: NotificationState): void {
notification.info({
message: (
<ReactMarkdown>{notificationState.message}</ReactMarkdown>
<CVATMarkdown history={history}>{notificationState.message}</CVATMarkdown>
),
description: notificationState?.description && (
<ReactMarkdown>{notificationState?.description}</ReactMarkdown>
<CVATMarkdown history={history}>{notificationState?.description}</CVATMarkdown>
),
duration: notificationState.duration || null,
});
}

const { notifications, resetMessages } = this.props;

let shown = false;
for (const where of Object.keys(notifications.messages)) {
for (const what of Object.keys((notifications as any).messages[where])) {
Expand All @@ -389,6 +389,8 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
}

private showErrors(): void {
const { notifications, resetErrors, history } = this.props;

function showError(title: string, _error: Error, shouldLog?: boolean, className?: string): void {
const error = _error?.message || _error.toString();
const dynamicProps = typeof className === 'undefined' ? {} : { className };
Expand All @@ -400,10 +402,10 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
notification.error({
...dynamicProps,
message: (
<ReactMarkdown>{title}</ReactMarkdown>
<CVATMarkdown history={history}>{title}</CVATMarkdown>
),
duration: null,
description: errorLength > 300 ? 'Open the Browser Console to get details' : <ReactMarkdown>{error}</ReactMarkdown>,
description: errorLength > 300 ? 'Open the Browser Console to get details' : <CVATMarkdown history={history}>{error}</CVATMarkdown>,
});

if (shouldLog) {
Expand All @@ -416,8 +418,6 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
}
}

const { notifications, resetErrors } = this.props;

let shown = false;
for (const where of Object.keys(notifications.errors)) {
for (const what of Object.keys((notifications as any).errors[where])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import './styles.scss';
import React, { useState, useEffect, useCallback } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import ReactMarkdown from 'react-markdown';
import { useHistory } from 'react-router';
import Modal from 'antd/lib/modal';
import Notification from 'antd/lib/notification';
import Text from 'antd/lib/typography/Text';
Expand All @@ -15,6 +15,7 @@ import { CombinedState, StorageLocation } from 'reducers';
import { exportActions, exportBackupAsync } from 'actions/export-actions';
import { getCore, Storage, StorageData } from 'cvat-core-wrapper';

import CVATMarkdown from 'components/common/cvat-markdown';
import TargetStorageField from 'components/storage/target-storage-field';

const core = getCore();
Expand All @@ -36,6 +37,7 @@ const initialValues: FormValues = {

function ExportBackupModal(): JSX.Element {
const dispatch = useDispatch();
const history = useHistory();
const [form] = Form.useForm();
const [instanceType, setInstanceType] = useState('');
const [useDefaultStorage, setUseDefaultStorage] = useState(true);
Expand Down Expand Up @@ -100,11 +102,11 @@ function ExportBackupModal(): JSX.Element {
);
closeModal();

const description = 'Backup export was started. You can check progress [here](/requests)';
const description = 'Backup export was started. You can check progress [here](/requests).';
Notification.info({
message: 'Backup export started',
description: (
<ReactMarkdown>{description}</ReactMarkdown>
<CVATMarkdown history={history}>{description}</CVATMarkdown>
),
className: 'cvat-notification-notice-export-backup-start',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import './styles.scss';
import React, { useState, useEffect, useCallback } from 'react';
import { connect, useDispatch } from 'react-redux';
import { useHistory } from 'react-router';
import Modal from 'antd/lib/modal';
import Notification from 'antd/lib/notification';
import { DownloadOutlined } from '@ant-design/icons';
Expand All @@ -16,12 +17,12 @@ import Form from 'antd/lib/form';
import Switch from 'antd/lib/switch';
import Space from 'antd/lib/space';
import TargetStorageField from 'components/storage/target-storage-field';
import CVATMarkdown from 'components/common/cvat-markdown';
import { CombinedState, StorageLocation } from 'reducers';
import { exportActions, exportDatasetAsync } from 'actions/export-actions';
import {
Dumper, ProjectOrTaskOrJob, Job, Project, Storage, StorageData, Task,
} from 'cvat-core-wrapper';
import ReactMarkdown from 'react-markdown';

type FormValues = {
selectedFormat: string | undefined;
Expand Down Expand Up @@ -59,6 +60,7 @@ function ExportDatasetModal(props: StateToProps): JSX.Element {
const [defaultStorageCloudId, setDefaultStorageCloudId] = useState<number>();
const [helpMessage, setHelpMessage] = useState('');
const dispatch = useDispatch();
const history = useHistory();

useEffect(() => {
if (instance instanceof Project) {
Expand Down Expand Up @@ -121,7 +123,7 @@ function ExportDatasetModal(props: StateToProps): JSX.Element {
Notification.info({
message: `${resource} export started`,
description: (
<ReactMarkdown>{description}</ReactMarkdown>
<CVATMarkdown history={history}>{description}</CVATMarkdown>
),
className: `cvat-notification-notice-export-${instanceType.split(' ')[0]}-start`,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import './styles.scss';
import React, { useCallback, useEffect, useReducer } from 'react';
import { connect, useDispatch } from 'react-redux';
import ReactMarkdown from 'react-markdown';
import { useHistory } from 'react-router';
import Modal from 'antd/lib/modal';
import Form, { RuleObject } from 'antd/lib/form';
import Text from 'antd/lib/typography/Text';
Expand All @@ -19,6 +19,7 @@ import {
UploadOutlined, InboxOutlined, QuestionCircleOutlined,
} from '@ant-design/icons';
import CVATTooltip from 'components/common/cvat-tooltip';
import CVATMarkdown from 'components/common/cvat-markdown';
import { CombinedState, StorageLocation } from 'reducers';
import { importActions, importDatasetAsync } from 'actions/import-actions';
import Space from 'antd/lib/space';
Expand Down Expand Up @@ -278,6 +279,7 @@ function ImportDatasetModal(props: StateToProps): JSX.Element {
} = props;
const [form] = Form.useForm();
const appDispatch = useDispatch();
const history = useHistory();

const [state, dispatch] = useReducer(reducer, {
instanceType: '',
Expand Down Expand Up @@ -462,11 +464,11 @@ function ImportDatasetModal(props: StateToProps): JSX.Element {
));
const resToPrint = uploadParams.resource.charAt(0).toUpperCase() + uploadParams.resource.slice(1);
const description = `${resToPrint} import was started for ${instanceType}.` +
' You can check progress [here](/requests)';
' You can check progress [here](/requests).';
Notification.info({
message: `${resToPrint} import started`,
description: (
<ReactMarkdown>{description}</ReactMarkdown>
<CVATMarkdown history={history}>{description}</CVATMarkdown>
),
className: `cvat-notification-notice-import-${uploadParams.resource}-start`,
});
Expand Down
Loading
Loading