Skip to content

Commit

Permalink
Fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Oct 13, 2023
1 parent 1b62e88 commit 3abff8f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 52 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20231013_135447_boris_disable_fetch_all_orgs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Changed

- Client does not load all the organizations onload anymore
(<https://github.com/opencv/cvat/pull/7004>)
6 changes: 0 additions & 6 deletions cvat-core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ function build() {
set removeUnderlyingMaskPixels(value: boolean) {
config.removeUnderlyingMaskPixels = value;
},
get onOrganizationChange(): (orgId: number) => void {
return config.onOrganizationChange;
},
set onOrganizationChange(value: (orgId: number) => void) {
config.onOrganizationChange = value;
},
},
client: {
version: `${pjson.version}`,
Expand Down
1 change: 0 additions & 1 deletion cvat-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const config = {
origin: '',
uploadChunkSize: 100,
removeUnderlyingMaskPixels: false,
onOrganizationChange: null,
};

export default config;
36 changes: 23 additions & 13 deletions cvat-core/src/server-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,6 @@ Axios.interceptors.request.use((reqConfig) => {
return reqConfig;
});

Axios.interceptors.response.use((response) => {
if (isResourceURL(response.config.url) &&
'organization' in (response.data || {})
) {
const newOrg: number | null = response.data.organization;
if (config.organization.organizationID !== newOrg) {
config?.onOrganizationChange(newOrg);
}
}

return response;
});

let token = store.get('token');
if (token) {
Axios.defaults.headers.common.Authorization = `Token ${token}`;
Expand Down Expand Up @@ -2012,6 +1999,29 @@ async function getOrganizations(filter) {
return response.data.results;
}

Axios.interceptors.response.use((response) => {
if (isResourceURL(response.config.url) &&
'organization' in (response.data || {})
) {
const newOrgId: number | null = response.data.organization;
if (newOrgId === null && config.organization.organizationID !== null) {
localStorage.removeItem('currentOrganization');
window.location.reload();
} else if (config.organization.organizationID !== newOrgId) {
getOrganizations({
filter: `{"and":[{"==":[{"var":"id"},${newOrgId}]}]}`,
}).then(([organization]) => {
if (organization) {
localStorage.setItem('currentOrganization', organization.slug);
window.location.reload();
}
});
}
}

return response;
});

async function createOrganization(data: SerializedOrganization): Promise<SerializedOrganization> {
const { backendAPI } = config;

Expand Down
1 change: 1 addition & 0 deletions cvat-ui/src/actions/organization-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export function activateOrganizationAsync(): ThunkAction {
} : {});
const [organization] = organizations;
if (organization?.slug === curSlug) {
await core.organizations.activate(organization);
dispatch(organizationActions.activateOrganizationSuccess(organization));
} else {
localStorage.removeItem('currentOrganization');
Expand Down
2 changes: 0 additions & 2 deletions cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import EmailVerificationSentPage from './email-confirmation-pages/email-verifica
import IncorrectEmailConfirmationPage from './email-confirmation-pages/incorrect-email-confirmation';
import CreateModelPage from './create-model-page/create-model-page';
import CreateJobPage from './create-job-page/create-job-page';
import OrganizationWatcher from './watchers/organization-watcher';
import AnalyticsPage from './analytics-page/analytics-page';

interface CVATAppProps {
Expand Down Expand Up @@ -500,7 +499,6 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
{ loggedInModals.map((Component, idx) => (
<Component key={idx} targetProps={this.props} targetState={this.state} />
))}
<OrganizationWatcher />
{/* eslint-disable-next-line */}
<a id='downloadAnchor' target='_blank' style={{ display: 'none' }} download />
</Layout.Content>
Expand Down
30 changes: 0 additions & 30 deletions cvat-ui/src/components/watchers/organization-watcher.tsx

This file was deleted.

0 comments on commit 3abff8f

Please sign in to comment.