From 64fe3a2c7043854e74a7a688facbd6f57c26bda4 Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Mon, 21 Aug 2023 17:26:36 +0300 Subject: [PATCH] Open org immediately after it was created (#6705) ### Motivation and context In usual use-case users hardly ever want to create many organizations ### How has this been tested? ### Checklist - [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. --- CHANGELOG.md | 2 +- cvat-ui/src/actions/organization-actions.ts | 6 ++---- .../create-organization-form.tsx | 15 +++++++-------- cvat-ui/src/reducers/index.ts | 1 - cvat-ui/src/reducers/organizations-reducer.ts | 14 -------------- .../case_113_new_organization_pipeline.js | 1 - tests/cypress/e2e/webhooks.js | 1 - tests/cypress/support/commands_organizations.js | 2 +- 8 files changed, 11 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4046439bbb50..5e5176f32c3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 () ### Deprecated diff --git a/cvat-ui/src/actions/organization-actions.ts b/cvat-ui/src/actions/organization-actions.ts index 4a2c72936af8..01fa06eaa42c 100644 --- a/cvat-ui/src/actions/organization-actions.ts +++ b/cvat-ui/src/actions/organization-actions.ts @@ -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', @@ -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 }, ), @@ -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)); } }; diff --git a/cvat-ui/src/components/create-organization-page/create-organization-form.tsx b/cvat-ui/src/components/create-organization-page/create-organization-form.tsx index 3ec2b66c742b..211fd251cfe6 100644 --- a/cvat-ui/src/components/create-organization-page/create-organization-form.tsx +++ b/cvat-ui/src/components/create-organization-page/create-organization-form.tsx @@ -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(); 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; @@ -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)), ); }; diff --git a/cvat-ui/src/reducers/index.ts b/cvat-ui/src/reducers/index.ts index 2207d73b807d..b84b34146c14 100644 --- a/cvat-ui/src/reducers/index.ts +++ b/cvat-ui/src/reducers/index.ts @@ -874,7 +874,6 @@ export interface OrganizationState { current?: Organization | null; initialized: boolean; fetching: boolean; - creating: boolean; updating: boolean; inviting: boolean; leaving: boolean; diff --git a/cvat-ui/src/reducers/organizations-reducer.ts b/cvat-ui/src/reducers/organizations-reducer.ts index 8adb025a87b8..fbc8b1e51131 100644 --- a/cvat-ui/src/reducers/organizations-reducer.ts +++ b/cvat-ui/src/reducers/organizations-reducer.ts @@ -11,7 +11,6 @@ const defaultState: OrganizationState = { list: [], initialized: false, fetching: false, - creating: false, updating: false, inviting: false, leaving: false, @@ -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: { diff --git a/tests/cypress/e2e/actions_organizations/case_113_new_organization_pipeline.js b/tests/cypress/e2e/actions_organizations/case_113_new_organization_pipeline.js index 17f683fa2689..a88bb78f43f2 100644 --- a/tests/cypress/e2e/actions_organizations/case_113_new_organization_pipeline.js +++ b/tests/cypress/e2e/actions_organizations/case_113_new_organization_pipeline.js @@ -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.', () => { diff --git a/tests/cypress/e2e/webhooks.js b/tests/cypress/e2e/webhooks.js index d1d64d9b42b8..08b759d2858e 100644 --- a/tests/cypress/e2e/webhooks.js +++ b/tests/cypress/e2e/webhooks.js @@ -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, diff --git a/tests/cypress/support/commands_organizations.js b/tests/cypress/support/commands_organizations.js index 29b478c00496..94ba5fede18b 100644 --- a/tests/cypress/support/commands_organizations.js +++ b/tests/cypress/support/commands_organizations.js @@ -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); });