Icu 16786 implement sort for targets (#2830)
* feat: 🎸 add sorting for targets ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16786
This commit is contained in:
1 parent
8f3cccce32
commit
44bd5ee1c6
16 files changed
+264
-150
No files matched your search
@@ -28,6 +28,8 @@ export default class ScopesScopeTargetsIndexController extends Controller {
|
||||
{ types: { type: 'array' } },
|
||||
'page',
|
||||
'pageSize',
|
||||
'sortAttribute',
|
||||
'sortDirection',
|
||||
];
|
||||
|
||||
@tracked search;
|
||||
@@ -37,6 +39,8 @@ export default class ScopesScopeTargetsIndexController extends Controller {
|
||||
@tracked page = 1;
|
||||
@tracked pageSize = 10;
|
||||
@tracked selectedTarget;
|
||||
@tracked sortAttribute;
|
||||
@tracked sortDirection;
|
||||
|
||||
get availableSessionOptions() {
|
||||
return [
|
||||
@@ -301,7 +305,7 @@ export default class ScopesScopeTargetsIndexController extends Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove destaination_id from alias
|
||||
* Remove destination_id from alias
|
||||
* @param {AliasModel} alias
|
||||
*/
|
||||
@action
|
||||
@@ -363,4 +367,11 @@ export default class ScopesScopeTargetsIndexController extends Controller {
|
||||
target.rollbackAttributes();
|
||||
await this.router.replaceWith('scopes.scope.targets.target.workers');
|
||||
}
|
||||
|
||||
@action
|
||||
onSort(sortBy, sortOrder) {
|
||||
this.sortAttribute = sortBy;
|
||||
this.sortDirection = sortOrder;
|
||||
this.page = 1;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,14 @@ export default class ScopesScopeTargetsIndexRoute extends Route {
|
||||
pageSize: {
|
||||
refreshModel: true,
|
||||
},
|
||||
sortAttribute: {
|
||||
refreshModel: true,
|
||||
replace: true,
|
||||
},
|
||||
sortDirection: {
|
||||
refreshModel: true,
|
||||
replace: true,
|
||||
},
|
||||
};
|
||||
|
||||
// =methods
|
||||
@@ -61,6 +69,8 @@ export default class ScopesScopeTargetsIndexRoute extends Route {
|
||||
types,
|
||||
page,
|
||||
pageSize,
|
||||
sortAttribute,
|
||||
sortDirection,
|
||||
useDebounce,
|
||||
}) => {
|
||||
if (useDebounce) {
|
||||
@@ -99,16 +109,19 @@ export default class ScopesScopeTargetsIndexRoute extends Route {
|
||||
let totalItems = 0;
|
||||
let doTargetsExist = false;
|
||||
if (this.can.can('list model', scope, { collection: 'targets' })) {
|
||||
const sort = {
|
||||
attribute: sortAttribute,
|
||||
direction: sortDirection,
|
||||
};
|
||||
targets = await this.store.query('target', {
|
||||
scope_id,
|
||||
query: { search, filters },
|
||||
query: { search, filters, sort },
|
||||
page,
|
||||
pageSize,
|
||||
});
|
||||
totalItems = targets.meta?.totalItems;
|
||||
doTargetsExist = await this.getDoTargetsExist(scope_id, totalItems);
|
||||
}
|
||||
|
||||
return { targets, doTargetsExist, totalItems };
|
||||
},
|
||||
);
|
||||
|
||||
@@ -69,103 +69,73 @@
|
||||
|
||||
{{#if @model.targets}}
|
||||
<Hds::Table
|
||||
@columns={{array
|
||||
(hash label=(t 'form.name.label'))
|
||||
(hash label=(t 'form.type.label'))
|
||||
(hash label=(t 'resources.target.titles.active-sessions'))
|
||||
(hash label=(t 'form.id.label'))
|
||||
}}
|
||||
@model={{@model.targets}}
|
||||
@valign='middle'
|
||||
@onSort={{this.onSort}}
|
||||
@sortBy={{this.sortAttribute}}
|
||||
@sortOrder={{this.sortDirection}}
|
||||
>
|
||||
<:head as |H|>
|
||||
<H.Tr>
|
||||
<H.ThSort
|
||||
@onClickSort={{fn H.setSortBy 'name'}}
|
||||
@sortOrder={{if (eq 'name' H.sortBy) H.sortOrder}}
|
||||
>{{t 'form.name.label'}}</H.ThSort>
|
||||
<H.ThSort
|
||||
@onClickSort={{fn H.setSortBy 'type'}}
|
||||
@sortOrder={{if (eq 'type' H.sortBy) H.sortOrder}}
|
||||
>{{t 'form.type.label'}}</H.ThSort>
|
||||
<H.Th>{{t 'resources.target.titles.active-sessions'}}</H.Th>
|
||||
<H.ThSort
|
||||
@onClickSort={{fn H.setSortBy 'id'}}
|
||||
@sortOrder={{if (eq 'id' H.sortBy) H.sortOrder}}
|
||||
>{{t 'form.id.label'}}</H.ThSort>
|
||||
</H.Tr>
|
||||
</:head>
|
||||
<:body as |B|>
|
||||
{{#if (feature-flag 'ssh-target')}}
|
||||
<B.Tr data-test-targets-table-row={{B.data.id}}>
|
||||
<B.Td>
|
||||
{{#if (can 'read model' B.data)}}
|
||||
<LinkTo
|
||||
@route='scopes.scope.targets.target'
|
||||
@model={{B.data.id}}
|
||||
>
|
||||
{{B.data.displayName}}
|
||||
</LinkTo>
|
||||
{{else}}
|
||||
{{B.data.displayName}}
|
||||
{{/if}}
|
||||
<Hds::Text::Body @tag='p'>
|
||||
{{B.data.description}}
|
||||
</Hds::Text::Body>
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
{{#if B.data.type}}
|
||||
<Hds::Badge
|
||||
@text={{t (concat 'resources.target.types.' B.data.type)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
{{#if B.data.isActive}}
|
||||
<Hds::Link::Standalone
|
||||
@text={{t 'actions.yes'}}
|
||||
@route='scopes.scope.sessions.index'
|
||||
@query={{hash targets=(array B.data.id)}}
|
||||
@icon='info'
|
||||
/>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
<Hds::Copy::Snippet
|
||||
@textToCopy={{B.data.id}}
|
||||
@color='secondary'
|
||||
/>
|
||||
</B.Td>
|
||||
</B.Tr>
|
||||
{{else}}
|
||||
{{#if B.data.isTCP}}
|
||||
<B.Tr data-test-targets-table-row={{B.data.id}}>
|
||||
{{#each @model.targets as |data|}}
|
||||
{{#if (or (feature-flag 'ssh-target') data.isTCP)}}
|
||||
<B.Tr data-test-targets-table-row={{data.id}}>
|
||||
<B.Td>
|
||||
{{#if (can 'read model' B.data)}}
|
||||
{{#if (can 'read model' data)}}
|
||||
<LinkTo
|
||||
@route='scopes.scope.targets.target'
|
||||
@model={{B.data.id}}
|
||||
@model={{data.id}}
|
||||
>
|
||||
{{B.data.displayName}}
|
||||
{{data.displayName}}
|
||||
</LinkTo>
|
||||
{{else}}
|
||||
{{B.data.displayName}}
|
||||
{{data.displayName}}
|
||||
{{/if}}
|
||||
<Hds::Text::Body @tag='p' class='p'>
|
||||
{{B.data.description}}
|
||||
{{data.description}}
|
||||
</Hds::Text::Body>
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
{{#if B.data.type}}
|
||||
{{#if data.type}}
|
||||
<Hds::Badge
|
||||
@text={{t
|
||||
(concat 'resources.target.types.' B.data.type)
|
||||
}}
|
||||
@text={{t (concat 'resources.target.types.' data.type)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
{{#if B.data.isActive}}
|
||||
{{#if data.isActive}}
|
||||
<Hds::Link::Standalone
|
||||
@text={{t 'actions.yes'}}
|
||||
@route='scopes.scope.sessions.index'
|
||||
@query={{hash targets=(array B.data.id)}}
|
||||
@query={{hash targets=(array data.id)}}
|
||||
@icon='info'
|
||||
/>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
<Hds::Copy::Snippet
|
||||
@textToCopy={{B.data.id}}
|
||||
@textToCopy={{data.id}}
|
||||
@color='secondary'
|
||||
/>
|
||||
</B.Td>
|
||||
</B.Tr>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</:body>
|
||||
</Hds::Table>
|
||||
<Rose::Pagination
|
||||
|
||||
Reference in new issue
Block a user