Skip to content

Commit

Permalink
Open org immediately after it was created (#6705)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
In usual use-case users hardly ever want to create many organizations

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [x] I have added a description of my changes into the
[CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [x] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
bsekachev authored Aug 21, 2023
1 parent 61c39b5 commit 64fe3a2
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- TBD
- Organization now opened immediately after it is created (<https://github.com/opencv/cvat/pull/6705>)

### Deprecated

Expand Down
6 changes: 2 additions & 4 deletions cvat-ui/src/actions/organization-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export enum OrganizationActionsTypes {
GET_ORGANIZATIONS_FAILED = 'GET_ORGANIZATIONS_FAILED',
ACTIVATE_ORGANIZATION_SUCCESS = 'ACTIVATE_ORGANIZATION_SUCCESS',
ACTIVATE_ORGANIZATION_FAILED = 'ACTIVATE_ORGANIZATION_FAILED',
CREATE_ORGANIZATION = 'CREATE_ORGANIZATION',
CREATE_ORGANIZATION_SUCCESS = 'CREATE_ORGANIZATION_SUCCESS',
CREATE_ORGANIZATION_FAILED = 'CREATE_ORGANIZATION_FAILED',
UPDATE_ORGANIZATION = 'UPDATE_ORGANIZATION',
Expand Down Expand Up @@ -46,7 +45,6 @@ const organizationActions = {
OrganizationActionsTypes.GET_ORGANIZATIONS_SUCCESS, { list },
),
getOrganizationsFailed: (error: any) => createAction(OrganizationActionsTypes.GET_ORGANIZATIONS_FAILED, { error }),
createOrganization: () => createAction(OrganizationActionsTypes.CREATE_ORGANIZATION),
createOrganizationSuccess: (organization: any) => createAction(
OrganizationActionsTypes.CREATE_ORGANIZATION_SUCCESS, { organization },
),
Expand Down Expand Up @@ -142,17 +140,17 @@ export function getOrganizationsAsync(): ThunkAction {
export function createOrganizationAsync(
organizationData: Store,
onCreateSuccess?: (createdSlug: string) => void,
onCreateFailed?: () => void,
): ThunkAction {
return async function (dispatch) {
const { slug } = organizationData;
const organization = new core.classes.Organization(organizationData);
dispatch(organizationActions.createOrganization());

try {
const createdOrganization = await organization.save();
dispatch(organizationActions.createOrganizationSuccess(createdOrganization));
if (onCreateSuccess) onCreateSuccess(createdOrganization.slug);
} catch (error) {
if (onCreateFailed) onCreateFailed();
dispatch(organizationActions.createOrganizationFailed(slug, error));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
//
// SPDX-License-Identifier: MIT

import React from 'react';
import React, { useState } from 'react';
import { useHistory } from 'react-router';
import { useDispatch, useSelector } from 'react-redux';
import { useDispatch } from 'react-redux';
import Form from 'antd/lib/form';
import Input from 'antd/lib/input';
import Button from 'antd/lib/button';
import Space from 'antd/lib/space';
import { Store } from 'antd/lib/form/interface';
import { useForm } from 'antd/lib/form/Form';
import notification from 'antd/lib/notification';

import { createOrganizationAsync } from 'actions/organization-actions';
import validationPatterns from 'utils/validation-patterns';
import { CombinedState } from 'reducers';

function CreateOrganizationForm(): JSX.Element {
const [form] = useForm<Store>();
const dispatch = useDispatch();
const history = useHistory();
const creating = useSelector((state: CombinedState) => state.organizations.creating);
const [creating, setCreating] = useState(false);
const MAX_SLUG_LEN = 16;
const MAX_NAME_LEN = 64;

Expand All @@ -36,11 +34,12 @@ function CreateOrganizationForm(): JSX.Element {
...(location ? { location } : {}),
};

setCreating(true);
dispatch(
createOrganizationAsync(rest, (createdSlug: string): void => {
form.resetFields();
notification.info({ message: `Organization ${createdSlug} has been successfully created` });
}),
localStorage.setItem('currentOrganization', createdSlug);
(window as Window).location = '/organization';
}, () => setCreating(false)),
);
};

Expand Down
1 change: 0 additions & 1 deletion cvat-ui/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,6 @@ export interface OrganizationState {
current?: Organization | null;
initialized: boolean;
fetching: boolean;
creating: boolean;
updating: boolean;
inviting: boolean;
leaving: boolean;
Expand Down
14 changes: 0 additions & 14 deletions cvat-ui/src/reducers/organizations-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const defaultState: OrganizationState = {
list: [],
initialized: false,
fetching: false,
creating: false,
updating: false,
inviting: false,
leaving: false,
Expand Down Expand Up @@ -55,23 +54,10 @@ export default function (
fetching: false,
};
}
case OrganizationActionsTypes.CREATE_ORGANIZATION: {
return {
...state,
creating: true,
};
}
case OrganizationActionsTypes.CREATE_ORGANIZATION_SUCCESS: {
return {
...state,
list: [...state.list, action.payload.organization],
creating: false,
};
}
case OrganizationActionsTypes.CREATE_ORGANIZATION_FAILED: {
return {
...state,
creating: false,
};
}
case OrganizationActionsTypes.UPDATE_ORGANIZATION: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ context('New organization pipeline.', () => {
describe(`Testing case "${caseId}"`, () => {
it('The first user creates an organization and activates it.', () => {
cy.createOrganization(organizationParams);
cy.activateOrganization(organizationParams.shortName);
});

it('Open the organization settings. Invite members.', () => {
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/e2e/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ context('Webhooks pipeline.', () => {
cy.visit('auth/login');
cy.login();
cy.createOrganization(organizationParams);
cy.activateOrganization(organizationParams.shortName);
cy.visit('/projects');
cy.createProjects(
project.name,
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/support/commands_organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Cypress.Commands.add('createOrganization', (organizationParams) => {
idWrapper.id = interception.response.body.id;
});
});

cy.get('.cvat-organization-page').should('exist').and('be.visible');
return cy.wrap(idWrapper);
});

Expand Down

0 comments on commit 64fe3a2

Please sign in to comment.