Chore onboarding routing logic (#1123)

* chore: 🤖 stub out onboarding routes

* chore: initial onboarding routing logic

* chore: initial routing logic and resource creation

* chore: route "manual" to new org

* Update en-us.yaml

* fix: linting

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
This commit is contained in:
Randall MoreyandDharini Jeeva authored and GitHub committed 2022-06-03 13:25:53 -04:00
1 parent d4ac887f7a
commit 24f630f084
18 files changed
+181 -34

No files matched your search

@@ -19,3 +19,5 @@ authentication-failed:
title: Authentication Failed
origin-verification-failed:
description: Unable to connect to the specified origin. Please check the URL and try again.
quick-setup-failed:
description: We're sorry, quick setup was unable to generate all resources.
+9
View File
@@ -18,6 +18,15 @@ 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');
@@ -1,3 +0,0 @@
import Route from '@ember/routing/route';
export default class OnboardingQuickSetupChoosePathRoute extends Route {}
@@ -1,3 +0,0 @@
import Route from '@ember/routing/route';
export default class OnboardingQuickSetupCreateResourcesRoute extends Route {}
@@ -1,3 +0,0 @@
import Route from '@ember/routing/route';
export default class OnboardingQuickSetupSuccessRoute extends Route {}
@@ -0,0 +1,26 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class ScopesScopeOnboardingQuickSetupChoosePathRoute extends Route {
// =services
@service router;
// =actions
@action
choosePath(path = 'guided') {
switch (path) {
case 'guided':
this.router.transitionTo(
'scopes.scope.onboarding.quick-setup.create-resources'
);
break;
case 'manual':
default:
this.router.transitionTo('scopes.scope.new', 'global');
break;
}
}
}
@@ -0,0 +1,93 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { loading } from 'ember-loading';
import { notifyError } from 'core/decorators/notify';
export default class ScopesScopeOnboardingQuickSetupCreateResourcesRoute extends Route {
// =services
@service router;
@service intl;
// =methods
async model() {
return {
org: this.store.createRecord('scope', {
type: 'org',
scopeID: 'global',
name: 'Marketing Department',
description: 'Sample org created by quick setup',
}),
project: this.store.createRecord('scope', {
type: 'project',
name: 'New widget ad campaign',
description: 'Sample project created by quick setup',
}),
hostCatalog: this.store.createRecord('host-catalog', {
name: 'All Databases',
description: 'Sample host catalog created by quick setup',
}),
hostSet: this.store.createRecord('host-set', {
name: 'QA Databases',
description: 'Sample host set created by quick setup',
}),
host: this.store.createRecord('host', {
name: 'CRM Database',
description: 'Sample host created by quick setup',
}),
target: this.store.createRecord('target', {
name: 'CRM Database target',
description: 'Sample target created by quick setup',
}),
};
}
// =actions
@action
@loading
@notifyError(({ message }) => message)
async submit(event, 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);
}
}
async createOnboardingResourcesAndRedirect(hostAddress, targetPort) {
const { org, project, hostCatalog, hostSet, host, target } =
this.currentModel;
// The Procedure
await org.save();
project.scopeID = org.id;
await project.save();
hostCatalog.scopeID = project.id;
await hostCatalog.save();
hostSet.host_catalog_id = hostCatalog.id;
await hostSet.save();
host.host_catalog_id = hostCatalog.id;
if (hostAddress) {
host.address = hostAddress;
await host.save();
await hostSet.addHosts([host.id]);
target.scopeID = project.id;
target.default_port = targetPort;
await target.save();
await target.addHostSources([hostSet.id]);
this.router.transitionTo(
'scopes.scope.onboarding.quick-setup.create-resources.success'
);
} else {
this.router.transitionTo(
'scopes.scope.host-catalogs.host-catalog.hosts',
org.id,
hostCatalog.id
);
}
}
}
@@ -0,0 +1,11 @@
import Route from '@ember/routing/route';
export default class ScopesScopeOnboardingQuickSetupCreateResourcesSuccessRoute extends Route {
// =methods
model() {
return this.modelFor(
'scopes.scope.onboarding.quick-setup.create-resources'
);
}
}
+3 -1
View File
@@ -223,7 +223,9 @@
.is-loading {
.rose-icon {
@keyframes hds-flight-icon-animation-rotation {
to {transform: rotate(360deg);}
to {
transform: rotate(360deg);
}
}
> svg {
@@ -0,0 +1,3 @@
<button type='button' {{on 'click' (route-action 'submit')}}>{{t
'actions.submit'
}}</button>
@@ -1,11 +0,0 @@
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);
});
});
@@ -1,11 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | onboarding/quick-setup/success', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup('route:onboarding/quick-setup/success');
assert.ok(route);
});
});
@@ -2,13 +2,13 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | onboarding/quick-setup/create-resources',
'Unit | Route | scopes/scope/onboarding/quick-setup/choose-path',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:onboarding/quick-setup/create-resources'
'route:scopes/scope/onboarding/quick-setup/choose-path'
);
assert.ok(route);
});
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/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/create-resources'
);
assert.ok(route);
});
}
);
@@ -0,0 +1,16 @@
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);
});
}
);