Icu 13897 create remove tag modal (#2377)
* feat: 🎸 add action dropdown in tags table ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 add removeApiTags method to worker ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 add tag removal workflow ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * test: 💍 add tests for removing a worker tag ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * test: 💍 add tests for removing a tag ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 fix spelling issue ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 use mirage worker serializer to remove empty tag ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 update modal id to class ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 add autofocus to remove tag modal ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 update tags controller attributes ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 create normalizer to add empty object for api_tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 update getter signature ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 remove unneeded parens ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 remove type from Hds::Button ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 update confirmation modal class name ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * feat: 🎸 add emptyObjectIfMissing model attribute ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 PR feedback ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897 * refactor: 💡 remove default to null in toggleModal ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13897
This commit is contained in:
1 parent
723101b779
commit
f9af4f0092
16 files changed
+443
-12
No files matched your search
@@ -4,10 +4,70 @@
|
||||
*/
|
||||
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { TAG_TYPE_CONFIG } from 'api/models/worker';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { TAG_TYPE_CONFIG, TAG_TYPE_API } from 'api/models/worker';
|
||||
|
||||
export default class ScopesScopeWorkersWorkerTagsController extends Controller {
|
||||
@controller('scopes/scope/workers/index') workers;
|
||||
|
||||
// =services
|
||||
@service intl;
|
||||
|
||||
// =attributes
|
||||
|
||||
tagTypeConfig = TAG_TYPE_CONFIG;
|
||||
tagTypeApi = TAG_TYPE_API;
|
||||
|
||||
@tracked removeModal = false;
|
||||
@tracked removalConfirmation = null;
|
||||
@tracked modalTag = null;
|
||||
|
||||
/**
|
||||
* Build the display name for a worker tag
|
||||
* @type {string}
|
||||
*/
|
||||
get tagDisplayName() {
|
||||
return `"${this.modalTag?.key} = ${this.modalTag?.value}"`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if user entered REMOVE to enable the remove button.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isRemovalConfirmed() {
|
||||
return (
|
||||
this.removalConfirmation === this.intl.t('actions.remove').toUpperCase()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes selected tag from the worker.
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('resources.worker.tags.remove.success')
|
||||
async removeApiTag() {
|
||||
await this.model.removeApiTags({
|
||||
[this.modalTag.key]: [this.modalTag.value],
|
||||
});
|
||||
this.removeModal = false;
|
||||
this.modalTag = null;
|
||||
this.removalConfirmation = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the remove tag modal.
|
||||
* @param {object} apiTag
|
||||
*/
|
||||
@action
|
||||
toggleRemoveModal(apiTag) {
|
||||
this.removeModal = !this.removeModal;
|
||||
this.modalTag = apiTag;
|
||||
this.removalConfirmation = null;
|
||||
}
|
||||
}
|
||||
@@ -1057,3 +1057,14 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.confirmation-modal {
|
||||
.hds-button-set {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.hds-form-field--layout-vertical {
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@
|
||||
<Hds::Dropdown as |dd|>
|
||||
<dd.ToggleIcon
|
||||
@icon='more-horizontal'
|
||||
@text='Overflow Options'
|
||||
@text={{t 'actions.overflow-options'}}
|
||||
@hasChevron={{false}}
|
||||
@size='small'
|
||||
/>
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
(hash label=(t 'resources.worker.table.key'))
|
||||
(hash label=(t 'resources.worker.table.value'))
|
||||
(hash label=(t 'resources.worker.table.type'))
|
||||
(hash label=(t 'titles.actions') isVisuallyHidden=true width='60px')
|
||||
}}
|
||||
@valign='middle'
|
||||
>
|
||||
@@ -61,11 +62,78 @@
|
||||
<Hds::Badge @text={{B.data.type}} />
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
{{#if (eq B.data.type this.tagTypeApi)}}
|
||||
<Hds::Dropdown as |dd|>
|
||||
<dd.ToggleIcon
|
||||
@icon='more-horizontal'
|
||||
@text={{t 'actions.overflow-options'}}
|
||||
@hasChevron={{false}}
|
||||
@size='small'
|
||||
/>
|
||||
{{#if (can 'removeTags worker' @model)}}
|
||||
<dd.Interactive
|
||||
@text={{t 'resources.worker.tags.actions.remove'}}
|
||||
{{on 'click' (fn this.toggleRemoveModal B.data)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</Hds::Dropdown>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
</B.Tr>
|
||||
</:body>
|
||||
</Hds::Table>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.removeModal}}
|
||||
<Hds::Modal
|
||||
class='confirmation-modal'
|
||||
@color='critical'
|
||||
@onClose={{this.toggleRemoveModal}}
|
||||
as |M|
|
||||
>
|
||||
<M.Header @icon='alert-diamond'>
|
||||
{{t 'resources.worker.tags.remove.title'}}
|
||||
</M.Header>
|
||||
<M.Body>
|
||||
<Hds::Text::Body @color='primary'>
|
||||
{{this.tagDisplayName}}
|
||||
{{t 'resources.worker.tags.remove.warning'}}
|
||||
</Hds::Text::Body>
|
||||
{{! template-lint-disable no-autofocus-attribute }}
|
||||
<Hds::Form::TextInput::Field
|
||||
name='removal-confirmation'
|
||||
autofocus={{true}}
|
||||
@value={{this.removalConfirmation}}
|
||||
{{on 'input' (set-from-event this 'removalConfirmation')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t
|
||||
'resources.worker.tags.remove.confirm.label'
|
||||
}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.worker.tags.remove.confirm.help'
|
||||
}}</F.HelperText>
|
||||
</Hds::Form::TextInput::Field>
|
||||
</M.Body>
|
||||
<M.Footer as |F|>
|
||||
<Hds::ButtonSet>
|
||||
<Hds::Button
|
||||
disabled={{not this.isRemovalConfirmed}}
|
||||
@color='critical'
|
||||
@text={{t 'actions.remove'}}
|
||||
{{on 'click' this.removeApiTag}}
|
||||
/>
|
||||
<Hds::Button
|
||||
@color='secondary'
|
||||
@text={{t 'actions.cancel'}}
|
||||
{{on 'click' F.close}}
|
||||
/>
|
||||
</Hds::ButtonSet>
|
||||
</M.Footer>
|
||||
</Hds::Modal>
|
||||
{{/if}}
|
||||
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
Reference in new issue
Block a user