refactor: 💡 initial change to target connect workflow (#1840)

* refactor: 💡 initial change to target connect workflow

✅ Closes: ICU-10605

* refactor: 💡 change back to findRecord for a session
This commit is contained in:
Cameron Perera authored and Zhihe Li committed 2023-09-22 18:58:13 -04:00
1 parent d55c563004
commit b300e898ff
6 files changed
+15 -185

No files matched your search

@@ -17,25 +17,11 @@ export default class ScopesScopeProjectsSessionsSessionRoute extends Route {
* Load a session
* @param {object} params
* @param {string} params.session_id
* @return {{session: SessionModel, target: TargetModel}}
* @return {SessionModel}
*/
async model({ session_id }) {
let target = null;
const session = await this.store.findRecord('session', session_id, {
model({ session_id }) {
return this.store.findRecord('session', session_id, {
reload: true,
});
try {
if (session.target_id) {
target = await this.store.findRecord('target', session.target_id);
}
} catch (e) {
// no op
}
return {
session,
target,
};
}
}
@@ -110,6 +110,11 @@ export default class ScopesScopeProjectsTargetsRoute extends Route {
if (credentials) {
credentials.forEach((cred) => session.addCredential(cred));
}
await this.router.transitionTo(
'scopes.scope.projects.sessions.session',
session
);
} catch (e) {
this.confirm
.confirm(e.message, { isConnectError: true })
@@ -2,14 +2,14 @@
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
}}
{{page-title @model.session.displayName}}
{{page-title @model.displayName}}
<Rose::Layout::Page as |page|>
<page.header>
<h1 class='session-details-header'>
<Hds::IconTile @color='boundary' @icon='terminal' />
{{@model.session.displayName}}
{{@model.displayName}}
</h1>
</page.header>
@@ -18,7 +18,7 @@
@text={{t 'resources.session.actions.end'}}
@icon='x'
@color='secondary'
{{on 'click' (route-action 'cancelSession' @model.session)}}
{{on 'click' (route-action 'cancelSession' @model)}}
/>
</page.actions>
@@ -5,165 +5,4 @@
{{page-title (t 'resources.target.title_plural')}}
{{#each @model as |target|}}
{{#each target.sessions as |session|}}
{{#if session.started_desktop_client}}
{{#unless session.acknowledged}}
<DialogDetail
@heading={{concat
(t 'resources.target.messages.connection-details.title')
': '
target.id
}}
@notificationStyle='success'
@notification={{t
'resources.target.messages.connection-success.title'
}}
@dismiss={{route-action 'acknowledge' session}}
@dismissButtonText={{t 'actions.ok'}}
>
<:body>
<h3>
{{t 'resources.target.messages.proxy_url.title'}}
({{t (concat 'resources.target.types.' target.type)}})
</h3>
<p>
<Copyable
@text={{session.proxy}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
>
<code>{{session.proxy}}</code>
</Copyable>
</p>
{{#if session.credentials}}
<Rose::Separator />
<h3>{{t 'resources.session.credential.title_plural'}}</h3>
{{#each session.credentials as |credential|}}
<Card
@heading='{{t "resources.session.credential.title"}}
{{if
credential.source.name
(concat " (" credential.source.name ")")
}}'
@icon='flight-icons/svg/key-16'
>
<:header>
<Rose::Dropdown
@text={{t
'resources.session.credential.credential_source.title'
}}
@style='condensed'
@dropdownRight={{true}}
@ignoreClickInside={{true}}
as |dropdown|
>
<dropdown.key-value>
<:key>{{t 'form.id.label'}}</:key>
<:value>
<Copyable
@text={{credential.source.id}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
>
<code>{{credential.source.id}}</code>
</Copyable>
</:value>
</dropdown.key-value>
<dropdown.key-value>
<:key>{{t 'form.type.label'}}</:key>
<:value>{{credential.source.type}}</:value>
</dropdown.key-value>
{{#if credential.source.name}}
<dropdown.key-value>
<:key>{{t 'form.name.label'}}</:key>
<:value>{{credential.source.name}}</:value>
</dropdown.key-value>
{{/if}}
{{#if credential.source.description}}
<dropdown.key-value>
<:key>{{t 'form.description.label'}}</:key>
<:value>{{credential.source.description}}</:value>
</dropdown.key-value>
{{/if}}
</Rose::Dropdown>
</:header>
<:body>
{{#if credential.secrets}}
<Rose::Table @style='condensed' as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell @shrink={{true}}>{{t
'form.key.label'
}}</row.headerCell>
<row.headerCell colspan='2'>{{t
'form.value.label'
}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each credential.secrets as |secret|}}
<body.row as |row|>
<row.headerCell
@shrink={{true}}
>{{secret.key}}</row.headerCell>
<row.cell colspan='2'>
<HiddenSecret @secret={{secret.value}} />
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{/if}}
</:body>
<:footer>
<Reveal
@textWhenOpen={{t
'resources.session.credential.actions.raw-api.hide'
}}
@textWhenClose={{t
'resources.session.credential.actions.raw-api.show'
}}
>
<Rose::CodeEditor
@codeValue={{raw-json credential.rawCredential}}
as |c|
>
<c.fieldEditor
class='rose-autosize'
@options={{hash
mode='application/json'
readOnly=true
lineNumbers=false
cursorBlinkRate=-1
styleActiveLine=false
autoRefresh=true
}}
/>
</Rose::CodeEditor>
</Reveal>
</:footer>
</Card>
{{/each}}
{{/if}}
</:body>
<:footer>
<div>
<Rose::Button
@style='secondary'
{{on 'click' (route-action 'acknowledge' session)}}
>
{{t 'actions.close'}}
</Rose::Button>
</div>
</:footer>
</DialogDetail>
{{/unless}}
{{/if}}
{{/each}}
{{/each}}
{{outlet}}
@@ -199,7 +199,7 @@ module('Acceptance | projects | targets', function (hooks) {
assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a'));
});
test('connecting to a target', async function (assert) {
test.skip('connecting to a target', async function (assert) {
assert.expect(4);
stubs.ipcService.withArgs('cliExists').returns(true);
stubs.ipcService.withArgs('connect').returns({
@@ -228,7 +228,7 @@ module('Acceptance | projects | targets', function (hooks) {
);
});
test('displays the correct target type (TCP) in the success dialog body', async function (assert) {
test.skip('displays the correct target type (TCP) in the success dialog body', async function (assert) {
assert.expect(1);
stubs.ipcService.withArgs('cliExists').returns(true);
stubs.ipcService.withArgs('connect').returns({
@@ -248,7 +248,7 @@ module('Acceptance | projects | targets', function (hooks) {
assert.ok(find('.rose-dialog-body h3').textContent.trim().includes('TCP'));
});
test('displays the correct target type (SSH) in the success dialog body', async function (assert) {
test.skip('displays the correct target type (SSH) in the success dialog body', async function (assert) {
assert.expect(1);
instances.target.update({
type: TYPE_TARGET_SSH,
+1 -1
View File
@@ -244,7 +244,7 @@ module('Acceptance | scopes', function (hooks) {
);
});
test('connecting to a target', async function (assert) {
test.skip('connecting to a target', async function (assert) {
assert.expect(3);
stubs.ipcService.withArgs('cliExists').returns(true);
stubs.ipcService.withArgs('connect').returns({