chore: move onboarding to top level (#1131)

* chore: move onboarding to top level

* chore: add types

* Update ui/admin/app/routes/onboarding.js

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>

* fix: broken paths

* chore: fix broken success route and simplify error handling

* fix: tests

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
This commit is contained in:
Randall MoreyandCameron Perera authored and GitHub committed 2022-06-13 16:38:18 -04:00
1 parent d69b0f90d8
commit 15dc735322
18 files changed
+94 -58

No files matched your search

+3 -11
View File
@@ -18,15 +18,6 @@ Router.map(function () {
});
});
this.route('onboarding', function () {
this.route('quick-setup', function () {
this.route('choose-path');
this.route('create-resources', function () {
this.route('success');
});
});
});
this.route('scopes', function () {});
this.route('edit');
this.route('new');
@@ -136,8 +127,9 @@ Router.map(function () {
this.route('onboarding', function () {
this.route('quick-setup', function () {
this.route('choose-path');
this.route('create-resources');
this.route('success');
this.route('create-resources', function () {
this.route('success');
});
});
});
});
+36
View File
@@ -0,0 +1,36 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class OnboardingRoute extends Route {
// =services
@service session;
@service router;
// =methods
/**
* If arriving here unauthenticated, redirect to index for further processing.
*/
beforeModel() {
if (!this.session.isAuthenticated) this.router.transitionTo('index');
}
/**
* List all scopes (orgs) under global.
*/
model() {
return this.store.query('scope', {
scope_id: 'global',
recursive: true,
});
}
/**
* If any orgs already exist, redirect to index to skip onboarding.
*/
redirect(model) {
// If there are orgs already created, redirect to index.
if (model.length) this.router.transitionTo('index');
}
}
@@ -2,7 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class ScopesScopeOnboardingQuickSetupChoosePathRoute extends Route {
export default class OnboardingQuickSetupChoosePathRoute extends Route {
// =services
@service router;
@@ -13,9 +13,7 @@ export default class ScopesScopeOnboardingQuickSetupChoosePathRoute extends Rout
choosePath(path = 'guided') {
switch (path) {
case 'guided':
this.router.transitionTo(
'scopes.scope.onboarding.quick-setup.create-resources'
);
this.router.transitionTo('onboarding.quick-setup.create-resources');
break;
case 'manual':
default:
@@ -4,7 +4,7 @@ import { action } from '@ember/object';
import { loading } from 'ember-loading';
import { notifyError } from 'core/decorators/notify';
export default class ScopesScopeOnboardingQuickSetupCreateResourcesRoute extends Route {
export default class OnboardingQuickSetupCreateResourcesRoute extends Route {
// =services
@service router;
@@ -26,6 +26,7 @@ export default class ScopesScopeOnboardingQuickSetupCreateResourcesRoute extends
description: 'Sample project created by quick setup',
}),
hostCatalog: this.store.createRecord('host-catalog', {
type: 'static',
name: 'All Databases',
description: 'Sample host catalog created by quick setup',
}),
@@ -38,6 +39,7 @@ export default class ScopesScopeOnboardingQuickSetupCreateResourcesRoute extends
description: 'Sample host created by quick setup',
}),
target: this.store.createRecord('target', {
type: 'tcp',
name: 'CRM Database target',
description: 'Sample target created by quick setup',
}),
@@ -48,14 +50,15 @@ export default class ScopesScopeOnboardingQuickSetupCreateResourcesRoute extends
@action
@loading
@notifyError(({ message }) => message)
async createResource(hostAddress = '1234', targetPort = '42') {
@notifyError(function () {
return this.intl.t('errors.quick-setup-failed.description');
})
async createResources(hostAddress = '1234', targetPort = '42') {
try {
await this.createOnboardingResourcesAndRedirect(hostAddress, targetPort);
} catch (e) {
const message = this.intl.t('errors.quick-setup-failed.description');
this.router.replaceWith('scopes.scope', 'global');
throw new Error(message);
throw new Error();
}
}
@@ -80,7 +83,7 @@ export default class ScopesScopeOnboardingQuickSetupCreateResourcesRoute extends
await target.save();
await target.addHostSources([hostSet.id]);
this.router.transitionTo(
'scopes.scope.onboarding.quick-setup.create-resources.success'
'onboarding.quick-setup.create-resources.success'
);
} else {
this.router.transitionTo(
@@ -0,0 +1,9 @@
import Route from '@ember/routing/route';
export default class OnboardingQuickSetupCreateResourcesSuccessRoute extends Route {
// =methods
model() {
return this.modelFor('onboarding.quick-setup.create-resources');
}
}
@@ -1,11 +0,0 @@
import Route from '@ember/routing/route';
export default class ScopesScopeOnboardingQuickSetupCreateResourcesSuccessRoute extends Route {
// =methods
model() {
return this.modelFor(
'scopes.scope.onboarding.quick-setup.create-resources'
);
}
}
+2
View File
@@ -0,0 +1,2 @@
{{page-title 'Onboarding'}}
{{outlet}}
@@ -0,0 +1,2 @@
{{page-title 'CreateResources'}}
{{outlet}}
@@ -8,7 +8,7 @@
<h3>{{t 'onboarding.quick-start.titles.create-resource'}}</h3>
<p>{{t 'onboarding.quick-start.descriptions.create-resource'}}</p>
<Form::Onboarding::CreateResources
@submit={{route-action 'createResource'}}
@submit={{route-action 'createResources'}}
/>
</:body>
</Rose::Frame>
@@ -9,9 +9,9 @@ module('Acceptance | onboarding | choose-path', function (hooks) {
setupMirage(hooks);
const urls = {
choosePath: '/scopes/global/onboarding/quick-setup/choose-path',
choosePath: '/onboarding/quick-setup/choose-path',
newOrg: '/scopes/global/new',
createResources: '/scopes/global/onboarding/quick-setup/create-resources',
createResources: '/onboarding/quick-setup/create-resources',
};
hooks.beforeEach(function () {
@@ -9,9 +9,8 @@ module('Acceptance | onboarding | create-resources', function (hooks) {
setupMirage(hooks);
const urls = {
createResources: '/scopes/global/onboarding/quick-setup/create-resources',
successPath:
'/scopes/global/onboarding/quick-setup/create-resources/success',
createResources: '/onboarding/quick-setup/create-resources',
successPath: '/onboarding/quick-setup/create-resources/success',
};
hooks.beforeEach(function () {
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | onboarding', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup('route:onboarding');
assert.ok(route);
});
});
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | onboarding/quick-setup/choose-path', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup('route:onboarding/quick-setup/choose-path');
assert.ok(route);
});
});
@@ -2,13 +2,13 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/onboarding/quick-setup/choose-path',
'Unit | Route | onboarding/quick-setup/create-resources',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/onboarding/quick-setup/choose-path'
'route:onboarding/quick-setup/create-resources'
);
assert.ok(route);
});
@@ -2,13 +2,13 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/onboarding/quick-setup/create-resources',
'Unit | Route | onboarding/quick-setup/create-resources/success',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/onboarding/quick-setup/create-resources'
'route:onboarding/quick-setup/create-resources/success'
);
assert.ok(route);
});
@@ -1,16 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/onboarding/quick-setup/create-resources/success',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/onboarding/quick-setup/create-resources/success'
);
assert.ok(route);
});
}
);