Icu 13889 update tags column to action that opens hds flyout and add link to tags tab if more than 10 tags (#2355)
* refactor: 💡 update worker factory to include api_tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * feat: 🎸 add tags flyout for workers table ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 move test selector to const ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 only show 'view more tags' if more than 10 tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * test: 💍 update test name ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 update how worker tags are shown in flyout ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 add one more api tag for worker in mirage ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 fix tagDisplayName signature ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 update tag shortener styling ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889
This commit is contained in:
1 parent
f51124cfdb
commit
40ebbf8b09
7 files changed
+277
-19
No files matched your search
@@ -7,6 +7,7 @@ import Controller from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
@@ -16,8 +17,39 @@ export default class ScopesScopeWorkersIndexController extends Controller {
|
||||
@service router;
|
||||
@service can;
|
||||
|
||||
// =attributes
|
||||
|
||||
@tracked selectedWorker;
|
||||
|
||||
/**
|
||||
* Get the first 10 tags of the selected worker.
|
||||
* @type {object[]}
|
||||
*/
|
||||
get selectedWorkerTags() {
|
||||
// only show the first 10 tags if there are more than 10
|
||||
return this.selectedWorker.allTags.slice(0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the display name for a worker tag
|
||||
* @param {object} tag
|
||||
* @returns {string}
|
||||
*/
|
||||
tagDisplayName(tag) {
|
||||
return `${tag.key} = ${tag.value}`;
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Toggle the tags flyout to display or hide the tags of a worker.
|
||||
* @param {object} selectedWorker
|
||||
*/
|
||||
@action
|
||||
selectWorker(selectedWorker) {
|
||||
this.selectedWorker = selectedWorker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback changes on workers.
|
||||
* @param {WorkerModel} worker
|
||||
|
||||
@@ -68,6 +68,16 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
|
||||
return workers;
|
||||
}
|
||||
|
||||
resetController(controller, isExiting) {
|
||||
// Clear selected worker when exiting route to prevent
|
||||
// the flyout from showing when returning to this route
|
||||
if (isExiting) {
|
||||
controller.setProperties({
|
||||
selectedWorker: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears filter selections.
|
||||
*/
|
||||
|
||||
@@ -1069,3 +1069,15 @@
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
// workers
|
||||
.view-more-tags {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.tag-shortener {
|
||||
display: inline-block;
|
||||
max-width: 310px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
@@ -124,12 +124,16 @@
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
{{#if B.data.tagCount}}
|
||||
<Hds::Badge
|
||||
<Hds::Button
|
||||
data-test-worker-tags-flyout-button={{B.data.id}}
|
||||
@icon='tag'
|
||||
@text={{t
|
||||
'resources.worker.table.tag_count'
|
||||
tagCount=B.data.tagCount
|
||||
}}
|
||||
@color='tertiary'
|
||||
@size='small'
|
||||
{{on 'click' (fn this.selectWorker B.data)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
@@ -145,6 +149,56 @@
|
||||
</B.Tr>
|
||||
</:body>
|
||||
</Hds::Table>
|
||||
|
||||
{{#if this.selectedWorker}}
|
||||
<Hds::Flyout
|
||||
data-test-worker-tags-flyout
|
||||
@onClose={{fn this.selectWorker null}}
|
||||
as |M|
|
||||
>
|
||||
<M.Header>
|
||||
{{t
|
||||
'resources.worker.flyout.title'
|
||||
workerName=this.selectedWorker.displayName
|
||||
}}
|
||||
</M.Header>
|
||||
<M.Body>
|
||||
<Hds::Table
|
||||
@model={{this.selectedWorkerTags}}
|
||||
@columns={{array
|
||||
(hash label=(t 'resources.worker.flyout.table.tag'))
|
||||
(hash label=(t 'resources.worker.flyout.table.type'))
|
||||
}}
|
||||
@valign='middle'
|
||||
>
|
||||
<:body as |B|>
|
||||
<B.Tr>
|
||||
<B.Td>
|
||||
<Hds::Text::Code class='tag-shortener'>
|
||||
{{this.tagDisplayName B.data}}
|
||||
</Hds::Text::Code>
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
<Hds::Badge @text={{B.data.type}} />
|
||||
</B.Td>
|
||||
</B.Tr>
|
||||
</:body>
|
||||
</Hds::Table>
|
||||
{{#if (gt this.selectedWorker.allTags.length 10)}}
|
||||
<div class='view-more-tags'>
|
||||
{{! TODO: Update route to worker.tags once route is added }}
|
||||
<Hds::Link::Standalone
|
||||
@icon='arrow-right'
|
||||
@iconPosition='trailing'
|
||||
@text={{t 'resources.worker.flyout.action.view_more'}}
|
||||
@route='scopes.scope.workers.worker'
|
||||
@model={{this.selectedWorker}}
|
||||
/>
|
||||
</div>
|
||||
{{/if}}
|
||||
</M.Body>
|
||||
</Hds::Flyout>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<Rose::Layout::Centered>
|
||||
<Rose::Message
|
||||
|
||||
Reference in new issue
Block a user