feat: 🎸 allow for connection for target with single host (#1887)
* feat: 🎸 allow for connection for target with single host ✅ Closes: ICU-10431 * refactor: 💡 small code clean up * refactor: 💡 move host fetch to model hook
This commit is contained in:
1 parent
85913acc61
commit
f0a848721a
2 files changed
+45
-18
No files matched your search
@@ -23,19 +23,46 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route {
|
||||
* Load a target
|
||||
* @param {object} params
|
||||
* @param {string} params.target_id
|
||||
* @param {bool} params.isConnecting
|
||||
* @return {TargetModel}
|
||||
* @return {{ target: TargetModel, hosts: [HostModel] }}
|
||||
*/
|
||||
async model({ target_id, isConnecting }) {
|
||||
async model({ target_id }) {
|
||||
let hosts = [];
|
||||
|
||||
const target = await this.store.findRecord('target', target_id, {
|
||||
reload: true,
|
||||
});
|
||||
|
||||
if (isConnecting) {
|
||||
await this.preConnect(target);
|
||||
if (target.host_sources) {
|
||||
const hostSets = await Promise.all(
|
||||
target.host_sources.map(({ host_source_id }) =>
|
||||
this.store.findRecord('host-set', host_source_id)
|
||||
)
|
||||
);
|
||||
|
||||
// Extract host ids from all host sets
|
||||
const hostIds = hostSets.flatMap(({ host_ids }) => host_ids);
|
||||
|
||||
// Load unique hosts
|
||||
const uniqueHostIds = new Set(hostIds);
|
||||
|
||||
hosts = await Promise.all(
|
||||
[...uniqueHostIds].map((hostId) =>
|
||||
this.store.findRecord('host', hostId)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return target;
|
||||
return { target, hosts };
|
||||
}
|
||||
|
||||
async afterModel(model, transition) {
|
||||
const { isConnecting } = transition.to.queryParams;
|
||||
|
||||
if (isConnecting) {
|
||||
if (model.target.address || model.hosts.length === 1) {
|
||||
await this.connect(model.target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,9 +71,9 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route {
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
async preConnect(target) {
|
||||
if (target.address) {
|
||||
await this.connect(target);
|
||||
async preConnect(model) {
|
||||
if (model.target.address || model.hosts.length === 1) {
|
||||
await this.connect(model.target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
SPDX-License-Identifier: MPL-2.0
|
||||
}}
|
||||
|
||||
{{page-title @model.displayName}}
|
||||
{{page-title @model.target.displayName}}
|
||||
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.header>
|
||||
<h1 class='target-details-header'>
|
||||
<Hds::IconTile @color='boundary' @icon='target' />
|
||||
{{@model.displayName}}
|
||||
{{@model.target.displayName}}
|
||||
</h1>
|
||||
</page.header>
|
||||
|
||||
@@ -48,21 +48,21 @@
|
||||
<Rose::MetadataList @orientation='vertical' as |list|>
|
||||
{{! Target name }}
|
||||
<list.Item @icon='target' @color='faint'>
|
||||
{{@model.name}}
|
||||
{{@model.target.name}}
|
||||
</list.Item>
|
||||
{{! Project name }}
|
||||
<list.Item @icon='grid' @color='faint'>
|
||||
{{@model.project.displayName}}
|
||||
{{@model.target.project.displayName}}
|
||||
</list.Item>
|
||||
{{! Target description }}
|
||||
{{#if @model.description}}
|
||||
{{#if @model.target.description}}
|
||||
<list.Item @icon='message-circle-fill' @color='faint'>
|
||||
{{@model.description}}
|
||||
{{@model.target.description}}
|
||||
</list.Item>
|
||||
{{/if}}
|
||||
{{! Target type }}
|
||||
<list.Item class='resource-type' @icon='terminal' @color='faint'>
|
||||
{{#if @model.isSSH}}
|
||||
{{#if @model.target.isSSH}}
|
||||
{{t 'resources.target.types.ssh'}}
|
||||
{{else}}
|
||||
{{t 'resources.target.types.tcp'}}
|
||||
@@ -71,11 +71,11 @@
|
||||
{{! Target ID }}
|
||||
<list.Item @icon='hash' @color='faint'>
|
||||
<Copyable
|
||||
@text={{@model.id}}
|
||||
@text={{@model.target.id}}
|
||||
@buttonText={{t 'actions.copy-to-clipboard'}}
|
||||
@acknowledgeText={{t 'states.copied'}}
|
||||
>
|
||||
{{@model.id}}
|
||||
{{@model.target.id}}
|
||||
</Copyable>
|
||||
</list.Item>
|
||||
</Rose::MetadataList>
|
||||
|
||||
Reference in new issue
Block a user