diff --git a/public/app/features/all.ts b/public/app/features/all.ts index d5e684e4a4e..d8dbc24be9a 100644 --- a/public/app/features/all.ts +++ b/public/app/features/all.ts @@ -9,7 +9,6 @@ import './admin'; import './alerting/NotificationsEditCtrl'; import './alerting/NotificationsListCtrl'; import './manage-dashboards'; -import './teams/CreateTeamCtrl'; import './profile/all'; import './datasources/settings/HttpSettingsCtrl'; import './datasources/settings/TlsAuthSettingsCtrl'; diff --git a/public/app/features/teams/CreateTeam.test.tsx b/public/app/features/teams/CreateTeam.test.tsx new file mode 100644 index 00000000000..66d19bf3850 --- /dev/null +++ b/public/app/features/teams/CreateTeam.test.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import { CreateTeam, Props } from './CreateTeam'; +import { mockActionCreator } from 'app/core/redux'; +import { updateLocation } from 'app/core/actions'; + +describe('Render', () => { + it('should render component', () => { + const props: Props = { + updateLocation: mockActionCreator(updateLocation), + navModel: {} as any, + }; + const wrapper = shallow(); + + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/app/features/teams/CreateTeam.tsx b/public/app/features/teams/CreateTeam.tsx new file mode 100644 index 00000000000..cb793230196 --- /dev/null +++ b/public/app/features/teams/CreateTeam.tsx @@ -0,0 +1,105 @@ +import React, { PureComponent } from 'react'; +import Page from 'app/core/components/Page/Page'; +import { hot } from 'react-hot-loader'; +import { FormField, Button } from '@grafana/ui'; +import { NavModel } from '@grafana/data'; +import { getBackendSrv } from '@grafana/runtime'; +import { updateLocation } from '../../core/actions'; +import { connect } from 'react-redux'; +import { getNavModel } from 'app/core/selectors/navModel'; +import { StoreState } from 'app/types'; + +export interface Props { + navModel: NavModel; + updateLocation: typeof updateLocation; +} + +interface State { + name: string; + email: string; +} + +export class CreateTeam extends PureComponent { + state: State = { + name: '', + email: '', + }; + + create = async (event: React.FormEvent) => { + event.preventDefault(); + + const { name, email } = this.state; + + const result = await getBackendSrv().post('/api/teams', { name, email }); + if (result.teamId) { + this.props.updateLocation({ path: `/org/teams/edit/${result.teamId}` }); + } + }; + + onEmailChange = (event: React.ChangeEvent) => { + this.setState({ + email: event.target.value, + }); + }; + + onNameChange = (event: React.ChangeEvent) => { + this.setState({ + name: event.target.value, + }); + }; + + render() { + const { navModel } = this.props; + const { name, email } = this.state; + + return ( + + + <> +

New Team

+ +
+ + +
+ +
+ + +
+
+ ); + } +} + +function mapStateToProps(state: StoreState) { + return { + navModel: getNavModel(state.navIndex, 'teams'), + }; +} + +const mapDispatchToProps = { + updateLocation, +}; + +export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(CreateTeam)); diff --git a/public/app/features/teams/CreateTeamCtrl.ts b/public/app/features/teams/CreateTeamCtrl.ts deleted file mode 100644 index df00c87c10f..00000000000 --- a/public/app/features/teams/CreateTeamCtrl.ts +++ /dev/null @@ -1,29 +0,0 @@ -import coreModule from 'app/core/core_module'; -import { BackendSrv } from 'app/core/services/backend_srv'; -import { ILocationService } from 'angular'; -import { NavModelSrv } from 'app/core/core'; - -export class CreateTeamCtrl { - name: string; - email: string; - navModel: any; - - /** @ngInject */ - constructor(private backendSrv: BackendSrv, private $location: ILocationService, navModelSrv: NavModelSrv) { - this.navModel = navModelSrv.getNav('cfg', 'teams', 0); - } - - create() { - const payload = { - name: this.name, - email: this.email, - }; - this.backendSrv.post('/api/teams', payload).then((result: any) => { - if (result.teamId) { - this.$location.path('/org/teams/edit/' + result.teamId); - } - }); - } -} - -coreModule.controller('CreateTeamCtrl', CreateTeamCtrl); diff --git a/public/app/features/teams/__snapshots__/CreateTeam.test.tsx.snap b/public/app/features/teams/__snapshots__/CreateTeam.test.tsx.snap new file mode 100644 index 00000000000..c06e4f817c8 --- /dev/null +++ b/public/app/features/teams/__snapshots__/CreateTeam.test.tsx.snap @@ -0,0 +1,50 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Render should render component 1`] = ` + + +

+ New Team +

+
+ + +
+ +
+ +
+
+`; diff --git a/public/app/features/teams/partials/create_team.html b/public/app/features/teams/partials/create_team.html deleted file mode 100644 index c62b8992a96..00000000000 --- a/public/app/features/teams/partials/create_team.html +++ /dev/null @@ -1,26 +0,0 @@ - - -
-

New Team

- -
-
- Name - -
-
- - Email - - This is optional and is primarily used for allowing custom team avatars. - - - -
-
- -
-
-
diff --git a/public/app/routes/routes.ts b/public/app/routes/routes.ts index 2d1985be4dd..b60d9b7fc98 100644 --- a/public/app/routes/routes.ts +++ b/public/app/routes/routes.ts @@ -244,9 +244,12 @@ export function setupAngularRoutes($routeProvider: route.IRouteProvider, $locati }, }) .when('/org/teams/new', { - templateUrl: 'public/app/features/teams/partials/create_team.html', - controller: 'CreateTeamCtrl', - controllerAs: 'ctrl', + template: '', + resolve: { + roles: () => (config.editorsCanAdmin ? [] : ['Admin']), + component: () => + SafeDynamicImport(import(/* webpackChunkName: "CreateTeam" */ 'app/features/teams/CreateTeam')), + }, }) .when('/org/teams/edit/:id/:page?', { template: '',