Skip to content

Commit

Permalink
Opening update CS page sends infinite requests when CS id does not ex…
Browse files Browse the repository at this point in the history
…ist (#7828)

=
  • Loading branch information
bsekachev authored Apr 30, 2024
1 parent f2924d4 commit a8aa49f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Opening update CS page sends infinite requests when CS id does not exist
(<https://github.com/cvat-ai/cvat/pull/7828>)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// SPDX-License-Identifier: MIT

import './styles.scss';
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import React, { useEffect, useState } from 'react';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
import { Row, Col } from 'antd/lib/grid';
import Spin from 'antd/lib/spin';
Expand All @@ -22,16 +22,23 @@ interface ParamType {
export default function UpdateCloudStoragePageComponent(): JSX.Element {
const dispatch = useDispatch();
const cloudStorageId = +useParams<ParamType>().id;
const isFetching = useSelector((state: CombinedState) => state.cloudStorages.fetching);
const isInitialized = useSelector((state: CombinedState) => state.cloudStorages.initialized);
const cloudStorages = useSelector((state: CombinedState) => state.cloudStorages.current);
const [cloudStorage] = cloudStorages.filter((_cloudStorage) => _cloudStorage.id === cloudStorageId);
const [requested, setRequested] = useState(false);
const {
isFetching,
isInitialized,
cloudStorage,
} = useSelector((state: CombinedState) => ({
isFetching: state.cloudStorages.fetching,
isInitialized: state.cloudStorages.initialized,
cloudStorage: state.cloudStorages.current.find((_cloudStorage) => _cloudStorage.id === cloudStorageId),
}), shallowEqual);

useEffect(() => {
if (!cloudStorage && !isFetching) {
if (!cloudStorage && !requested && !isFetching) {
setRequested(true);
dispatch(getCloudStoragesAsync({ id: cloudStorageId }));
}
}, [isFetching]);
}, [requested, cloudStorage, isFetching]);

if (!cloudStorage && !isInitialized) {
return <Spin size='large' className='cvat-spinner' />;
Expand All @@ -42,7 +49,7 @@ export default function UpdateCloudStoragePageComponent(): JSX.Element {
<Result
className='cvat-not-found'
status='404'
title={`Sorry, but the cloud storage #${cloudStorageId} was not found`}
title='Sorry, but the requested cloud storage was not found'
subTitle='Please, be sure id you requested exists and you have appropriate permissions'
/>
);
Expand Down

0 comments on commit a8aa49f

Please sign in to comment.