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 error handling if organizations request is failed #7063

Merged
merged 10 commits into from
Oct 30, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- There is no switcher to personal workspace if an organization request failed
(<https://github.com/opencv/cvat/pull/7063>)
7 changes: 7 additions & 0 deletions cvat-ui/src/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Menu from 'antd/lib/menu';
import Dropdown from 'antd/lib/dropdown';
import Modal from 'antd/lib/modal';
import Text from 'antd/lib/typography/Text';
import notification from 'antd/lib/notification';

import config from 'config';

Expand Down Expand Up @@ -169,6 +170,12 @@ function HeaderComponent(props: Props): JSX.Element {
if (isMounted()) {
setOrganizationList(organizations);
}
}).catch((error: unknown) => {
setOrganizationList([]);
notification.error({
message: 'Could not receive a list of organizations',
description: error instanceof Error ? error.message : '',
});
});
}, []);

Expand Down
7 changes: 7 additions & 0 deletions cvat-ui/src/components/header/organizations-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './styles.scss';
import _ from 'lodash';
import React, { useEffect, useState } from 'react';
import AutoComplete from 'antd/lib/auto-complete';
import notification from 'antd/lib/notification';

import { Organization } from 'cvat-core-wrapper';

Expand All @@ -25,6 +26,12 @@ function OrganizationsSearch(props: {
if (searchPhrase) {
searchOrganizations(searchPhrase).then((organizations) => {
setSearchResults(organizations);
}).catch((error: unknown) => {
setSearchResults([]);
notification.error({
message: 'Could not receive a list of organizations',
description: error instanceof Error ? error.message : '',
});
});
}
}, [searchPhrase]);
Expand Down
6 changes: 3 additions & 3 deletions cvat/apps/organizations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class OrganizationViewSet(viewsets.GenericViewSet,
PartialUpdateModelMixin,
):
queryset = Organization.objects.select_related('owner').all()
search_fields = ('name', 'owner')
filter_fields = list(search_fields) + ['id', 'slug']
simple_filters = list(search_fields) + ['slug']
search_fields = ('name', 'owner', 'slug')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name may be empty. It makes it impossible to find some organizations via search query

filter_fields = list(search_fields) + ['id']
simple_filters = list(search_fields)
lookup_fields = {'owner': 'owner__username'}
ordering_fields = list(filter_fields)
ordering = '-id'
Expand Down
7 changes: 4 additions & 3 deletions cvat/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3113,7 +3113,7 @@ paths:

Details about the syntax used can be found at the link: https://jsonlogic.com/

Available filter_fields: ['name', 'owner', 'id', 'slug'].
Available filter_fields: ['name', 'owner', 'slug', 'id'].
schema:
type: string
- name: name
Expand Down Expand Up @@ -3141,7 +3141,8 @@ paths:
- name: search
required: false
in: query
description: 'A search term. Available search_fields: (''name'', ''owner'')'
description: 'A search term. Available search_fields: (''name'', ''owner'',
''slug'')'
schema:
type: string
- name: slug
Expand All @@ -3153,7 +3154,7 @@ paths:
required: false
in: query
description: 'Which field to use when ordering the results. Available ordering_fields:
[''name'', ''owner'', ''id'', ''slug'']'
[''name'', ''owner'', ''slug'', ''id'']'
schema:
type: string
tags:
Expand Down
Loading