chore: 🤖 alias target route (#2228)
This commit is contained in:
1 parent
c550faddb4
commit
bd65c91ff9
21 files changed
+745
-17
No files matched your search
@@ -37,6 +37,13 @@ export default class ScopesScopeTargetsTargetIndexController extends Controller
|
||||
return this.model.aliases.length > 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides when to show the flyout component
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get showFlyOutComponent() {
|
||||
return this.showFlyout && this.model.aliases.length > 3;
|
||||
}
|
||||
/**
|
||||
* Returns only the first three items in the aliases array if there are more than 3
|
||||
* @returns {array}
|
||||
|
||||
@@ -88,6 +88,8 @@ Router.map(function () {
|
||||
this.route('injected-application-credential-sources');
|
||||
this.route('add-brokered-credential-sources');
|
||||
this.route('add-injected-application-credential-sources');
|
||||
this.route('create-alias');
|
||||
this.route('manage-alias', { path: ':alias_id' }, function () {});
|
||||
this.route('enable-session-recording', function () {
|
||||
this.route('create-storage-bucket');
|
||||
});
|
||||
|
||||
@@ -140,4 +140,33 @@ export default class ScopesScopeTargetsRoute extends Route {
|
||||
this.router.replaceWith('scopes.scope.targets');
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an alias
|
||||
* @param {AliasModel} alias
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async deleteAlias(alias) {
|
||||
await alias.destroyRecord();
|
||||
await this.router.replaceWith('scopes.scope.targets.target');
|
||||
this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove destaination_id from alias
|
||||
* @param {AliasModel} alias
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.clear-success')
|
||||
async clearAlias(alias) {
|
||||
alias.destination_id = '';
|
||||
await alias.save();
|
||||
this.router.refresh('scopes.scope.targets.target');
|
||||
await this.router.transitionTo('scopes.scope.targets.target');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { loading } from 'ember-loading';
|
||||
import { TYPE_ALIAS_TARGET } from 'api/models/alias';
|
||||
|
||||
export default class ScopesScopeTargetsTargetCreateAliasRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service store;
|
||||
@service router;
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Creates a new unsaved alias.
|
||||
* @return {AliasModel}
|
||||
*/
|
||||
model() {
|
||||
const scopeModel = this.store.peekRecord('scope', 'global');
|
||||
const record = this.store.createRecord('alias', {
|
||||
type: TYPE_ALIAS_TARGET,
|
||||
});
|
||||
record.scopeModel = scopeModel;
|
||||
return record;
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Handle save
|
||||
* @param {AliasModel} alias
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess('notifications.save-success')
|
||||
async save(alias) {
|
||||
await alias.save();
|
||||
await this.router.transitionTo('scopes.scope.targets.target');
|
||||
this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback changes on alias.
|
||||
* @param {AliasModel} alias
|
||||
*/
|
||||
@action
|
||||
cancel(alias) {
|
||||
alias.rollbackAttributes();
|
||||
this.router.transitionTo('scopes.scope.targets.target');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { loading } from 'ember-loading';
|
||||
|
||||
export default class ScopesScopeTargetsTargetManageAliasRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service store;
|
||||
@service router;
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Creates a new unsaved alias.
|
||||
* @return {AliasModel}
|
||||
*/
|
||||
async model({ alias_id }) {
|
||||
return this.store.findRecord('alias', alias_id, {
|
||||
reload: true,
|
||||
});
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Handle save
|
||||
* @param {AliasModel} alias
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess('notifications.save-success')
|
||||
async save(alias) {
|
||||
await alias.save();
|
||||
await this.router.refresh('scopes.scope.targets.target');
|
||||
this.router.transitionTo('scopes.scope.targets.target');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback changes on alias.
|
||||
* @param {AliasModel} alias
|
||||
*/
|
||||
@action
|
||||
async cancel(alias) {
|
||||
alias.rollbackAttributes();
|
||||
await this.router.transitionTo('scopes.scope.targets.target');
|
||||
}
|
||||
}
|
||||
@@ -625,6 +625,7 @@
|
||||
|
||||
.target-sidebar-aliases {
|
||||
margin-bottom: 3rem;
|
||||
width: 300px;
|
||||
|
||||
.description {
|
||||
color: var(--token-form-helper-text-color);
|
||||
@@ -636,8 +637,28 @@
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.link-list-item:first-of-type {
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.link-list-item {
|
||||
margin-bottom: 0.5rem;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* stylelint-disable selector-class-pattern */
|
||||
.hds-card__container > ul {
|
||||
display: flex;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.hds-link-standalone__text {
|
||||
margin: 1rem 0;
|
||||
}
|
||||
/* stylelint-enable selector-class-pattern */
|
||||
|
||||
.hds-dropdown .hds-dropdown-toggle-icon {
|
||||
color: var(--stark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
{{!
|
||||
Copyright (c) HashiCorp, Inc.
|
||||
SPDX-License-Identifier: MPL-2.0
|
||||
}}
|
||||
|
||||
{{page-title (t 'titles.new')}}
|
||||
<Breadcrumbs::Item
|
||||
@text={{t 'resources.alias.titles.new'}}
|
||||
@route='scopes.scope.aliases.new'
|
||||
/>
|
||||
|
||||
<Rose::Layout::Page as |page|>
|
||||
<page.breadcrumbs>
|
||||
<Breadcrumbs::Container />
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
<h2>
|
||||
{{t 'resources.alias.titles.new'}}
|
||||
{{! TODO: Add doc link for alias }}
|
||||
|
||||
</h2>
|
||||
<p>{{t 'resources.alias.description'}}</p>
|
||||
|
||||
</page.header>
|
||||
<page.body>
|
||||
<Form::Alias
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
/>
|
||||
</page.body>
|
||||
</Rose::Layout::Page>
|
||||
@@ -38,16 +38,28 @@
|
||||
{{t 'resources.alias.form.sidebar.help'}}
|
||||
</p>
|
||||
{{#if @model.aliases}}
|
||||
|
||||
{{#each this.aliases as |alias|}}
|
||||
<LinkListPanel as |P|>
|
||||
<P.Item
|
||||
@icon='at-sign'
|
||||
@color='boundary'
|
||||
@text={{alias.value}}
|
||||
{{! @route=' ' }}
|
||||
@model={{alias.id}}
|
||||
/>
|
||||
<P.Item>
|
||||
<Hds::Dropdown as |dd|>
|
||||
<dd.ToggleIcon
|
||||
@icon='more-horizontal'
|
||||
@text={{t 'actions.manage'}}
|
||||
@hasChevron={{false}}
|
||||
@size='small'
|
||||
/>
|
||||
<dd.Interactive
|
||||
@route='scopes.scope.targets.target.manage-alias'
|
||||
@model={{alias.id}}
|
||||
@text={{t 'actions.manage'}}
|
||||
/>
|
||||
</Hds::Dropdown>
|
||||
</P.Item>
|
||||
</LinkListPanel>
|
||||
{{/each}}
|
||||
|
||||
@@ -59,7 +71,7 @@
|
||||
{{on 'click' this.targets.toggleFlyout}}
|
||||
/>
|
||||
{{/if}}
|
||||
{{#if this.showFlyout}}
|
||||
{{#if this.showFlyOutComponent}}
|
||||
<Hds::Flyout
|
||||
data-test-flyout
|
||||
@onClose={{this.toggleFlyout}}
|
||||
@@ -79,9 +91,22 @@
|
||||
@icon='at-sign'
|
||||
@color='boundary'
|
||||
@text={{alias.value}}
|
||||
{{! @route='' }}
|
||||
@model={{alias.id}}
|
||||
/>
|
||||
<P.Item>
|
||||
<Hds::Dropdown as |dd|>
|
||||
<dd.ToggleIcon
|
||||
@icon='more-horizontal'
|
||||
@text={{t 'actions.manage'}}
|
||||
@hasChevron={{false}}
|
||||
@size='small'
|
||||
/>
|
||||
<dd.Interactive
|
||||
@route='scopes.scope.targets.target.manage-alias'
|
||||
@model={{alias.id}}
|
||||
@text={{t 'actions.manage'}}
|
||||
/>
|
||||
</Hds::Dropdown>
|
||||
</P.Item>
|
||||
</LinkListPanel>
|
||||
{{/each}}
|
||||
</M.Body>
|
||||
@@ -92,7 +117,7 @@
|
||||
@icon='plus'
|
||||
@text={{t 'resources.target.actions.add-an-alias'}}
|
||||
@color='secondary'
|
||||
{{! @route='' }}
|
||||
@route='scopes.scope.targets.target.create-alias'
|
||||
/>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
{{!
|
||||
Copyright (c) HashiCorp, Inc.
|
||||
SPDX-License-Identifier: MPL-2.0
|
||||
}}
|
||||
|
||||
<Breadcrumbs::Item
|
||||
@text={{t 'resources.alias.title'}}
|
||||
@route='scopes.scope.targets.target.manage-alias'
|
||||
/>
|
||||
<Rose::Layout::Page as |page|>
|
||||
<page.breadcrumbs>
|
||||
<Breadcrumbs::Container />
|
||||
</page.breadcrumbs>
|
||||
<page.header>
|
||||
<h2>
|
||||
{{t 'resources.alias.title'}}
|
||||
{{! TODO: DOC LINK }}
|
||||
</h2>
|
||||
<p>{{t 'resources.alias.description'}}</p>
|
||||
<Hds::Copy::Snippet @color='secondary' @textToCopy={{@model.id}} />
|
||||
</page.header>
|
||||
<page.actions>
|
||||
|
||||
<Hds::Dropdown as |dd|>
|
||||
<dd.ToggleButton
|
||||
data-test-manage-dropdown
|
||||
@text={{t 'actions.manage'}}
|
||||
@color='secondary'
|
||||
/>
|
||||
|
||||
<dd.Interactive
|
||||
@text={{t 'actions.clear'}}
|
||||
{{on 'click' (route-action 'clearAlias' @model)}}
|
||||
/>
|
||||
{{#if (can 'delete model' @model)}}
|
||||
<dd.Separator />
|
||||
<dd.Interactive
|
||||
data-test-manage-alias-dropdown-delete
|
||||
@color='critical'
|
||||
@text={{t 'actions.delete'}}
|
||||
{{on 'click' (route-action 'deleteAlias' @model)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</Hds::Dropdown>
|
||||
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
<Form::Alias
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
/>
|
||||
</page.body>
|
||||
</Rose::Layout::Page>
|
||||
Reference in new issue
Block a user